This tutorial is going to show you how to migrate MySQL database from one server to another directly using only 1 command.
Firstly we will need to make sure the MySQL database, username and password on the new server exists. If so there is nothing to stop us doing it.
Here it is the line we have to execute from one of the servers:
Note: Please make sure that the server you are accessing remotely is allowing such access. For example if you are doing it from the new server you should be able to access the old server remotely.
mysqldump –add-drop-table -hOLDDBHOST -uUNAME -pPASSWORD DBNAME | mysql -hNEWDBHOST -uUNAME -pPASSWORD DBNAME
NOTE: This is 1 line command including the pipe!
ODLDBHOST: This is the hostname of the server we are migrating from.
NEWDBHOST: This is the hostname of the server we are migrating to.
UNAME: This is the username for accessing the database.
PASSWORD: This is the password for accessing the database.
DBNAME: This is the database name.
The line before the pipe e.g. | is dumping the database from the old server. The rest of the command is importing the database to the new server.