I think most of us know that enable remote access, need to create a new user with % host.

But in EC2, there are some security config need to be done.

Update the security group of the EC2 instance

EC2 instance list

Go to your AWS console, select the instance where you host your database (MySQL).

EC2 security group

Then select the security group

EC2 security group add rule

Make sure you add a rule in the In bound there, for MySQL, and set the IP to 0.0.0.0

Update the mysql binding address

Edit the file /etc/mysql/my.cnf, and change the binding address to 0.0.0.0

(EDIT: 2019-04-04, you may also update the file /etc/mysql/conf.d/mysql.cnf
, for newer version of MySQL. Thanks for Dawood pointing out.)

1
bind-address = 0.0.0.0

then restart mysql server

1
$ sudo /etc/init.d/mysql restart

Create a new user for any host in MySQL

1
2
3
4
CREATE USER 'foo'@'%' IDENTIFIED BY 'your-awesome-pass';

# grant privileges to table(s)
GRANT ALL PRIVILEGES ON db_name.* TO 'foo'@'%' WITH GRANT OPTION;

NOTE: bare in mind that 'foo'@'localhost' & 'foo'@'%' are consider as different user, you may have 2 different passwords for each of them

References: