首页 > 技术文章 > mysql Host 'XXX' is not allowed to connect to this MySQL server 解决方案

coates 2017-02-17 09:47 原文

在 Windows 主机中点击开始菜单,运行,输入“cmd”,进入控制台,然后cd 进入MySQL 的 bin 目录下(可以不用进入bin目录本在在这里已经实验),然后输入下面的命令。
        > MySQL -uroot -p123456                 (123456 为 root 用户的密码。)

如何开启MySQL的远程帐号-2)创建远程登陆用户并授权
        > grant all PRIVILEGES on *.* to root@'192.168.1.115'  identified by '123456';

上面的语句表示将数据库的所有权限授权给 root 这个用户,允许 root 用户在 192.168.1.115 这个 IP 进行远程登陆,并设置 root 用户的密码为 123456 。

当然也可单独给用户权限如下:

1,设置访问单个数据库权限

  mysql>grant all privileges on test.* to 'root'@'%';

2.设置访问全部数据库权限

   mysql>grant all privileges on *.* to 'root'@'%';

    说明:设置用户名为root,密码为空,可访问所有数据库*

 

3.设置指定用户名访问权限

  mysql>grant all privileges on *.* to 'testyonghu'@'%';

4.设置密码访问权限

  mysql>grant all privileges on *.* to 'zhangsan'@'%' IDENTIFIED BY '123456';

5.设置指定可访问主机权限

 grant all privileges on *.* to 'lisi'@'192.168.1.115';

 

====================================================================

所有的设置完之后,还需要  执行 mysql>  FLUSH PRIVILEGES;

然后退出mysql生效

推荐阅读