Deploy Django using MySQL to AWS EC2 and RDS
Asked Answered
L

1

5

I'm trying out AWS EC2 and RDS. I had followed this tutorial and it worked, but the tutorial is missing a database migration. https://www.youtube.com/watch?v=YJoOnKiSYws So, could someone point me in the right direction to continue with the database migration?

I've tried https://support.cloud.engineyard.com/entries/21009887-Access-Your-Database-Remotely-Through-an-SSH-Tunnel but it didn't work for me because of an RDS permission issue.

I've also tried the instructions on Amazon, http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Overview.RDSSecurityGroups.html but it just confused me even more.
http://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/MySQL.Procedural.Importing.NonRDSRepl.html

I've posted a message on AWS forum, but no one answered. And I was hoping that someone here can help me out. I just need some plain simple example such as

step1.  From local pc export MySQL with mysqldump (done)
step2.  Upload local mysqldump.sql file to EC2  (I don't know how to do)
step3.  import mysqldump.sql on EC2 to RDS (I don't know how to do)
step4.  connect django web app to use new MySQL database that has data dump  (don't know how)

I really appreciate your help.

BTW, the data is in MySQL on my local computer running maverick OS (I hope that info is helpful).

Lani answered 24/3, 2014 at 0:59 Comment(0)
H
7

If you are using RDS you don't have SSH access so creating an SSH tunnel is not an option.

So what's missing from your question is whether you are in a VPC or not, so assuming you are not in a VPC. In essence:

  1. On the RDS security group, open the ingress EC2 security group that your EC2 instance you are going use to access the database with is in. For example, on the RDS console this shows up as the actual EC2 security group name

    EC2 RDS security group

(To get to Security groups click RDS->Security Groups->Create DB Security Group, you first new to create an DB Security Group to see the screenshot above or you can use the default DB Security Group):

  1. Dump your database on the server that you are running your original MySQL database. Hopefully this is the same server that is in the EC2 security group that you are allowing as an ingress on your RDS security group above: mysqldump -uroot -p <database-name> > database-name.sql

  2. Load the database from the EC2 instance in EC2 security group allowed by RDS security group:

    • mysql -uroot -h<RDS-hostname> -p < database-name.sql

    • The RDS hostname is something like this: database-name.xxxxxxxxxx.us-east-1.rds.amazonaws.com

  3. You don't have to connect to the RDS database to load a dump into it. But if you want to connect to it you can just run: mysql -uroot -p -h<RDS-hostname>

In case you you are in a VPC make sure that the EC2 instance that you are running the commands from is in the same VPC and subnet as your RDS instance. You have to create a VPC Subnet group for your VPC on the RDS console, this Subnet group has to be in two different Availability Zones if you are running a multi-az RDS instance. Other than that the procedure is the same.

Headspring answered 24/3, 2014 at 4:25 Comment(6)
Hi Rico, the explanation is super useful. Yes, RDS is in VPC. I think I had misunderstood the steps to get my data (which is on my local computer) into RDS. I will revised the question. Based on the traffic, at least several more people thought this question is worth reading. So I hope you can add more color to your answer.Lani
@Lani added details for a VPC. So it's basically the same procedure except that you have to make sure your RDS and EC2 instances are in the same VPC.Headspring
I'm new to AWS and I don't really know how to make sure the RDS and EC2 instances are in the same VPC. Actually, I searched all over and could not find the screenshot to your step(1). And for step(2). I don't know how to login to the EC2 server, so I can't do step(3). Thanks for help me out.Lani
Check my edit. You need to first create an RDS DB Security group in the RDS console to see the screenshotHeadspring
Thanks Rico. I truly appreciate your help and being very patient with my questions.Lani
@Lani no problem let me know if I can be of any other help.Headspring

© 2022 - 2024 — McMap. All rights reserved.