Take the 2-minute tour ×

I have database on a server with 120 tables.

I want to clone the whole database with a new db name and the copied data.

Is there an efficient way to do this?

share|improve this question
add comment

3 Answers

up vote 33 down vote accepted
$ mysqldump yourFirstDatabase -u user -ppassword > yourDatabase.sql
$ mysql yourSecondDatabase -u user -ppassword < yourDatabase.sql
share|improve this answer
This is really nice and easy. Thank you! –  MartyIX Jun 23 '12 at 8:13
Probably obvious to most, but I missed it the first few times I tried it. This should be done from the regular command line, not from the mysql prompt. Also, you might want to add " -uroot" or whatever your user's name is, right after the "mysqldump" (1st line) and after the "mysql" (2nd line). –  charliepark Aug 28 '12 at 17:57
I'd vote this answer up, if it also included the user/password command line option –  superjos Oct 8 '12 at 10:36
I guess -ppassword is the same as --password=<password> (I don't know that command options)... so here's my vote ;) –  superjos Oct 9 '12 at 15:25
It should be noted that this does not create the new Database. You first need to create the new Database (in this example 'yourSecondDatabase' ) and then run the above commands. –  Kevin Bradshaw Jan 2 '13 at 10:31
show 1 more comment

In case you use phpMyAdmin

  1. Select the database you wish to copy (by clicking on the database from the phpMyAdmin home screen).
  2. Once inside the database, select the Operations tab.
  3. Scroll down to the section where it says "Copy database to:"
  4. Type in the name of the new database.
  5. Select "structure and data" to copy everything. Alternately, you can select "Structure only" if you want the columns but not the data.
  6. Check the box "CREATE DATABASE before copying" to create a new database.
  7. Check the box "Add AUTO_INCREMENT value."
  8. Click on the Go button to proceed.
share|improve this answer
Just what I look for. –  mmv-ru Jun 17 at 18:54
add comment
mysqldump -u <user> --password=<password> <DATABASE_NAME> | mysql -u <user> --password=<password> -h <hostname> <DATABASE_NAME_NEW>
share|improve this answer
Is this as fast as using mysqldump and mysqlimport as per these instructions? dev.mysql.com/doc/refman/5.5/en/copying-databases.html –  Adam Nelson Apr 5 '11 at 16:00
add comment

Your Answer


