Categories
#DEV

Import MySQL Database via SSH

We have been migrating a lot of our MySQL databases across to Amazon RDS due to our extensive use of AWS services. In the process of doing this, we realized the traditional PhpMyAdmin UI doesn’t do the job anymore.

It will timeout, and we need to keep uploading the same SQL multiple times to get it to import bit by bit partially. It can become quite a handful and somewhat frustrating especially when your database is more than 100MB or so in size.

An alternative way is to import through good ole SSH. This is how we do it. We export the database SQL file. Then, we login to our remote database (Amazon RDS) and import it to that remote DB instance. These commands are not suitable for importing to localhost MySQL.

1) Login to your MySQL with root user by using the following command.

mysql -h main.xxxxxxxxxxx.us-east-1.rds.amazonaws.com -P 3306 -u YOURUSERNAME -p

2) Once you are in, you can select the database you want to import into by entering the following:

USE DATABASENAME;

3) You should get a successful database selected message. Then enter the following to import desired SQL file

SOURCE FILENAME.sql

4) You should get a whole load of queries being executed. After a while, it should stop and hopefully you have a fully imported database ready to be used.

Happy Migrating!