AWS EC2 - Enable remote access on mysql
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
Go to your AWS console, select the instance where you host your database (MySQL).
Then select the security group
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 | CREATE USER 'foo'@'%' IDENTIFIED BY 'your-awesome-pass'; |
NOTE: bare in mind that 'foo'@'localhost'
& 'foo'@'%'
are consider as different user, you may have 2 different passwords for each of them
References: