Recently installed MySQL on the Amazon Cloud host, want to remote access, the results can not be accessed anyway. After stepping on a few pits, finally the visit succeeded, here to do a record: How to turn on remote access after MySQL is installed on EC2.
First, the problems encountered
To remotely access MySQL on EC2, always tip:
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 up the EC2 firewall
EC2 The default firewall is to block all traffic, so in addition to the other necessary rules in EC2 's scurity groups, add an ingress traffic rule: TCP的3306端口的任意源IP的连接都允许
.
2. Set user's access in MySQL
MySQL is only allowed to be accessed from the native computer by default, and to enable remote access, execute the following command in terminal, respectively:
mysql -u root -puse mysqlupdate user set Host=‘%‘ where User=‘root‘
This will enable MySQL to be accessed from any IP.
3. Set the binding IP in MySQL
sudo vim /etc/mysql/my.cnf
Then change bind-address 127.0.0.1
to bind-address 0.0.0.0
, so EC2 IP no matter how changes, can be remotely accessed.
4. Restart MySQL
sudo /etc/init.d/mysql restart
Third, reference
MySQL initializes the root password and allows remote access
Connect to MySQL in Amazon EC2 from a remote server
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
EC2 turn on MySQL remote access