- 注册时间
- 2012-11-28
- 最后登录
- 2021-2-12
- 阅读权限
- 200
- 积分
- 3774
- 精华
- 0
- 帖子
- 116
  
ta_mind | mb_qb7 2013-3-19 01:56 |
---|
classn_01: 366 classn_02 [LV.9]以坛为家II
|
在我们使用mysql数据库时,有时我们的程序与数据库不在同一机器上,这时我们需要远程访问数据库。缺省状态下,mysql的用户没有远程访问的权限。下面介绍两种方法,解决这一问题。
1、改表法
可能是你的帐号不允许从远程登陆,只能在localhost。这个时候只要在localhost的那台电脑,登入mysql后,更改 "mysql" 数据库里的 "user" 表里的 "host" 项,从"localhost"改称"%"
mysql -u root -p
mysql>use mysql;
mysql>update user set host = '%' where user = 'root';
mysql>select host, user from user;
2、授权法
在安装mysql的机器上运行:
1、d:\mysql\bin\>mysql -h localhost -u root
//这样应该可以进入MySQL服务器
2、mysql>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%'WITH GRANT OPTION
//赋予任何主机访问数据的权限
例如,你想myuser使用mypassword从任何主机连接到mysql服务器的话。
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%'IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
如果你想允许用户myuser从ip为192.168.1.6的主机连接到mysql服务器,并使用mypassword作为密码
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'192.168.1.3'IDENTIFIED BY
'mypassword' WITH GRANT OPTION;
3、mysql>FLUSH PRIVILEGES
//修改生效
4、mysql>EXIT
退出MySQL服务器,这样就可以在其它任何的主机上以root身份登录
同理,hyper-v装了centos6.8, 通过NAT访问外网, 开了远程端口3306, 也给了root远程权限, 用navicat连接时提示网关不允许连接,
譬如:网关是192,.168.168.1, 就给它个远程连接权限 GRANT ALL PRIVILEGES ON *.* TO 'root'@'192.168.168.1' IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
搞掂!
|
|