Import database schema

╄→гoц情女王★ 提交于 2020-01-13 04:13:38

问题


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

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

mysql -uUSER -pPASSWORD < filename.sql

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

How can I do it?


回答1:


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.

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.




回答2:


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

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

Don't use this for production environments though.




回答3:


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-data option:

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




回答4:


if you want try this:

mysql -u USER -pPASSWORD database < database_schema.sql


来源:https://stackoverflow.com/questions/6355996/import-database-schema

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!