如何在MySQL Workbench中获得表创建脚本? [英] How to get a table creation script in MySQL Workbench?

查看:507
本文介绍了如何在MySQL Workbench中获得表创建脚本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于我找不到在MySQL Workbench中获取表的创建脚本的快捷方式,因此我将回滚到MySQL GUI Tools的MySQL查询浏览器.

I am rolling back to MySQL GUI Tools' MySQL Query Browser since I can't find the shortcut to get a table's creation script in MySQL Workbench.

推荐答案

至少在Community Edition中,我也找不到这样的选项.

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) :

对数据库进行反向工程 直接从MySQL服务器应用 到MySQL的商业版本 仅限工作台.

reverse engineering a database directly from a MySQL server applies to commercial versions of MySQL Workbench only.


不过,您仍然可以使用Plain-SQL获取create table指令,该指令将允许您创建表.


Still, you can use plain-SQL to get the create table instruction that will allow you to create a table.

例如,以下查询:

show create table url_alias;

在drupal数据库上执行时,在结果上使用正确的click > copy field content时会给出:

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'

不幸的是(再次),MySQL Workbench以这种方式复制时在各处都添加了一些引号:-(

Unfortunately (again), MySQL Workbench adds some quotes everywhere when copying this way :-(


最后,除了使用MySQL Query Browser之外,最简单的解决方案很可能是使用命令行客户端连接到数据库,然后从那里执行show create table查询:


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.


并且,为了完整起见,您还可以使用mysqldump来获取表的结构:

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

使用--no-data开关,您只会在某些模式设置以及所有这些设置的中间得到结构-.

Using the --no-data switch, you'll only get the structure -- in the middle of some mode settings and all that.

这篇关于如何在MySQL Workbench中获得表创建脚本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆