Copy and overwrite one database into another using mysql

Glitch answer is usually good, but stored procedures and functions will not be in backup, therefore not copied to second database.

This is why I always do (--routines can be used instead of -R in command below):

$ mysqldump ${source_db} -R | mysql ${dest_db}

In fact, as I make a regular dump for backup purposes, I prefer to use the backup dump itself, therefore keeping it in a file:

mysqldump ${source_db} -R > ${source_db}.sql
mysql ${dest_db} < ${source_db}.sql

Note: I always avoid -u and -p parameters, for security reasons.


It's not MySQL commands but it's the easiest method, from command line:

$ mysqldump -u user --password=pass live_db_name | mysql -u user --password=pass -h localhost duplicate_db_name

Works on Windows terminal too.