Dump a MySQL database and restore it in another database

Suppose you want to copy one MySQL production database to another MySQL database (in the same server) to have the production data in another environment (development or pre-production, for example).

The command you can use is this:

mysqldump -u user_db_production -ppass_db_production --routines --triggers db_production | mysql -u user_db_development -ppass_db_development -A -Ddb_development

First, the command makes a dump for the production database. With a pipe, the command restore the dump in the devolopment database.

Be careful sending emails in the development or pre-production environments.

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.