Take the 2-minute tour ×

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?

share|improve this question
Do you expect mysql to selectively ignore SQL code in filename.sql? –  Álvaro G. Vicario Jun 15 '11 at 10:03
first make sure you have backed up only the schema , the command for importing will be same. –  Vamsi Jun 15 '11 at 10:06

4 Answers 4

up vote 1 down vote accepted

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.

share|improve this answer

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

share|improve this answer

if you want try this:

mysql -u USER -pPASSWORD database < database_schema.sql
share|improve this answer

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.

share|improve this answer

Your Answer


