Connect to mysql on Amazon EC2 from a remote server Connect to mysql on Amazon EC2 from a remote server mysql mysql

Connect to mysql on Amazon EC2 from a remote server


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.


There could be one of the following reasons:

  1. You need make an entry in the Amazon Security Group to allow remoteaccess from your machine to Amazon EC2 instance. :- I believe thisis done by you as from your question it seems like you already madean entry with 0.0.0.0, which allows everybody to access the machine.
  2. MySQL not allowing user to connect from remote machine:- Bydefault MySql creates root user id with admin access. But rootid's access is limited to localhost only. This means that root userid with correct password will not work if you try to access MySqlfrom a remote machine. To solve this problem, you need toallow either the root user or some other DB user to access MySQL from remotemachine. I would not recommend allowing root user id accessing DBfrom 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 enabledthen make sure that port 3306 is open.

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


Update: Feb 2017

Here are the COMPLETE STEPS for remote access of MySQL (deployed on Amazon EC2):-

1. Add MySQL to inbound rules.

Go to security group of your ec2 instance -> edit inbound rules -> add new rule -> choose MySQL/Aurora and source to Anywhere.

2. Add bind-address = 0.0.0.0 to my.cnf

In instance console:

sudo vi /etc/mysql/my.cnf

this will open vi editor.
in my.cnf file, after [mysqld] add new line and write this:

bind-address = 0.0.0.0

Save file by entering :wq(enter)

now restart MySQL:

sudo /etc/init.d/mysqld restart

3. Create a remote user and grant privileges.

login to MySQL:

mysql -u root -p mysql (enter password after this)

Now write following commands:

CREATE USER 'jerry'@'localhost' IDENTIFIED BY 'jerrypassword';CREATE USER 'jerry'@'%' IDENTIFIED BY 'jerrypassword';GRANT ALL PRIVILEGES ON *.* to jerry@localhost IDENTIFIED BY 'jerrypassword' WITH GRANT OPTION;GRANT ALL PRIVILEGES ON *.* to jerry@'%' IDENTIFIED BY 'jerrypassword' WITH GRANT OPTION;FLUSH PRIVILEGES;EXIT;

After this, MySQL dB can be remotely accessed by entering public dns/ip of your instance as MySQL Host Address, username as jerry and password as jerrypassword. (Port is set to default at 3306)