登录数据库
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
正文完