如何在 mysql 数据库上运行脚本?
我使用 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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
等等...
将其放入名为 mydbcreate.sql 的文件中并运行(从命令行)
etc...
Put that in a file called mydbcreate.sql and run (from the command line)
了解 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
这里有一些提示:
它
确实生成一个包含结构和数据的文件。第二行将文件中的数据读取到数据库中。
-p 和密码之间没有空格。最好不要将密码放在命令中,因为这可能会出现在您的 .bash_history 中。如果您省略密码,系统会提示您输入:
并且
Here are some hints :
And
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:
And
也许你需要知道那些语句叫做DDL?然后你可以去任何MySQL站点询问如何生成DDL?没有刻薄的意思,只是说说而已。 。 。
另外,您可以尝试以下操作:
通过命令行使用 mysqldump 和 --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:
(of course, without the curly braces)
你有两个选择。
对于 #1,使用以下菜单命令
从这里,您可以使用 MySQL GUI Tools 等程序或查看此线程中的其他答案,从命令行导入生成的 SQL 脚本。
对于 #2,请使用以下菜单命令
在执行上述任一操作之前,您可能需要先通过
重要!对于这两个选项,请确保仔细查看提示中可用的每个选项 - 小设置可以使输出发生很大变化!
You have two options.
For #1, use the following menu command
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
Before you do either of these, you may want to establish a connection first via
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!