• rror querying database. Cause: java.sql.SQLException: null, message from server: "Host '192.168.30.1' is not allowed to connect to this MySQL server"


    连接远程Mysql的时候  出现如下错误

    org.apache.ibatis.exceptions.PersistenceException:
    ### Error querying database.  Cause: java.sql.SQLException: null,  message from server: "Host '192.168.30.1' is not allowed to connect to this MySQL server"
    ### The error may exist in UserMapper.xml
    ### The error may involve com.myth.mybatis.UserMapper.selectUser
    ### The error occurred while executing a query
    ### Cause: java.sql.SQLException: null,  message from server: "Host '192.168.30.1' is not allowed to connect to this MySQL server"
     at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:30)
     at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:150)
     at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:141)
     at org.apache.ibatis.session.defaults.DefaultSqlSession.selectOne(DefaultSqlSession.java:77)
     at MybatisTest.Test(MybatisTest.java:20)
     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
     at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
     at java.lang.reflect.Method.invoke(Method.java:483)
     at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:47)
     at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
     at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:44)
     at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
     at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:271)
     at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:70)
     at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:50)
     at org.junit.runners.ParentRunner$3.run(ParentRunner.java:238)
     at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:63)
     at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:236)
     at org.junit.runners.ParentRunner.access$000(ParentRunner.java:53)
     at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:229)
     at org.junit.runners.ParentRunner.run(ParentRunner.java:309)
     at org.junit.runner.JUnitCore.run(JUnitCore.java:160)
     at com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
     at com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
     at com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
     at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
    Caused by: java.sql.SQLException: null,  message from server: "Host '192.168.30.1' is not allowed to connect to this MySQL server"
     at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:964)
     at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:897)
     at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:886)
     at com.mysql.jdbc.MysqlIO.doHandshake(MysqlIO.java:1040)
     at com.mysql.jdbc.ConnectionImpl.coreConnect(ConnectionImpl.java:2198)
     at com.mysql.jdbc.ConnectionImpl.connectOneTryOnly(ConnectionImpl.java:2229)
     at com.mysql.jdbc.ConnectionImpl.createNewIO(ConnectionImpl.java:2024)
     at com.mysql.jdbc.ConnectionImpl.<init>(ConnectionImpl.java:779)
     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:408)
     at com.mysql.jdbc.Util.handleNewInstance(Util.java:425)
     at com.mysql.jdbc.ConnectionImpl.getInstance(ConnectionImpl.java:389)
     at com.mysql.jdbc.NonRegisteringDriver.connect(NonRegisteringDriver.java:330)
     at java.sql.DriverManager.getConnection(DriverManager.java:664)
     at java.sql.DriverManager.getConnection(DriverManager.java:208)
     at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.doGetConnection(UnpooledDataSource.java:201)
     at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.doGetConnection(UnpooledDataSource.java:196)
     at org.apache.ibatis.datasource.unpooled.UnpooledDataSource.getConnection(UnpooledDataSource.java:93)
     at org.apache.ibatis.datasource.pooled.PooledDataSource.popConnection(PooledDataSource.java:385)
     at org.apache.ibatis.datasource.pooled.PooledDataSource.getConnection(PooledDataSource.java:89)
     at org.apache.ibatis.transaction.jdbc.JdbcTransaction.openConnection(JdbcTransaction.java:138)
     at org.apache.ibatis.transaction.jdbc.JdbcTransaction.getConnection(JdbcTransaction.java:60)
     at org.apache.ibatis.executor.BaseExecutor.getConnection(BaseExecutor.java:336)
     at org.apache.ibatis.executor.SimpleExecutor.prepareStatement(SimpleExecutor.java:84)
     at org.apache.ibatis.executor.SimpleExecutor.doQuery(SimpleExecutor.java:62)
     at org.apache.ibatis.executor.BaseExecutor.queryFromDatabase(BaseExecutor.java:324)
     at org.apache.ibatis.executor.BaseExecutor.query(BaseExecutor.java:156)
     at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:109)
     at org.apache.ibatis.executor.CachingExecutor.query(CachingExecutor.java:83)
     at org.apache.ibatis.session.defaults.DefaultSqlSession.selectList(DefaultSqlSession.java:148)
     ... 25 more
     
    原因是:远程服务器不允许你的java程序访问它的数据库。所以,我们要对远程服务器进行设置,使它允许你进行连接。

    方案一:改表:

    use mysql

    update user set host = '%' where user='root';

    重启Mysql

     可以看到结果了

  • 相关阅读:
    linux 总结一下git reset的各个选项吧
    深入C++的new
    Android中binderDied()以及"Unknown binder error code" 出现的原因说明
    C/C++语言void及void指针深层探索
    Android 不通过USB数据线调试的方法
    Android Browser Gallery3D无法两指手势缩放
    Android eMMC Booting
    android基础知识13:AndroidManifest.xml文件解析
    Package sunjava6jdk is not available Ubuntu 10.04 LTS 安装sunjava6jdk ,出现错误
    SQL Server 2008中Service Broker基础应用(上)
  • 原文地址:https://www.cnblogs.com/mythdoraemon/p/9527295.html
Copyright © 2020-2023  润新知