MySQL duplicate database quick tip!
- Published January 5th, 2006 in Tips & Tricks, MySQL
Here’s how you can quickly copy the contents of one database to another. First, create the new database
CREATE DATABASE db2;
Then, from the command-line, do the following:
$ mysqldump -u root --password=pass db1 | mysql -u root --password=pass db2
If anyone knows how to do this directly from the mysql environment it would be nice! :-)




hmmmm…. Why not system() in php?
http://www.php.net/system
I’m not aware of a way to do this through mysql statements… :-\
mysql> create database db2; \! /usr/local/mysql/bin/mysqldump -u root –password=pass db1 | /usr/local/mysql/bin/mysql -u root –password=pass db2
As root:
cp /var/lib/mysql/db1 /var/lib/mysql/db2
Rui Lapa, that won’t work for Innodb tables. ibdata1 typically resides on /var/lib/mysql/ and it’s the file that stores all Innodb tables from all databases in your box. By doing that you are simply leaving the data behind.