默认情况下,mysql帐号不允许从远程登陆,只能在localhost登录。这里提供了两种方法设置mysql可以通过远程主机进行连接。
1.改表
登入mysql后,更改 "mysql" 数据库里的 "user" 表里的 "host" 项,将"localhost"改称"%"
update user set host = '%' where user = 'root';
2.授权
myuser使用mypassword(密码)从任何主机连接到mysql服务器的话
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%'IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
如果你想允许用户myuser从ip为192.168.x.xx的主机连接到mysql服务器,并使用mypassword作为密码
- GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'192.168.x.xx'IDENTIFIED BY
- 'mypassword' WITH GRANT OPTION;
-
- FLUSH PRIVILEGES