MySQL 如何在MySQL中为数据库中的所有表生成DDL

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6597890/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 20:24:04  来源:igfitidea点击:

How to generate DDL for all tables in a database in MySQL

mysqldatabasedatabase-designddl

提问by Sumit Gupta

How to generate the DDL for all tables in a database of MySQL at once. I know that the following query will output the DDL for a table. But I want DDL of all tables at once because I am having hundreds of tables in my database.

如何一次性为MySQL数据库中的所有表生成DDL。我知道以下查询将输出表的 DDL。但是我想要一次对所有表进行 DDL,因为我的数据库中有数百个表。

show create table <database name>.<table name>;

For example:

例如:

show create table projectdb.customer_details; 

The above query will result in DDL of customer_detailstable.

上述查询将导致customer_details表的DDL 。

I am using MySQL with MySQL workbench on Windows OS.

我在 Windows 操作系统上将 MySQL 与 MySQL 工作台一起使用。

回答by AJ.

You can do it using the mysqldump command line utility:

您可以使用 mysqldump 命令行实用程序执行此操作:

mysqldump -d -u <username> -p<password> -h <hostname> <dbname>

The -doption means "without data".

-d选项的意思是“没有数据”。

回答by John Toups

@tftdias above made a comment that is partially correct:

上面的@tftdias 发表了部分正确的评论:

The issue was the space between the -p and 'pps' as the password. You can absolutely freetext your password on the command line. You just shouldn't, as a general security rule. In linux, with a proper configuration, you can add a space (" ") BEFORE the first character on your command line, and that line will not enter into 'history'. I would recommend that whenever you cleartext your password (don't do it!), that you at least put a space first so that the password is not in visible history.

问题是 -p 和 'pps' 之间的空格作为密码。您绝对可以在命令行上随意输入密码。作为一般安全规则,您不应该这样做。在 linux 中,通过适当的配置,您可以在命令行的第一个字符之前添加一个空格 (" "),该行不会进入 'history'。我建议,每当您明文输入密码时(不要这样做!),至少先放一个空格,这样密码就不会出现在可见的历史记录中。

回答by Ovais Khatri

You must get list of all the tables in database and then run this query. check this link to get list of all tables: http://php.net/manual/en/function.mysql-list-tables.php

您必须获取数据库中所有表的列表,然后运行此查询。检查此链接以获取所有表的列表:http: //php.net/manual/en/function.mysql-list-tables.php