MySQL 数据库复制 Clone/Copy MySQL Databases from Remote Servers

Scenario: I need to copy/clone a database from a remote server to my local MySQL server.

Steps:

  1. Generate SQL statements by reverse engineering the database on the remote server: [Execute on local machine] mysqldump -h remoteServerNameOrIP -u remoteUser -p remoteDatabaseName > temp.sql
  2. Executes the SQL generated to the local database: [Execute on local machine] mysql -u localUser -p localDatabaseName < temp.sql

Sample Session:

D:\>mysqldump -h 192.168.1.98 -u root -p meta > meta2009-01-15.sql
Enter password: // password used to log on the remote MySQL server

D:\>mysql -u root -p metaJack < meta2009-01-15.sql
Enter password: // password used to log on the local MySQL server

D:\>

Additional Thoughts:

  • If you drop the -h remoteServerNameOrIP argument, you can perform local copying;
  • What does copy/clone mean exactly? It means two things: 1. table/view ... creations; 2. data insertion. Note that it does not include database creation, so you need to create target database if it does not exist.