Host '****' is not allowed to connect to this MySQL server

原创 2018年04月17日 18:14:07

错误信息

今天在VMWare上的Ubuntu上配置Solr服务时报错:

Caused by: java.sql.SQLException: null,  message from server: "Host 'DESKTOP-FG4HTMB' is not allowed to connect to this MySQL server"
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:965)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:898)
    at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:887)
    at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1038)
    at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2190)
    at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2221)
    at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2016)
    at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:776)
    at com.mysql.jdbc.JDBC4Connection.<init>(JDBC4Connection.java:47)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
    at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:386)
    at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:330)
    at org.apache.solr.handler.dataimport.JdbcDataSource$1.call(JdbcDataSource.java:192)
    at org.apache.solr.handler.dataimport.JdbcDataSource$1.call(JdbcDataSource.java:172)
    at org.apache.solr.handler.dataimport.JdbcDataSource.getConnection(JdbcDataSource.java:528)
    at org.apache.solr.handler.dataimport.JdbcDataSource$ResultSetIterator.<init>(JdbcDataSource.java:317)
    ... 14 more

错误分析与解决

报错原因:

本机的MySql服务只允许本机访问,未开启对其他计算机的访问权限。


进入MySql的cmd窗口,通过查询user表,可以看到当前的host模式:

mysql> use mysql
Database changed

mysql> select user,host from user;
+-----------+-----------+
| user      | host      |
+-----------+-----------+
| root      | localhost |
| mysql.sys | localhost |
+-----------+-----------+
2 rows in set (0.00 sec)

可以发现root用户的host=localhost,也就是说只允许本机访问。


通过update进行修改:

mysql> update user set host='%'where user='root';
Query OK, 1 row affected (0.00 sec)
Rows matched: 1  Changed: 1  Warnings: 0

mysql> select user,host from user;
+-----------+-----------+
| user      | host      |
+-----------+-----------+
| root      | %         |
| mysql.sys | localhost |
+-----------+-----------+
2 rows in set (0.00 sec)

将localhost修改成%。

重启Mysql服务

问题解决。


host=%的意义

%是通配符,host标识允许访问的IP地址。

例如:

  • host=localhost:只允许本机访问
  • host=192.168.7.%:只允许以192.168.7.为前缀的IP地址访问
  • host=%:允许所有IP地址访问
版权声明:本文为博主hanchao5272原创文章,转载请注明来源,并留下原文链接地址,谢谢! https://blog.csdn.net/hanchao5272/article/details/79978694

解决Navicat 报错:1130-host ... is not allowed to connect to this MySql server,MySQL不允许从远程访问的方法

http://blog.csdn.net/lhh1002/article/details/6131733
  • limuzi13
  • limuzi13
  • 2017-02-09 10:04:58
  • 5807

Host 'XXX' is not allowed to connect to this MySQL server解决方案

如何允许远程连接mysql数据库呢,操作如下: 首先登录账号 mysql -uroot -p 使用mysql用户 use mysql 如何开启MySQL的远程帐号,创建远程登陆用户并授权 gran...
  • tjcyjd
  • tjcyjd
  • 2016-08-12 22:33:49
  • 8947

mysql远程连接报错: Host * is not allowed to connect to this MySQL server,解决方法

解决此问题有以下2个方法: localhost改成% 1.进入mysql的BIN目录 注:root为管理员用户名,password为用户root的密码: mys...
  • dingqinghu
  • dingqinghu
  • 2016-07-17 09:41:42
  • 7789

解决mysql本地可访问,远程无法访问的问题 Host is not allowed to connect to this MySQL server

解决方法: 改表法。可能是你的帐号不允许从远程登陆,只能在localhost。这个时候只要在localhost的那台电脑,登入mysql后,更改 “mysql” 数据库里的 “user” 表里的 “h...
  • zml_2015
  • zml_2015
  • 2017-05-13 21:16:29
  • 1937

解决问题——SQLyog连接报错:Host ''xxx.xx.xxx.xxx'' is not allowed to connect to this MySQL server

登录mysql 并进入shell后: (执行下面的语句  *.*:所有库下的所有表   %:任何IP地址或主机都可以连接) GRANT ALL PRIVILEGES ON *.* TO 'root'@...
  • xuejingfu1
  • xuejingfu1
  • 2016-08-25 00:20:19
  • 1017

解决Navicat 报错:1130-host ... is not allowed to connect to this MySql server,MySQL

解决Navicat 报错:1130-host ... is not allowed to connect to this MySql server,MySQL 解决方法: ...
  • kingmax54212008
  • kingmax54212008
  • 2017-01-07 13:50:16
  • 5645

Host 'HostName' is not allowed to connect to this MySQL server

导读:   应用程序采用ODBC方式从本机登陆MySQL数据库,出现下面的提示:   [MySQL][ODBC 3.51 Driver]Host HostName is not allowed to...
  • rayleigh_w
  • rayleigh_w
  • 2007-12-26 21:22:00
  • 5620

ERROR 1130: Host '192.168.1.3' is not allowed to connect to this MySQL

当使用Mysql帐号远程登陆的时候,出现类似如下错误:ERROR 1130: Host 192.168.1.3 is not allowed to connect to this MySQL 解决办法...
  • zxyvb
  • zxyvb
  • 2008-05-20 15:21:00
  • 22365

E Host '192.168..' is not allowed to connect to this MySQL server 问题解决!

刚在虚拟机上面安装好MySQL,但是用工具远程连接时候,报错,在cmd模式下,telnet中报E Host '192.168..' is not allowed to connect to this ...
  • oraclemch
  • oraclemch
  • 2010-07-29 13:44:00
  • 3626

Host is not allowed to connect to this MySQL server解决方法

今天在Linux上面装完MySQL,却发现在本地登录可以,但是远程登录却报错Host is not allowed to connect to this MySQL server,找了半天试了网上的一...
  • bingjianIT
  • bingjianIT
  • 2017-01-12 22:46:38
  • 29148
收藏助手
不良信息举报
您举报文章:Host '****' is not allowed to connect to this MySQL server
举报原因:
原因补充:

(最多只允许输入30个字)