问题
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