Daily Archives: March 31, 2010


How to copy a mysql database

While there is no “copy database” function for mysql, there is a way to automate the process better than saving a bunch of SQL to a file, then uploading the file. Mysqldump offers a way to copy a database to another existing database on the same server or a remote server. The official documentation is here http://dev.mysql.com/doc/refman/5.0/en/mysqldump.html , although their syntax doesn’t include the required username and password login syntax (if your database server requires a login, I hope).

Use the following on linux –
mysqldump nameofdatabase1 -u root -p | mysql –host=localhost -u root -p -C nameofdatabase2;

You’ll be prompted for the password and you’ll need to enter it twice. If your destination database is remote, then replace localhost with the IP address.