Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Connect to mysql on Amazon EC2 from a remote server

I want to connect to db on EC2 from my local machine, I am not able to do and have tried everything- I am using this command to connect to EC2:

mysql -uUSERNAME -hEC2_IP -pPASSWORD 

This error is generated

ERROR 2003 (HY000): Can't connect to MySQL server on 'IP' (110)

I have modified my.cnf with

skip networking bind-address            = 0.0.0.0 

Still not able to connect to the database

like image 792
Aashish Katta Avatar asked Mar 19 '12 06:03

Aashish Katta


People also ask

Does MySQL allow remote connections?

The Remote Management tab is available when connecting to MySQL remotely, as the following figure shows. To access this tab, select a remote connection from the MySQL Connections pane or click New to create a new connection.

How does AWS connect to MySQL database?

Sign in to the AWS Management Console and open the Amazon RDS console at https://console.aws.amazon.com/rds/ . In the navigation pane, choose Databases to display a list of your DB instances. Choose the name of the MySQL DB instance to display its details. On the Connectivity & security tab, copy the endpoint.


2 Answers

as mentioned in the responses above, it could be related to AWS security groups, and other things. but if you created a user and gave it remote access '%' and still getting this error, check your mysql config file, on debian, you can find it here: /etc/mysql/my.cnf and find the line:

bind-address            = 127.0.0.1 

and change it to:

bind-address            = 0.0.0.0 

and restart mysql.

on debian/ubuntu:

/etc/init.d/mysql restart 

I hope this works for you.

like image 83
mohamed elbou Avatar answered Oct 02 '22 14:10

mohamed elbou


There could be one of the following reasons:

  1. You need make an entry in the Amazon Security Group to allow remote access from your machine to Amazon EC2 instance. :- I believe this is done by you as from your question it seems like you already made an entry with 0.0.0.0, which allows everybody to access the machine.
  2. MySQL not allowing user to connect from remote machine:- By default MySql creates root user id with admin access. But root id's access is limited to localhost only. This means that root user id with correct password will not work if you try to access MySql from a remote machine. To solve this problem, you need to allow either the root user or some other DB user to access MySQL from remote machine. I would not recommend allowing root user id accessing DB from remote machine. You can use wildcard character % to specify any remote machine.
  3. Check if machine's local firewall is not enabled. And if its enabled then make sure that port 3306 is open.

Please go through following link: How Do I Enable Remote Access To MySQL Database Server?

like image 21
Sandip Dhummad Avatar answered Oct 02 '22 13:10

Sandip Dhummad