use mysql;
update user set host = '%' where user = '用户名';(如果写成host=localhost那此用户就不具有远程访问权限)
FLUSH PRIVILEGES;
第三步: 配置防火墙
如果系统装有防火墙iptables,得设置下
修改防火墙配置文件:
vi /etc/sysconfig/iptables
增加下面一行:
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport3306 -j ACCEPT
如果想开通21等端口,只需要将3306换成21等要开放的端口就可以了。
附:iptables
==============================================
# Firewall configuration written bysystem-config-securitylevel
# Manual customization of this file is not recommended.
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:RH-Firewall-1-INPUT - [0:0]
-A INPUT -j RH-Firewall-1-INPUT
-A FORWARD -j RH-Firewall-1-INPUT
-A RH-Firewall-1-INPUT -i lo -j ACCEPT
-A RH-Firewall-1-INPUT -p icmp –icmp-type any -j ACCEPT
-A RH-Firewall-1-INPUT -p 50 -j ACCEPT
-A RH-Firewall-1-INPUT -p 51 -j ACCEPT
-A RH-Firewall-1-INPUT -p udp –dport 5353 -d 224.0.0.251 -jACCEPT
-A RH-Firewall-1-INPUT -p udp -m udp –dport 631 -j ACCEPT
-A RH-Firewall-1-INPUT -m state –state ESTABLISHED,RELATED -jACCEPT
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 22-j ACCEPT
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 80-j ACCEPT
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport 21-j ACCEPT
-A RH-Firewall-1-INPUT -m state –state NEW -m tcp -p tcp –dport3306 -j ACCEPT
-A RH-Firewall-1-INPUT -j REJECT –reject-withicmp-host-prohibited
COMMIT
================================================
配置后,重新启动 iptable
service iptables restart
这时就可以从外网访问Mysql了。
第四步 测试
From remote system type command:
$ mysql -u webadmin –h 65.55.55.2 –p
第五 删除远程访问权限
如果不再需要远程访问了,想要删除远程访问权限,就把grant换成revoke命令,把命令中的to换成from,如下
授权的命令是
GRANT ALL PRIVILEGES ON *.* TO myuser@'%' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
那么去权的命令就是
REVOKE ALL PRIVILEGES ON *.* FROM myuser@'%';