In order to copy a database from another server, using ssh, you can follow these instructions:

Add your new server’s IP address to the old server’s remote MySQL configuration, like this:

– If using cPanel on your old server, simply access your cPanel interface > Remote MySQL and add here your new server’s IP address.

– If you are not using cPanel, the run these commands in SSH as root on the old server:

Enter mysql instance:

mysql

or

mysql -u user -p

and when prompted for a password, enter your MySQL server’s password.

after successfully entering the MySQL instance run the following:

GRANT ALL ON db_name.* TO db_user@’192.168.12.11‘ IDENTIFIED BY ‘Password‘;

Here:

db_name – name of the database you wish to copy

db_user – name of the associated database user

192.168.12.11 – your new server’s IP Address

Password – password for your database associated user

 

After successfully adding your new server’s IP to the old server’s remote MySQL, you can login to your new server and proceed with copying the database by entering this command in ssh as root:

mysqldump -h OLDHOST -u OLDUSER -p  --single-transaction OLD_DB | mysql NEW_DB

Here:

OLDHOST – Your old server’s IP address or hostname

OLDUSER – Username associated to your old mysql database

OLD_DB – Your old database name

NEW_DB – Your new MySQL Database from current server

After entering this command, you will be prompted for a password and you need to enter the password for the old database user.

If you entered the correct password, then the transfer procedure will begin and the new database will be automatically updated.

 

Leave a Reply