如何在 MySQL Workbench 中生成整个数据库脚本?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4930733/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to generate the whole database script in MySQL Workbench?
提问by HAJJAJ
I want to take the whole database. Where do I find the database file?
我想把整个数据库。我在哪里可以找到数据库文件?
And is there a way to write the whole database with all data to a text file (like the one in SQL Server)?
有没有办法将包含所有数据的整个数据库写入文本文件(如 SQL Server 中的文件)?
采纳答案by mingos
Q#1: I would guess that it's somewhere on your MySQL server? Q#2: Yes, this is possible. You have to establish a connection via Server Administration. There you can clone any table or the entire database.
Q#1:我猜它在你的 MySQL 服务器上的某个地方?Q#2:是的,这是可能的。您必须通过服务器管理建立连接。在那里您可以克隆任何表或整个数据库。
This tutorialmight be useful.
本教程可能有用。
EDIT
编辑
Since the provided link is no longer active, here's a SO answeroutlining the process of creating a DB backup in Workbench.
由于提供的链接不再有效,这里有一个SO 答案,概述了在 Workbench 中创建数据库备份的过程。
回答by Aaronster
How to generate SQL scripts for your database in Workbench
如何在 Workbench 中为您的数据库生成 SQL 脚本
- In Workbench Central(the default "Home" tab) connect to your MySQL instance, opening a SQL Editortab.
- Click on the SQL Editortab and select your database from the SCHEMASlist in the Object Browseron the left.
- From the menu select
Database > Reverse Engineer
and follow the prompts. The wizard will lead you through connecting to your instance, selecting your database, and choosing the types of objects you want to reverse engineer. When you're all done, you will have at least one new tab called MySQLModel. You may also have a tab called EER Diagramwhich is cool but not relevant here. - Click in the MySQL Modeltab
- Select
Database > Forward Engineer
- Follow the prompts. Many options present themselves, including Generate INSERT Scripts for Tableswhich allows you to script out the data contained within your tables (perfect for lookup tables).
- Soon you will see the generated script in front of you. At this point you can
Copy to Clipboard
orSave to Text File
.
- 在Workbench Central(默认的“主页”选项卡)中连接到您的 MySQL 实例,打开SQL 编辑器选项卡。
- 单击SQL Editor选项卡并从左侧对象浏览器的SCHEMAS列表中选择您的数据库。
- 从菜单中选择
Database > Reverse Engineer
并按照提示操作。该向导将引导您连接到您的实例、选择您的数据库以及选择您想要逆向工程的对象类型。全部完成后,您将至少拥有一个名为MySQL模型的新选项卡。您可能还有一个名为EER Diagram的选项卡,它很酷但在这里不相关。 - 单击MySQL 模型选项卡
- 选择
Database > Forward Engineer
- 按照提示操作。许多选项都存在,包括为表生成插入脚本,它允许您编写表中包含的数据的脚本(非常适合查找表)。
- 很快您就会看到生成的脚本出现在您面前。此时您可以
Copy to Clipboard
或Save to Text File
。
The wizard will take you further, but if you just want the script you can stop here.
向导会带你走得更远,但如果你只想要脚本,你可以在这里停下来。
A word of caution: the scripts are generated with CREATE
commands. If you want ALTER
you'll have to (as far as I can tell) manually change the CREATEs to ALTERs.
请注意:脚本是通过CREATE
命令生成的。如果您愿意,ALTER
您必须(据我所知)手动将 CREATE 更改为 ALTER。
This is guaranteed to work, I just did it tonight.
这保证有效,我今晚刚做到。
回答by Gruber
In MySQL Workbench 6, commands have been repositioned as the "Server Administration" tab is gone.
在 MySQL Workbench 6 中,命令已重新定位,因为“服务器管理”选项卡不见了。
You now find the option "Data Export" under the "Management" section when you open a standard server connection.
当您打开标准服务器连接时,您现在可以在“管理”部分下找到“数据导出”选项。
回答by Saurabh Chandra Patel
there is data export option in MySQL workbech
MySQL 工作台中有数据导出选项
回答by Tod Birdsall
I found this question by searching Google for "mysql workbench export database sql file". The answers here did not help me, but I eventually did find the answer, so I am posting it here for future generations to find:
我通过在 Google 上搜索“mysql workbench 导出数据库 sql 文件”找到了这个问题。这里的答案对我没有帮助,但我最终确实找到了答案,所以我把它贴在这里供后代找到:
Answer
回答
In MySQLWorkbench 6.0, do the following:
在 MySQLWorkbench 6.0 中,执行以下操作:
- Select the appropriate database under MySQL Connections
- On the top-left hand side of screen, under the MANAGEMENT heading, select "Data Export".
- 在 MySQL Connections 下选择合适的数据库
- 在屏幕左上角的“管理”标题下,选择“数据导出”。
Here is a screenshot for reference:
这是一个截图供参考:
回答by bentzy
None of these worked for me. I'm using Mac OS 10.10.5 and Workbench 6.3. What worked for me is Database->Migration Wizard...Flow the steps very carefully
这些都不适合我。我使用的是 Mac OS 10.10.5 和 Workbench 6.3。对我有用的是Database->Migration Wizard ...非常小心地执行这些步骤
回答by fancyPants
In the top menu of MySQL Workbench click on database and then on forward engineer. In the options menu with which you will be presented, make sure to have "generate insert statements for tables" set.
在 MySQL Workbench 的顶部菜单中,单击数据库,然后单击正向工程师。在您将看到的选项菜单中,确保设置了“为表生成插入语句”。
回答by Fender
Try the export function of phpMyAdmin.
试试phpMyAdmin的导出功能。
I think there is also a possibility to copy the database files from one server to another, but I do not have a server available at the moment so I can't test it.
我认为还可以将数据库文件从一台服务器复制到另一台服务器,但我目前没有可用的服务器,因此无法对其进行测试。
回答by u5675325
回答by Marquez
Surprisingly the Data Export in the MySql Workbench is not just for data, in fact it is ideal for generating SQL scripts for the whole database (including views, stored procedures and functions) with just a few clicks. If you want just the scripts and no data simply select the "Skip table data" option. It can generate separate files or a self contained file. Here are more details about the feature: http://dev.mysql.com/doc/workbench/en/wb-mysql-connections-navigator-management-data-export.html
令人惊讶的是,MySql Workbench 中的数据导出不仅仅用于数据,事实上,它非常适合只需点击几下即可为整个数据库(包括视图、存储过程和函数)生成 SQL 脚本。如果您只需要脚本而不需要数据,只需选择“跳过表数据”选项。它可以生成单独的文件或自包含文件。以下是有关该功能的更多详细信息:http: //dev.mysql.com/doc/workbench/en/wb-mysql-connections-navigator-management-data-export.html