How to transfer a MySQL database to another server?
You can import the database to the new server by using phpMyAdmin but it will take a lot of time if the database size is large. So, the best and easiest solution that I would suggest is, transfer the database by using SSH.
To do that, you must make sure you have SSH access in both servers – old and new server. You can request the access by contacting your hosting provider to enable it for you.
Old Server
- Telnet/SSH into the old server.
- Backup your database by issuing this command:
mysqldump –opt -Q -u USERNAME -p DATABASENAME > /PATH/TO/DATABASENAME.sql
- Use the MySQL database password when the old server asks for password.
- Then, zip the file to reduce the file size:
zip DATABASENAME.zip DATABASENAME.sql
- Done.
- USERNAME – This is the username that you use to access MySQL.
- DATABASENAME – Name of the database.
- /PATH/TO/DATABASENAME.sql – The path of the database file that will be created.
New Server
- Telnet/SSH into the new server.
- Download DATABASENAME.zip from the old server:
wget www.oldserver.com/PATH/TO/DATABASENAME.zip
- Unzip the file:
unzip DATABASENAME.zip
- Import the database file into your new server:
mysql -u NEWUSERNAME -p NEWDBNAME < /PATH/TO/NEW/DATABASENAME.sql
- Use the new MySQL database password when the server asks for password.
- Done.
- NEWUSERNAME – This is the new username that you use to access MySQL.
- NEWDBNAME – Name of the new database.
- /PATH/TO/NEW/DATABASENAME.sql – The path of the database file that you have extracted in New Server – Step 3.
No comments:
Post a Comment