Connect to MySQL on AWS from local machine

前端 未结 6 1893
轮回少年
轮回少年 2020-12-23 11:48

I am trying to set up a dev environment on my local machine that accesses a MySQL DB on AWS, but I keep getting a \"Can\'t connect\" message.

mysql_connect(\         


        
6条回答
  •  失恋的感觉
    2020-12-23 12:26

    I have been using MySQL Workbench http://www.mysql.com/products/workbench/ with RDS and it works great. Very easy to create and save a new database service instance. Click "New Server Instance" under "Server Administration" and follow the prompts. You will need to enter the information provided in the AWS RDS webpage for that instance (for example, it's endpoint).

    NOTE: In order for you to actually connect, you MUST add your IP address in the "DB Security Groups." The link is in the left-hand column, which is titled "Navigation." I use the "CIDR/IP" option (the other is EC2 Security Group). Make sure to include a "/##" after the IP, such as the "/32" they use in the example (you will see it on the page). In a few seconds, the IP address should be authorized.

    After that, go back to MySQL Workbench and complete the New Server Instance creation process.

    To use the connection, your code might look something like this (that excerpts of my Java code):

    String url = "jdbc:mysql://yourdatabasename.foo.us-east-1.rds.amazonaws.com:3306/";
    String userName = "your_user_name";
    String password = "your_password";
    String dbName = "your_db_name";
    String driver = "com.mysql.jdbc.Driver";
    Connection connection = DriverManager.getConnection(url + dbName, userName, password);
    

提交回复
热议问题