copy database structure without data in mysql (with empty tables)

Pramod picture Pramod · Jan 1, 2013 · Viewed 56.7k times · Source

Is there any way to copy database structure without data in MySQL, so the new database will be the same as it is copied from, but with empty tables.

After getting some suggestions I tried the command, but I am getting syntax error, my username = root and password = nothing. I guess the default one. I am trying following command,

mysqldump -u root -p -d xyz_db | mysql -u root -p -Dnew_db

what I am missing or misplacing in command?

Answer

Raab picture Raab · Jan 1, 2013
mysqldump -u user -ppass -d olddb | mysql -u user -ppass -D newdb

The new database must already exist. The -d flag in the mysqldump command prevents copying of data.

There's no space between the flag -p and the password.