Cause of the problem: The connected user account does not have the permission to connect remotely, and can only log in to the local machine (localhost).
solution:
1. Turn off the firewall or open a certain port in the firewall
// 关闭防火墙
systemctl stop firewalld
// 或者不关闭防火墙打开端口
firewall-cmd --zone=public --add-port=3306/tcp --permanent
firewall-cmd --reload #重载防火墙配置
firewall-cmd --list-all #查看开放的端口
2. Modify the database table
// 登录数据库执行
update user set Host='%' where User='root';
flush privileges;
Change the host item in the user table in the mysql database from "localhost" to "%"
3. Authorize
// 授权 myuser 使用 mypassword 从任何主机连接到 mysql 服务器
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
flush privileges;
// 授权用户 myuser 从 IP 为 192.168.1.3 的主机连接到 mysql 服务器,并使用 mypassword 作为密码
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'192.168.1.3' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
flush privileges;