We often encounter this problem when managing databases from a remote computer
So this article will help you solve this problem
The test server uses CentOS7.5-MySQL5.5
You need to open theMySQLport first; otherwise, it will not connect even after configuration
If you are using aniptablesfirewall, you can open3306with the following operationsvi /etc/sysconfig/iptables #编辑防火墙配置文件
Add a line at the very bottom-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT:wq! #保存退出
Then you need to restart the firewallsystemctl restart iptables.service #重启防火墙使配置生效systemctl enable iptables.service #设置防火墙开机启动
The operation is very simple, just 5 steps, as follows:
First, connect to MySQL
mysql -uroot -p or /usr/local/mysql/bin/mysql -u root -p
Then, when Enter password: appears, enter your MySQL root password
If the following image appears, it means MySQL connected successfully
Enter the mysql table
use mysql;
View the user table
SELECT `Host`,`User` FROM user;
Update the permissions of the root user
UPDATE user SET `Host` = '%' WHERE `User` = 'root' LIMIT 1;
% can be changed to a specified IP
Force refresh permissions
flush privileges;
After completing the above steps, you can connect to the database remotely