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?
If you need to duplicate the table structure, but not its data, it is better to use the CREATE TABLE ... LIKE statement. In case you need to copy the table structure including primary keys, foreign keys and constraints, run the SHOW CREATE TABLE ...
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.
You can take backup using mysqldump and restore with mysql using commandline.
For backup database
$ mysqldump -u root-pPassword -P3309 --routines --no-data testdb > "d:\dbwithnodata.sql"
For restoration of database
$ mysql -u root-pPassword -P3309 newdb < "d:\dbwithnodata.sql"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With