远程访问 MySQL

1:将 localhost 改成 “%”

修改 “mysql” 数据库里的 “user” 表里的 “host” 项,将”localhost”改成”%”

mysql>use mysql;

mysql>update user set host = ‘%’ where user = ‘root’;

mysql>select host, user from user;

mysql>FLUSH PRIVILEGES;

2:使用 myuser/mypassword 从任何主机连接到 mysql 服务器:

GRANT ALL PRIVILEGES ON . TO ‘myuser’@’%’ IDENTIFIED BY ‘mypassword’ WITH GRANT OPTION;

使用myuser/mypassword从ip为192.168.225.166的主机连接到mysql服务器:

GRANT ALL PRIVILEGES ON . TO ‘myuser’@’192.168.225.166’ IDENTIFIED BY ‘mypassword’ WITH GRANT OPTION;

3:泛授权

mysql -h localhost -u root

mysql>GRANT ALL PRIVILEGES ON . TO ‘root’@’%’ WITH GRANT OPTION; //赋予任何主机上以root身份访问数据的权限

mysql>FLUSH PRIVILEGES;[17]