Mysql 远程访问权限

1、改表法。
可能是你的帐号不允许从远程登陆,只能在localhost。这个时候只要在localhost的那台电脑,登入mysql后,更改 "mysql" 数据库里的 "user" 表里的 "host" 项,从"localhost"改称"%"

[root@cloud ~]# mysql -u root -p123456
mysql> use mysql;
mysql> update user set host = '%' where user = 'root';
mysql> select host, user from user;
mysql> flush privileges;
mysql> exit

2、授权法。例如,你想root在任何主机连接到mysql服务器的话。

mysql> GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'IDENTIFIED BY '123456' WITH GRANT OPTION;
mysql> flush privileges;
mysql> exit

如果你想允许用户test从ip为192.168.31.60的主机连接到mysql服务器,并使用mytest作为密码

如上授权后无法远程连接 可查看 /etc/my.cnf 是否有这句
bind-address = 127.0.0.1
有则将其注释 再重启下mysql 试试

mysql> GRANT ALL PRIVILEGES ON *.* TO 'test'@'192.168.31.60'IDENTIFIED BY 'mytest' WITH GRANT OPTION;
mysql> flush privileges;
comments powered by Disqus