Softpedia
 

NEWS CATEGORIES:



NEWS ARCHIVE >>
SOFTPEDIA REVIEWS >>
MEET THE EDITORS >>
Home > News > Webmaster > Tips and Tricks

August 28th, 2007, 13:05 GMT · By Adrian Placinta

How to Copy an MYSQL Database from One Computer to Another

SHARE:

Adjust text size:


mysqldump --opt command
Enlarge picture
If you want to transfer a database to another system with a different architecture, try mysqldump to create a file with all the statements from your database. To see what options are available, type mysqldump --help. In addition, you can use mysql --opt command if you move the database to a newer version of MySQL. Using this argument, the dump file will be smaller and can be imported quickly.

One of the easiest ways to move a database is to run the following commands on the computer where the database is:
shell> mysqladmin -h 'other_hostname' create db_name
shell> mysqldump --opt db_name | mysql -h 'other_hostname' db_name


If
your network is slow and you want to copy the database from a remote computer, use the following commands:
shell> mysqladmin create db_name
shell> mysqldump -h 'other_hostname' --opt --compress db_name | mysql db_name


Another way is to use the mysqldump command to dump the database into a file, copy it to the other computer and load the file from there. The following command shows how to dump the database to a compressed file:
shell> mysqldump --quick db_name | gzip > db_name.gz

Copy the database file to the target computer and run the following commands:
shell> mysqladmin create db_name
shell> gunzip < db_name.gz | mysql db_name


For larger tables you can use mysqlimport command which is much faster. To use it, create the directory for the output files and dump the database:
shell> mkdir DUMPDIR
shell> mysqldump --tab=DUMPDIR db_name


DUMPDIR represents the full pathname of the directory you use to store the output from mysqldump.

After you create the directory and dump the database, move the files from DUMPDIR to the directory from the target computer where you will load the files into MYSQL:
shell> mysqladmin create db_name
shell> cat DUMPDIR/*.sql | mysql db_name
shell> mysqlimport db_name DUMPDIR/*.txt


The last step is to reload the grant table information using mysqladmin flush-privileges command.

TELL US WHAT YOU THINK:

26,428 hits · 5 comments · Link to this article · Print article · Send to friend · Subscribe to news

MUST-READ RELATED ARTICLES:


Ubuntu Ultimate Edition

Create MySQL database backup

Install and configure MySQL for Windows

Tips to Improve Joomla Performance

READER COMMENTS:


Comment #1 by: nabia on 05 Sep 2009, 21:33 UTC reply to this comment

It's a very helpful article. but i got confused in the very last step..

After you create the directory and dump the database, move the files from DUMPDIR to the directory from the target computer where you will load the files into MYSQL


do i need to first copy the DUMPDIR folder to my target computer and then follow with those commands or should i directly do it without copying DUMPDIR to the target remote computer?


Comment #2 by: GKG on 19 Aug 2010, 21:29 UTC reply to this comment

Thanks... It is really very helpful


Comment #3 by: codergirl on 26 Jan 2011, 22:30 UTC reply to this comment

Thank you, it helped :)


Comment #4 by: GUXO on 13 May 2011, 19:37 UTC reply to this comment

If I want to move all of my databases to a new computer, what happens if I just copy the directory "data" containing my databases to the new computer C:\Program Files\MySQL\MySQL Server 5.5\data ? Of course turning off the mysql service before on both PC s


Comment #5 by: Panks on 09 Oct 2011, 17:19 UTC reply to this comment

its a really helpful article for the budding software developers.

Copyright © 2001-2012 Softpedia. Contact/Tip us at

WindowsGamesDriversMacLinuxScriptsMobileHandheldNews

SUBMIT PROGRAM   |   ADVERTISE   |   GET HELP   |   SEND US FEEDBACK   |   RSS FEEDS   |   UPDATE YOUR SOFTWARE   |   ROMANIAN FORUM