Gaurav Gupta
Gaurav Gupta

Reputation: 445

Making MySQL connection on AWS

I am writing MySQL code using Python using MySQL Connector. Code is - enter image description here

I have implemented this locally, and it is working properly. Now I want to deploy this file on AWS server. Its not working over there. What changes should I make, so that this code work on AWS server as well.

Thank you!!

Upvotes: 0

Views: 162

Answers (2)

Achyut Vyas
Achyut Vyas

Reputation: 501

@Mayank Raj's answer is right, although I want to add something. if you want to deploy database server on RDS or any other server make sure you allow Port 3306 (MySQL Port) in the security group of EC2 instance.

Upvotes: 1

Mayank Raj
Mayank Raj

Reputation: 1624

Depending on where you are hosting the database, the connection details would change accordingly:

  1. Hosting Database yourself on the server itself (not recomended): If your database instance lies on the same server then your code should work as it is. This is because the host will still be localhost and you have configured the credentials appropriately. In cloud enviornment this is not recomended for various reasons - if your instance goes down, the database goes down as well and more importantly you will have to manage the database which includes things like backups, mirroring, scaling etc
  2. Use Amazon Relational Database service - RDS (recomended): Depending on the type of security you want to implement, you can take any one of the routes mentioned here. Essentially you use the endpoint of the RDS instance as the host. As for authentication, you can go the normal route of configuring username and password when configuring the instance.

RDS is the recomended way to go as being a managed service, you offload a lot of heavy lifting that comes with managing a database to AWS. If you are starting out, RDs also Free Tier bundle (link)

Note: While provisioning the RDS instance or whike updating it, be sure to mark the option of "Enable Internet Access". This will make it possible for you to access the database via the internet eg outside the VPC, from your home etc

Upvotes: 3

Related Questions