如何在 mysql 数据库上运行脚本?

发布于 2024-08-25 23:07:15 字数 124 浏览 14 评论 0原文

我使用 MySQL Workbench 创建了一个 MySQL 数据库。它有大约20张桌子。我无法弄清楚如何在数据库上运行脚本。

基本上,我想制作一个数据库创建脚本,它允许我在任何其他 MySQL 服务器上创建数据库。

I have created a MySQL database using MySQL Workbench. It has about 20 tables. I cannot figure out how to run scripts on the database.

Basically, I want to make a database creation script which will allow me to create my database on any other MySQL server.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

坏尐絯℡ 2024-09-01 23:07:15
create database mydatabase;

grant all on mydatabase.* to 'myuser'@'%' identified by 'mypasswd';

create table mytable (
id int not null auto_increment,
myfield varchar(255) not null default ''
);

等等...

将其放入名为 mydbcreate.sql 的文件中并运行(从命令行)

mysql -u <myuser> -p < mydbcreate.sql
create database mydatabase;

grant all on mydatabase.* to 'myuser'@'%' identified by 'mypasswd';

create table mytable (
id int not null auto_increment,
myfield varchar(255) not null default ''
);

etc...

Put that in a file called mydbcreate.sql and run (from the command line)

mysql -u <myuser> -p < mydbcreate.sql
戒ㄋ 2024-09-01 23:07:15

了解 mysql 命令行实用程序是有用的&重要的是,但要执行常见任务,请使用数据库管理工具(例如 phpMyAdmin)来创建和管理数据库。这些工具使创建和创建变得极其容易。浏览表、创建导出脚本(包含用于创建表、插入数据等的所有查询的文件)以及其他很棒的事情。

phpMyAdmin 很棒,运行在 LAMP 环境中,免费且易于使用。

http://www.phpmyadmin.net/home_page/index.php

导出截图phpMyAdmin 中的数据库(裁剪镜头)替代文本 http://www. typolight.org/tl_files/images/documentation/sql-export.jpg

Knowing the mysql command line utilities is useful & important but for performing common tasks use a database administration tool, such as phpMyAdmin, to create and manage your databases. These tools make it extremely easy to create & browse tables, create export scripts (a file with all the queries to create tables, insert data, etc...), and other great things.

phpMyAdmin is great, runs in and LAMP environment, is free, and easy to use.

http://www.phpmyadmin.net/home_page/index.php

Screeny of exporting a db in phpMyAdmin (cropped shot)alt text http://www.typolight.org/tl_files/images/documentation/sql-export.jpg

离笑几人歌 2024-09-01 23:07:15

这里有一些提示:

mysqldump -u [username] -p[password] [databasename] > [backupfile.sql]

mysql -u [username] -p[password] [database_to_restore] < [backupfile.sql]

确实生成一个包含结构和数据的文件。第二行将文件中的数据读取到数据库中。

-p 和密码之间没有空格。最好不要将密码放在命令中,因为这可能会出现在您的 .bash_history 中。如果您省略密码,系统会提示您输入:

mysqldump -u [username] -p [databasename] > [backupfile.sql]

并且

mysql -u [username] -p [database_to_restore] < [backupfile.sql]

Here are some hints :

mysqldump -u [username] -p[password] [databasename] > [backupfile.sql]

And

mysql -u [username] -p[password] [database_to_restore] < [backupfile.sql]

It does generate a file with structures and data. The second line take the data from the file to the database.

There is no space between -p and the password. It would be better not to put the password in your command as this can end up in your .bash_history. If you omit the password it will be prompted for:

mysqldump -u [username] -p [databasename] > [backupfile.sql]

And

mysql -u [username] -p [database_to_restore] < [backupfile.sql]
东北女汉子 2024-09-01 23:07:15

也许你需要知道那些语句叫做DDL?然后你可以去任何MySQL站点询问如何生成DDL?没有刻薄的意思,只是说说而已。 。 。

另外,您可以尝试以下操作:

通过命令行使用 mysqldump 和 --no-data 选项。如果需要更多信息,请寻求帮助。但一个简单的例子是:(

$ mysqldump -u{username} -p{password} {dbname} --no-data

当然,没有花括号)

Perhaps what you need is to know that those statements are called DDL? Then you can go to any MySQL site and ask how to generate DDL? Not being snarky, just saying . . .

Also, you can try this:

use mysqldump from the command line with the --no-data option. Ask for help if need more info. But a simple example would be:

$ mysqldump -u{username} -p{password} {dbname} --no-data

(of course, without the curly braces)

眼睛会笑 2024-09-01 23:07:15

你有两个选择。

  1. 导出可在任何 MySQL 服务器上存储和/或任意运行的 CREATE 脚本
  2. 直接与特定 MySQL 服务器同步。

对于 #1,使用以下菜单命令

File >> Export >> Forward Engineer SQL CREATE Script...

从这里,您可以使用 MySQL GUI Tools 等程序或查看此线程中的其他答案,从命令行导入生成的 SQL 脚本。

对于 #2,请使用以下菜单命令

Database >> Forward Engineer...
- or -
Database >> Synchronize Model...

在执行上述任一操作之前,您可能需要先通过

Database >> Manage Connections...

重要!对于这两个选项,请确保仔细查看提示中可用的每个选项 - 小设置可以使输出发生很大变化!

You have two options.

  1. Export a CREATE script that you can store and/or arbitrarily run on any MySQL server
  2. Synchronize with a specific MySQL server directly.

For #1, use the following menu command

File >> Export >> Forward Engineer SQL CREATE Script...

From here, you can use a program like MySQL GUI Tools or see the other answers in this thread to import the generated SQL script from the command line.

For #2, use the following menu command

Database >> Forward Engineer...
- or -
Database >> Synchronize Model...

Before you do either of these, you may want to establish a connection first via

Database >> Manage Connections...

Important! For both of these options, make sure you look closely at every option available in the prompts - small settings can make a big change in the output!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文