In this example, we’ll migrate/move a theoretical SQL database named twatdb from it’s current location on example.com over to the twat.ca server.
1. Export the database from the old server using “mysqldump”
For our example, let’s say our database is named “junglist”. Before transferring the database file to the new VPS, we first need to create a database dump on the original server using mysqldump:
mysqldump -u root -p –opt [database name] > [database file].sql
1 2 3 |
mysqldump -u root -p --opt twatdb > twatdb.sql |
2. Transfer the .sql database file to the new server
While there’s many different ways we could move our .sql file over to the new server (SFTP, rsync, etc.) we’re going to use “scp” (secure copy) in this example.
Syntax: scp [database name].sql [username]@[servername]:path/to/database/
Using scp, we’ll put the file in our home folder on the new server:
1 2 3 |
scp twatdb.sql username@twat.ca:~/ |
3. Import the database on the new server
Log in to your new server via SSH and import using mysql:
mysql -u root -p [database name] < [database file].sql
1 2 3 |
mysql -u root -p twatdb < ~/twatdb.sql |
Speak Your Mind