Home >Operation and Maintenance >CentOS >What to do if MySQL cannot connect remotely in CentOS
I cannot remotely connect to mysql under the Centos7 system. The following will introduce how to solve it for the reference of friends who also encounter this problem.
What to do if MySQL cannot be connected remotely in CentOS
There are two reasons why the MySQL database cannot be connected remotely:
1. The database is not authorized
2. The server firewall does not open port 3306
Recommended study:Linux video tutorial
The specific solution is as follows:
1. The database is not authorized
There is no authorization for the mysql database, so you only need to use 2 commands.
mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY '123456' WITH GRANT OPTION; mysql>FLUSH PRIVILEGES;
2. The server firewall does not open port 3306
centos has two firewalls, Firewalld and iptables firewall. Centos7 uses Firewalld firewall.
Firewalld is a front-end controller for iptables that implements persistent network traffic rules. It provides command line and graphical interfaces and is available in the repositories of most Linux distributions.
1. FirewallD firewall opens port 3306
firewall-cmd --zone=public --add-port=3306/tcp --permanent
Command meaning:
--zone #scope
--add-port= 3306/tcp #Add port, the format is: port/communication protocol
--permanent #Permanently effective, without this parameter it will be invalid after restart
Restart the firewall
systemctl restart firewalld.service
2. iptables development 3306 port
/sbin/iptables -I INPUT -p tcp -dport 3306 -j ACCEPT /etc/rc.d/init.d/iptables save
This article comes from the PHP Chinese website, CentOS usage tutorial column, please pay attention to this column for more related tutorials!
The above is the detailed content of What to do if MySQL cannot connect remotely in CentOS. For more information, please follow other related articles on the PHP Chinese website!