How do I import a local MySQL db to RDS db instance?

Derek picture Derek · Jul 31, 2012 · Viewed 47.3k times · Source

I've created a RDS instance called realcardiodb (the engine is mysql) and I've exported my database from my localhost. File is saved locally called localhostrealcardio.sql

Most research says to use mysqldump to import data from a local system to a web server, but my system doesn't even recognize mysqldump.

C:\xampp\mysql>mysqldump
'mysqldump' is not recognized as an internal or external command, operable program or batch   file. 

How do I resolve this error should I use mysqldump? (I definitely have mysql install on my system)

Is there a better utility I should use?

Any help is appreciated, especially if you have experience importing mysql to aws rds.

Thanks! DK

Update 7/31/2012 So I got the error resolved. mysqldump is in the bin directory C:\xampp\mysql\bin>mysqldump AWS provides the folloinwg instructions for uploading a local database to RDS:

mysqldump acme | mysql --host=hostname --user=username --password acme

Can someone break this down for me?

1) Is the first 'acme' (after mysqldump command) the name of my local database or the exported sql file I saved locally?

2)Is the hostname the IP address, Public DNS, RDS Endpoint or neither?

3)The username and password I assume is the RDS credentials and the second acme is the name of the database I created in RDS.

Thanks!

Answer

David Csonka picture David Csonka · Aug 1, 2012

This is how I did it for a couple instances that had data in the MySQl tables.

The steps to creating an RDS database instance: http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/CHAP_GettingStarted.CreatingConnecting.MySQL.html

Note: Make sure the RDS instance has a security group configured that relates to the EC2 security group. http://docs.amazonwebservices.com/AmazonRDS/latest/UserGuide/USER_Workin...

Before we go forward, let me provide a list of what some of the following placeholders are:

  • host.address.for.rds.server = this will be what is referred to as the "end point" in your RDS description/settings page.
  • rdsusername = the master user account which you created during RDS setup.
  • rdsdatabase = a blank database which you created inside the server on your RDS instance.
  • backupfile.sql = the sql dump file your made of your pre-existing installation's database.

Once you've created a fresh RDS database instance, and have configured its security settings, log into this server (from within an ssh session to your EC2 server) and then create an empty database inside the instance using basic SQL commands.

mysql -h host.address.for.rds.server -P 3306 -u rdsusername -p
(enter your password)
create database rdsdatabase;

Then quit out of the MySQL environment inside your RDS server.

\q

This tutorial assumes you already have a backup from your old database. If you don't, go create one now. After that, you’re ready to import that sql dump file into the empty database waiting on your RDS server.

mysql -h host.address.for.rds.server -u rdsusername -p  rdsdatabase < backupfile.sql

It might take a few seconds to complete, depending on the size of the sql dump file. Your indication that it is finished is that the bash command prompt reappears.

Note: the command “mysqlimport” is used when imported data directly into an existing table inside a database. It might seem like we’re “importing” data, but this is not what we’re actually doing in this situation. The database we are migrating to has no tables yet, and the sql dump file we’re using contains the sql commands to generate the tables it needs.

Confirm the Transfer

Now, if you didn't get any error messages, then your sql transfer probably worked. If you want, you can double check to see if it did by connecting to your RDS database server, looking up the database you created, and check to see if the tables are now present.

mysql -h host.address.for.rds.server -P 3306 -u rdsusername -p
(enter your password)
use rdsdatabase;
show tables;