Previously encountered MySQL local can connect but remote connection problem, no record, today on the Ucloud cloud on the new application on the server encountered this problem, record the resolution process.
1. Troubleshoot network or firewall issues
First see if you can ping the remote server, ping 192.168.1.211, if it is not a network problem. Then, check whether the port is blocked by the firewall, Telnet 192.168.1.211 3306, and if the connection fails, configure the firewall.
Configure the firewall to turn on port 3306
Vi/etc/sysconfig/iptables
-A input-m state–state new-m tcp-p tcp–dport 3306-j ACCEPT (Allow 3306 ports through the firewall)
/etc/init.d/iptables Restart (Restart the firewall for configuration to take effect)
2. Check MySQL configuration
If the firewall is turned on, Telnet still fails to view the port status of 3306 through Netstat:
Netstat-apn|grep 3360
TCP6 0 0 127.0.0.1:3306:::* LISTEN 13524/mysqld
Note the Red place, which shows that 3306 is bound to the local. Check the configuration of the my.cnf, where you can configure the binding IP address.
Bind-address=addr
No configuration or IP configuration of 0.0.0.0 indicates that all client connections are listening.
PS: I turned on port 3306, and after checking the MySQL configuration, telent still failed, but at native telnet is OK, and repeatedly confirmed that the configuration is not a problem. Later with our Ucloud account administrator to mention a bit, just know ucloud management background also need to open 3306 port, with Cloud server note this.
3. Check User access rights
MySQL when the user will be designated a host, the default is 127.0.0.1/localhost, then this user can only be native access, the other machine with this user account access will prompt no permissions, host changed to%, indicating that all machine access is allowed.
#mysql-U root-p
mysql> use MySQL;
Database changed
mysql> Update user set host= '% ' where user= ' root ';
Query OK, 0 rows Affected (0.00 sec)
Rows matched:1 changed:0 warnings:0
Mysql> select Host,user from user;
+ ——— –+ ——— +
| Host | user |
+ ——— –+ ——— +
| 127.0.0.1 | Root |
| % | Night |
+ ——— –+ ——— +
2 rows in Set (0.00 sec)
Finally, don't forget to restart MySQL for the configuration to take effect.
#/etc/init.d/mysql Restart
MySQL local can connect, remote connection not on the problem