1、改表法:在本机登入mysql后,更改“mysql”数据库里的“user”表里的“host”项,从”localhost”改为' % '。
mysql>
mysql>use mysql;
mysql>select 'host' from user where user='root';<wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>#查看mysql库中的user表的host值(即可进行连接访问的主机/IP名称)<br><br> mysql>update<span style="color:rgb(77,109,243); word-wrap:normal; word-break:normal">user</span>set host = '<span style="color:rgb(237,28,36); word-wrap:normal; word-break:normal">%</span>'<wbr>where user ='<span style="color:rgb(77,109,243); word-wrap:normal; word-break:normal">root</span>'; #修改host值(以通配符%的内容增加主机/IP地址,当然也可以直接增加某个特定IP地址,如果执行update语句时出现<strong>ERROR 1062 (23000): Duplicate entry '%-root' for key 'PRIMARY'</strong>错误,需要<strong>select host from user where user = 'root';</strong><br> 查看一下<strong>host是否已经有了%这个值</strong>,如果有了直接执行下面的<strong>flush privileges;</strong>即可)<br> mysql>flush privileges;<br> mysql>select host,user from user where user='root';<br> mysql>quit<br><br> 退出后会回到DOS正常的提示符状态,此时可以通过远程连接Mysql了!</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
========================================<wbr><wbr></wbr></wbr>
2. 授权法。例如,你想myuser使用mypassword从任何主机连接到mysql服务器的话。
为mysql创建一个远程连接用户:
grant<wbr>all<wbr>privileges<wbr>on<wbr>*.*<wbr>to<wbr>remoteuser@remoteIPAddr<wbr>identified<wbr>by<wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>'password'; (remoteIPAddr是指远程客服端ip)
例如:grant<wbr>all<wbr>privileges<wbr>on<wbr>*.*<wbr>to<wbr><a target="_blank" href="mailto:myuser@192.168.0.10" style="color:rgb(27,113,155); text-decoration:none">myuser@192.168.0.10</a><wbr>identified<wbr>by<wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>'shihuan';
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'%'IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
如果你想允许用户myuser从ip为192.168.0.10的主机连接到mysql服务器,并使用mypassword作为密码
GRANT ALL PRIVILEGES ON *.* TO
'myuser'@'192.168.0.10'IDENTIFIED BY 'mypassword' WITH GRANT OPTION;
<wbr><wbr><wbr><wbr>我的mysql.user里root用户的host果然是localhost,先用改表法给localhost改成“%”,还是不行,仍然报1130的错误,又按“从任何主机连接到mysql服务器”方法授权,还是报一样的错,最后给自己的ip授权之后,终于登录上了。</wbr></wbr></wbr></wbr>
|