Copying a MySQL database from one server (MySQL server/host) to another may be done using a simple two-step process.
STEP 1: Backup the database on the source server
The mysqldump utility can be used to backup the database on the source server. An example using the root account is provided below:
mysqldump -u root --databases mytestdb > mytestdb.sql |
NOTE:The "–databases" option above ensures that a "CREATE" statement for the database is written to the backup SQL, thereby enabling you to restore the database to a server where the empty database does not exist. If you do not use the "–databases" option before the database name, then the backup will still work, but in this case, you must have an empty database of the same name existing on the target server (no CREATE statement in SQL).
STEP 2: Restore the database on the target server
Restoring the database on the target server simply involves executing the "backup SQL" created on the source server.An example using the root account is provided below:
mysql --password=XXXXX < mytestdb.sql |