Home > Database > Mysql Tutorial > body text

What should I do if the remote connection to mysql fails?

王林
Release: 2020-09-30 09:20:02
Original
9697 people have browsed it

Solution to the failure of remote connection to mysql: 1. Configure the firewall and open port 3306; 2. Edit the my.cnf configuration file and bind the IP address; 3. Modify user access rights to allow access from all machines; 4. Restart mysql.

What should I do if the remote connection to mysql fails?

1. Troubleshoot network or firewall problems

(Recommended tutorial: mysql tutorial)

First check if you can ping the remote server, ping 192.168.1.211. If not, there is a network problem. Then, check whether the port is blocked by the firewall, telnet 192.168.1.211 3306, if the connection fails, configure the firewall.

Configure the firewall and open port 3306

vi /etc/sysconfig/iptables
-A INPUT -m state –state NEW -m tcp -p tcp –dport 3306 -j ACCEPT(允许3306端口通过防火墙)
/etc/init.d/iptables restart(重启防火墙使配置生效)
Copy after login

2. Check the MySQL configuration

If the firewall is enabled and telnet still fails, check the port status of 3306 through netstat:

netstat -apn|grep 3306
tcp6  0  0 127.0.0.1:3306  :::*  LISTEN    13524/mysqld
Copy after login

Pay attention to the place, this shows that 3306 is bound to the local. Check the configuration of my.cnf, where you can configure the binding IP address.

bind-address=addr
Copy after login

If not configured or the IP is configured as 0.0.0.0, it means monitoring all client connections.

ps: I opened port 3306 and checked the MySQL configuration. Telent still failed, but telnet on the local machine was ok. I repeatedly confirmed that there was no problem with the configuration. Later, I mentioned it to our ucloud account administrator and found out that the ucloud management backend also needs to open port 3306. Those who use cloud servers should pay attention to this.

3. Check user access permissions

MySQL will specify a host when creating a user. The default is 127.0.0.1/localhost. Then this user can only access the local machine. Others If the machine is accessed using this user account, it will prompt that there is no permission. If the host is changed to %, it means that all machines are allowed to access.

What should I do if the remote connection to mysql fails?

4. Restart mysql to make the configuration take effect.

Related recommendations: php training

The above is the detailed content of What should I do if the remote connection to mysql fails?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template