Migrate a MySQL database to another Linux server using the command line

Problem:

I have a MySQL database on one server and I need to move it to another one but don’t have access to any GUI client that will make it possible to drag & drop (eg Navicat)

Solution:

1. Make a dump of the db

# mysqldump -uroot -p mydb > dumpfile.sql

2. Use rsync from the new server to get the dump file (SCP or similar would also work)

# rsync -avr root@myolddbserver:/home/mydumpfolder/dumpfile.sql .

3. log into mysql client on new server

# mysql -u root -p

4. make the database

mysql> create database mydb;

5. select the new database;

mysql> use mydb;

6. load the data

mysql> source dumpfile.sql

3 thoughts on “Migrate a MySQL database to another Linux server using the command line

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>