Solution to MySQL remote connection failure (centos)
(1) Stop the MySQL service first.
#/Etc/init. d/mysqld stop
(2) view the MySQL configuration file
# Vi/etc/My. CNF
Pay special attention to the following two items: bind_address and skip_networking. bind_address cannot be 127.0.0.1; otherwise, it can only be connected locally and skip_networking cannot appear, otherwise, only the UNIX socket is accepted and the TCP socket service is not available. We recommend that you comment out bind_address and skip_networking directly.
(3) restart the MySQL Service
#/Etc/init. d/mysqld start
(4) authorize the user to allow remote access by the specified user. The simplest way is to set the host of the user in the User table in the MySQL database to %, that is, allow remote access from any IP address.
# Mysql-u root-ppassword // enter the MySQL Console
# Mysql> use MySQL;
# Mysql> Update user set host = '%' where user = 'root'; // you can skip this error when executing this command.
# Mysql> flush privileges;
# Mysql> select host, user from user; // check whether '%' is inserted into the database
# Mysql> \ q
(5) In general, remote access can be satisfied at this time, but some systems still need to check firewall settings and IP access policies, in case that the system cannot remotely access MySQL due to network access restrictions
For centos systems, it is best to check iptables settings. The procedure is as follows:
5.1 suspend the iptables service
# Service iptables stop
5.2 view the iptables configuration file
# Vi/etc/sysconfig/iptables
5.3 you may see the following content
: Output accept [1009120: 257185920]
-A input-p tcp-m tcp-dport 3306-J accept
#-A input-s 118.144.89.18-p tcp-m tcp-dport 3306-J accept
#-A input-s 123.127.177.239-p tcp-m tcp-dport 3306-J accept
We recommend that you open port 3306 directly, instead of specifying an IP address to access port 3306.
5.4 restart the iptables service
# Service iptables start