没有数据的 MySql 导出模式

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

MySql export schema without data

mysqlsql

提问by Darth Blue Ray

I'm using a MySql database with a Java program, now I want to give the program to somebody else.

我正在使用带有 Java 程序的 MySql 数据库,现在我想将该程序提供给其他人。

How to export the MySql database structure without the data in it, just the structure?

如何导出没有数据的MySql数据库结构,只有结构?

回答by Daric

You can do with the --no-dataoption with mysqldump command

您可以--no-data使用 mysqldump 命令使用该选项

mysqldump -u root -p --no-data dbname > schema.sql

回答by onteria_

Yes, you can use mysqldumpwith the --no-dataoption:

是的,您可以使用mysqldump以下--no-data选项:

mysqldump -u user -h localhost --no-data -p database > database.sql

回答by PodTech.io

you can also extract an individual table with the --no-dataoption

您还可以使用--no-data选项提取单个表

mysqldump -u user -h localhost --no-data -p database tablename > table.sql

回答by Anders B

Dumping without using output.

在不使用输出的情况下进行转储。

mysqldump --no-data <database name> --result-file=schema.sql

回答by Rahul Chipad

You can use the -d option with mysqldump command

您可以在 mysqldump 命令中使用 -d 选项

mysqldump -u root -p -d databasename > database.sql

回答by Mamta Satoor

Beware though that --no-data option will not include the view definition. So if yo had a view like following create view v1 select a.idAS id, a.created_dateAS created_datefrom t1; with --no-data option, view definition will get changed to following create view v1 select 1 AS id, 1 AS created_date

请注意 --no-data 选项将不包括视图定义。所以如果你有一个像下面这样的视图 create view v1 select aidAS ida。 从 t1 开始的created_dateAS created_date;使用 --no-data 选项,视图定义将更改为以下 create view v1 select 1 AS id, 1 AScreated_date

回答by Khaleel Hmoz

You Can Use MYSQL Administrator Tool its free http://dev.mysql.com/downloads/gui-tools/5.0.html

您可以免费使用 MYSQL 管理员工具 http://dev.mysql.com/downloads/gui-tools/5.0.html

you'll find many options to export ur MYSQL DataBase

你会发现很多选项可以导出你的 MYSQL 数据库

回答by Ant1Zykl0n

In case you are using IntelliJ you can enable the Database view (View -> Tools Window -> Database)

如果您使用 IntelliJ,您可以启用数据库视图(视图 -> 工具窗口 -> 数据库)

Inside that view connect to your database. Then you can rightclick the database and select "Copy DDL". Other IDEs may offer a similar function.

在该视图中连接到您的数据库。然后您可以右键单击数据库并选择“复制 DDL”。其他 IDE 可能提供类似的功能。

IntelliJ DDL

IntelliJ DDL

回答by Javier Larroulet

If you want to dump all tables from all databases and with no data (only database and table structures) you may use:

如果你想从所有数据库中转储所有表并且没有数据(只有数据库和表结构),你可以使用:

mysqldump -P port -h hostname_or_ip -u username -p --no-data --all-databases > db_backup.sql

This will produce a .sql file that you can load onto a mysql server to create a fresh database. Use cases for this are not many in a production environment, but I do this on a weekly basis to reset servers which are linked to demo websites, so whatever the users do during the week, on sunday nights everything rolls back to "new" :)

这将生成一个 .sql 文件,您可以将其加载到 mysql 服务器上以创建新的数据库。这在生产环境中的用例并不多,但我每周都会这样做以重置链接到演示网站的服务器,所以无论用户在一周内做什么,在星期天晚上一切都会回滚到“新”: )

回答by mias

To get an individual table's creation script:
- select all the table (with shift key)
- just right click on the table name and click Copy to Clipboard > Create Statement.

要获取单个表的创建脚本:
- 选择所有表(使用 shift 键)
- 只需右键单击表名,然后单击复制到剪贴板 > 创建语句。