1. 程式人生 > >遠端連線CentOs7的mysql報錯:Can't connect to MySQL server on 'x.x.x.x' (10060)

遠端連線CentOs7的mysql報錯:Can't connect to MySQL server on 'x.x.x.x' (10060)

前提條件:
1.centos和windows的網路是互通的;
2.MySQL賦予了遠端連線的所有許可權

GRANT ALL PRIVILEGES ON *.* TO 'root' @ '%' IDENTIFIED BY 'myPassword' WITH GRANT OPTION;

問題:
centos7預設是沒有iptables的。根據網上的教程, 我禁用了firewalld,安裝iptables,並在iptables中開放了3306埠,可是遠端連線一直出錯,報錯10060.

解決:
關閉iptables,開啟firewalld,並在firewalld中開放3306埠。
1.關閉iptables:systemctl stop iptables


2.啟動防火牆:systemctl start firewalld
3.設定開機啟用防火牆:systemctl enable firewalld.service
4.檢視開放的埠:firewall-cmd --list-ports
在這裡插入圖片描述
5.開啟防火牆埠:firewall-cmd --zone=public --add-port=3306/tcp --permanent
在這裡插入圖片描述
6.重新載入配置:firewall-cmd --reload
在這裡插入圖片描述
7.檢視開放的埠:firewall-cmd --list-ports
在這裡插入圖片描述
最後,連線成功!
在這裡插入圖片描述