Copying MySQL Databases to Another Machine
In cases where you need to transfer databases between different architectures, you can usemysqldumpto create a file containing SQL statements. You can then transfer the file to the other machine and feed it as input to themysqlclient.
Usemysqldump --helpto see what options are available.
The easiest (although not the fastest) way to move a database between two machines is to run the following commands on the machine on which the database is located:
If you want to copy a database from a remote machine over a slow network, you can use these commands:
You can also store the dump in a file, transfer the file to the target machine, and then load the file into the database there. For example, you can dump a database to a compressed file on the source machine like this:
Transfer the file containing the database contents to the target machine and run these commands there:
You can also usemysqldumpandmysqlimportto transfer the database. For large tables, this is much faster than simply usingmysqldump. In the following commands,DUMPDIRrepresents the full path name of the directory you use to store the output frommysqldump.
First, create the directory for the output files and dump the database:
Then transfer the files in theDUMPDIRdirectory to some corresponding directory on the target machine and load the files into MySQL there:
Do not forget to copy themysqldatabase because that is where the grant tables are stored. You might have to run commands as the MySQLrootuser on the new machine until you have themysqldatabase in place.
After you import themysqldatabase on the new machine, executemysqladmin flush-privilegesso that the server reloads the grant table information.
Note
You can copy the.frm,.MYI, and.MYDfiles forMyISAMtables between different architectures that support the same floating-point format. (MySQL takes care of any byte-swapping issues.) SeeSection 15.2, “The MyISAM Storage Engine”.