登录数据库
mysql -u root -p
任意主机以用户 root 和密码 mypwd 连接到 mysql 服务器
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password' WITH GRANT OPTION;
flush privileges; #清除一下缓存 必须
IP 为 192.168.133.128 的主机以用户 myuser 和密码 mypwd 连接到 mysql 服务器
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'192.168.133.128' IDENTIFIED BY 'mypwd' WITH GRANT OPTION;
flush privileges;
如果远程无法连接 那么就是防火墙禁止了 3306 端口
vi /etc/sysconfig/iptables
增加下面一行:-A RH-Firewall-1-INPUT -m state --state NEW -m tcp -p tcp --dport 3306-j ACCEPT
service iptables restart
ps: iptables 设置
1) 重启后生效
开启:chkconfig iptables on
关闭:chkconfig iptables off
2) 即时生效,重启后失效
开启:service iptables start
关闭:service iptables stop
## 或者
-A INPUT -p tcp -m tcp --dport 3306 -j ACCEPT #DROP 禁止
修改 MySQL 的配置文件 /etc/mysql/my.cnf,因为默认 3306 端口只允许本地访问的,注释掉这行
#bind-address = 127.0.0.1
然后重启 Mysql,/etc/init.d/mysql restart
正文完