EC2 enables MySql remote access and ec2mysql Remote Access
Recently, MySql was installed on an Amazon cloud host and cannot be accessed remotely. After several pitfalls, the access was successful. Here we will record how to enable remote access after MySql is installed on EC2.
I. Problems Encountered
To remotely access MySql on EC2, the following message is displayed:
ERROR 2003 (HY000): Can't connect to MySQL server on 'xx.xx.xx.xx' (111)
Or
Host 'xx.xx.xx.xx' is not allowed to connect to this MySQL server
Ii. solution 1. Set the EC2 Firewall
EC2's default firewall blocks all traffic. Therefore, in addition to other necessary rules in EC2's Scurity Groups, you must add an ingress traffic rule:Any source IP connection of port 3306 of TCP is allowed.
.
2. Set User Access in MySql
By default, MySql only allows access from the local machine. To enable remote access, run the following commands in Terminal:
mysql -u root -puse mysqlupdate user set Host='%' where User='root'
In this way, you can access MySql from any IP address.
3. Bind IP addresses in MySql
sudo vim /etc/mysql/my.cnf
Thenbind-address 127.0.0.1
Changebind-address 0.0.0.0
In this way, no matter how the EC2 IP address changes, it can be remotely accessed.
4. Restart MySql
sudo /etc/init.d/mysql restart
Iii. References
Mysql initializes the root password and allows remote access
Connect to mysql on Amazon EC2 from a remote server
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.