轉發:https://blog.csdn.net/qq_37655695/article/details/78042824
3、授權法:
[java] view plain copy
mysql> USE MYSQL;
mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION //賦予任何主機訪問以及修改所有數據的權限
例如,你想root用戶使用root從任何主機連接到mysql服務器的話。
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'root' WITH GRANT OPTION;
如果你想允許用戶root從ip為192.168.1.123的主機連接到mysql服務器,並使用root作為密碼
GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.1.123'IDENTIFIED BY 'root' WITH GRANT OPTION;
mysql> FLUSH PRIVILEGES //修改生效
最后:
防火牆開放3306端口
1、打開防火牆配置文件
vi /etc/sysconfig/iptables
?
2、增加下面一
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
?
3、更改后的防火牆配置文件
[java] view plain copy
# Firewall configuration written by system-config-firewall
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -m state --state ESTABLISHED,RELATED -j ACCEPT
-A INPUT -p icmp -j ACCEPT
-A INPUT -i lo -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 22 -j ACCEPT
-A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
-A INPUT -j REJECT --reject-with icmp-host-prohibited
-A FORWARD -j REJECT --reject-with icmp-host-prohibited
COMMIT
4、保存后重啟防火牆
service iptables restart (操作系統高得話這個命令不適合就用) systemctl restart iptables
