我正在回滚到 MySQL GUI 工具的 MySQL 查询浏览器,因为我找不到在 MySQL Workbench 中获取表创建脚本的快捷方式。
I cannot find such an option either, at least in the Community edition.
I suppose this corresponds to the Reverse Engineering feature, which, unfortunately, is only available in the commercial edition (quoting) :
reverse engineering a database directly from a MySQL server applies to commercial versions of MySQL Workbench only .
Still, you can use plain-SQL to get the create table
instruction that will allow you to create a table.
For instance, the following query :
show create table url_alias;
when executed on a drupal database, would give, when using right click > copy field content
on the result :
'CREATE TABLE `url_alias` (
`pid` int(10) unsigned NOT NULL auto_increment,
`src` varchar(128) NOT NULL default '''',
`dst` varchar(128) NOT NULL default '''',
`language` varchar(12) NOT NULL default '''',
PRIMARY KEY (`pid`),
UNIQUE KEY `dst_language` (`dst`,`language`),
KEY `src_language` (`src`,`language`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8'
Unfortunately (again) , MySQL Workbench adds some quotes everywhere when copying this way :-(
click > copy field (unquoted)
on the result to get the desired result without quotes.
In the end, the simplest solution, except from staying with MySQL Query Browser, will most likely be to connect to the database, using the command-line client, and execute the show create table
query from there :
mysql> show create table url_alias\G
*************************** 1. row ***************************
Table: url_alias
Create Table: CREATE TABLE `url_alias` (
`pid` int(10) unsigned NOT NULL auto_increment,
`src` varchar(128) NOT NULL default '',
`dst` varchar(128) NOT NULL default '',
`language` varchar(12) NOT NULL default '',
PRIMARY KEY (`pid`),
UNIQUE KEY `dst_language` (`dst`,`language`),
KEY `src_language` (`src`,`language`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8
1 row in set (0.00 sec)
Getting " the right portion " of the output is easier, there : no quote to remove.
And, just for the sake of completness, you could also use mysqldump
to get your table's structure :
mysqldump --no-data --user=USERNAME --password=PASSWORD --host=HOST DATABASE_NAME TABLE_NAME
Using the --no-data
switch, you'll only get the structure -- in the middle of some mode settings and all that .
To get an individual table's creation script just right click on the table name and click Copy to Clipboard > Create Statement.
To enable the File > Forward Engineering SQL_CREATE Script.. option and to get the creation script for your entire database :
Right-click on the relevant table and choose either of:
That seems to work for me.
It is located in server administration rather than in SQL development.
I came here looking for the answer to the same question. But I found a much better answer myself.
In the tables list, if you right-click on the table name there is a suite of CRUD script generation options in "Send to SQL Editor". You can select multiple tables and take the same approach too.
My version of MySQL Workbench: 5.2.37
只需使用:
show create table <table_name>
不确定我是否完全理解您的问题,但如果只是创建导出脚本,您应该将工程师转发到 SQL 脚本 - Ctrl + Shift + G 或文件 -> 导出 -> 第一个选项。
Solution for MySQL Workbench 6.3E
Not sure if this is still an issue, but for me in 5.2.35CE it's possible to get the create scripts by:
Database --> Reverse Engineer
Under stored connection, choose your database
Hit "Next" a few times, choose which schema you want to reverse engineer, and let the tool work
You'll get an "EER Diagram" view with all the DB's schema. If you right click on the table you care about and choose "Copy SQL to Clipboard" I think you'll have what you need.
Hopefully this helps someone else that needs it.
Or Check https://dev.mysql.com/doc/workbench/en/wb-admin-export-import-management.html
在“模型概述”或“图表”中,只需右键单击表格,您就有以下选项:“将插入复制到剪贴板”或“将 SQL 复制到剪贴板”
您可以使用MySQL Proxy及其脚本系统在终端中实时查看 SQL 查询。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.