array(2) { ["docs"]=> array(0) { } ["count"]=> int(0) } 111string(0) "" int(1) int(10) int(70) int(8640000) string(13) "likecs_art_db" array(1) { ["query"]=> array(1) { ["match_all"]=> object(stdClass)#30 (0) { } } } array(1) { ["createtime.keyword"]=> array(1) { ["order"]=> string(4) "desc" } } int(10) int(0) int(8640000) array(2) { ["docs"]=> array(0) { } ["count"]=> int(0) } MySql 只能localhost 和 127.0.0.1访问 不能通过其他IP访问 - 爱码网

    问题描述:想在远程主机访问本机的MySql时,总是无法连接。本机也只能用localhost和127.0.0.1访问,不可以用192.168.*.*等IP访问。

 

  解决方案:cmd下连接到mysql,执行一下命令: grant all privileges on *.* to root@'%' identified by 'your root password';

        返回信息:Query OK, 0 rows affected (0.03 sec)

        之后就远程主机就可以正常连接本机的MySql了。

        关于这条命令啥意思,大家自己百度下吧。

 

  过程说明:首先,远程主机无法访问本机服务,情况可能是有很多的,如防火墙、网络不通等原因。这些本文都不做考虑。

        在没有执行上面的命令之前,在MySql下的“mysql”数据库下,有个“user”表,里面有如下数据(见图):

                     MySql 只能localhost 和 127.0.0.1访问  不能通过其他IP访问

        执行命令之后,“user”表增加了一条数据(见图):

                     MySql 只能localhost 和 127.0.0.1访问  不能通过其他IP访问

 

        当然,用户可以是自己另外新建的用户,不一定非得root。

        刚开始一直出错,是因为使用了这个命令: grant all privileges on *.* to root@'%';      ---->后面没有加  identified by 'your root password'

        错误信息:ERROR 1133 (42000): Can't find any matching row in the user table 

 

          完毕!

        

相关文章: