MySQL 导入数据库架构

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

Import database schema

mysqlimportschema

提问by srahul07

I am having a mysqldump file which contains schema as well as data dump.

我有一个包含架构和数据转储的 mysqldump 文件。

I need to import only database schema from my sqldump. I tried with following command:

我只需要从我的 sqldump 导入数据库模式。我尝试使用以下命令:

mysql -uUSER -pPASSWORD < filename.sql

but of no help. it imports both schema as well as data.

但没有帮助。它同时导入模式和数据。

How can I do it?

我该怎么做?

采纳答案by álvaro González

IMHO, the easiest solution is to just open the dump in a regular text editor and copy the CREATE TABLE ...statements into another file. I would not even care about doing anything else.

恕我直言,最简单的解决方案是在常规文本编辑器中打开转储并将CREATE TABLE ...语句复制到另一个文件中。我什至不会关心做任何其他事情。

If that's not an option for whatever the reason, you can simply create a new dump and this time separate structure and data in two files.

如果这不是一个选项,无论出于何种原因,您都可以简单地创建一个新的转储,这次将结构和数据分离到两个文件中。

If that's not an option either, you can load the dump into a local MySQL server create the new dump from there, or use a GUI tool like HeidiSQL to transfer the structure right into the destination server.

如果这也不是一个选项,您可以将转储加载到本地 MySQL 服务器中,从那里创建新的转储,或者使用像 HeidiSQL 这样的 GUI 工具将结构直接传输到目标服务器。

回答by COMMANDER CAPSLOCK

Just in case you don't want to dump everything again and you just need it for some quick tests you could also cheat verydirty by using

万一你不想再转储一切,你只需要一些快速的测试,你也可以欺骗非常用脏

grep -ve '^INSERT' dump.sql > dump-no-data.sql

Don't use this for production environments though.

但是不要在生产环境中使用它。

回答by lethalMango

As far as I know you can't as if it's in the dump, it will be inserted again.

据我所知你不能好像它在转储中一样,它会被再次插入。

What you can do is dump a database without the data in the first place using the -no-dataoption:

您可以做的是首先使用以下-no-data选项转储没有数据的数据库:

mysqldump -u username -p -h localhost –no-data database_name > dump.sql

mysqldump -u username -p -h localhost –no-data database_name > dump.sql

回答by Spiros

if you want try this:

如果你想试试这个:

mysql -u USER -pPASSWORD database < database_schema.sql