解决java.sql.SQLException: null, message from server: “Host ‘XXX‘ is not allowed to connect异常

Posted 只睡四小时

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了解决java.sql.SQLException: null, message from server: “Host ‘XXX‘ is not allowed to connect异常相关的知识,希望对你有一定的参考价值。

今天弄android studio的时候,数据库连接总是不行,一直超时没反应,仔细思考觉得是ip地址出了问题,在jdbc:mysql://xxxx:3306/DBname 这句语句中的xxxx具体写什么地址使我浪费了很多时间,不论是用公网ip地址还是私网ip地址还是本机地址127.0.0.1都没有用。
我公网ip地址和本机地址浪费了太多时间,因为这玩意用了第三方模拟器所以不能用本机地址,而经过chatgpt的指点后,我确定了应该把方向放在私网ip上,方向对了,问题就解决了。
而java.sql.SQLException: null, message from server: "Host ‘XXX’ is not allowed to connect,这就是我把方向放在私网ip后出现的问题。
解决办法:修改数据库权限


flush privileges是为了将权限更新操作刷新到内存中,而不用下次启动时生效。
不用这句话的话重启mysql服务也行。
上面操作执行完成之后就可以连接数据库了。

反思:此次解决问题花了很多时间,这个问题的产生原因是用了第三方模拟器不能直接连本地地址,但是我却不知道用哪个地址。
我应该:本机地址不行->换私网ip->解决私网ip的问题(数据库权限问题)->解决问题
但是我:本机地址不行->换公网ip->公网ip弹出的问题(超时)不是根本问题->解决了之后并不能解决问题

对策:以后解决问题首先要定位问题出现在哪里,然后把解决方案先列出来,以广度优先搜索的方式去试这些问题,不要太死磕一个方案,当一个方案行不通时要立刻换方案,然后继续深究。如:看报错定位是数据库问题,然后数据库问题肯定是这地址选用问题,到底选用什么地址就是关键问题。公网ip的超时问题不是根本问题,私网ip的服务器权限才是根本问题。

参考:https://blog.csdn.net/m0_37460012/article/details/90290148

解决sqoop导入报错:Caused by: java.sql.SQLException: Protocol violation

报错信息:

2017-06-15 15:02:15,374 INFO [main] org.apache.hadoop.mapred.MapTask: Ignoring exception during close for org.apache.hadoop.mapred.MapTask$NewTrackingRecordReader@7555b920
java.io.IOException: java.sql.SQLException: Protocol violation
    at org.apache.sqoop.mapreduce.db.DBRecordReader.close(DBRecordReader.java:173)
    at org.apache.hadoop.mapred.MapTask$NewTrackingRecordReader.close(MapTask.java:523)
    at org.apache.hadoop.mapred.MapTask.closeQuietly(MapTask.java:2004)
    at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:796)
    at org.apache.hadoop.mapred.MapTask.run(MapTask.java:341)
    at org.apache.hadoop.mapred.YarnChild$2.run(YarnChild.java:164)
    at java.security.AccessController.doPrivileged(Native Method)
    at javax.security.auth.Subject.doAs(Subject.java:422)
    at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1657)
    at org.apache.hadoop.mapred.YarnChild.main(YarnChild.java:158)
Caused by: java.sql.SQLException: Protocol violation
    at oracle.jdbc.driver.T4CTTIfun.readRXH(T4CTTIfun.java:631)
    at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:391)
    at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:227)
    at oracle.jdbc.driver.T4C7Ocommoncall.doOCOMMIT(T4C7Ocommoncall.java:75)
    at oracle.jdbc.driver.T4CConnection.doCommit(T4CConnection.java:641)
    at oracle.jdbc.driver.PhysicalConnection.commit(PhysicalConnection.java:3928)
    at oracle.jdbc.driver.PhysicalConnection.commit(PhysicalConnection.java:3934)
    at org.apache.sqoop.mapreduce.db.DBRecordReader.close(DBRecordReader.java:169)
    ... 9 more
2017-06-15 15:02:15,384 FATAL [main] org.apache.hadoop.mapred.YarnChild: Error running child : java.lang.OutOfMemoryError: Java heap space
    at java.lang.reflect.Array.newArray(Native Method)
    at java.lang.reflect.Array.newInstance(Array.java:75)
    at oracle.jdbc.driver.BufferCache.get(BufferCache.java:226)
    at oracle.jdbc.driver.PhysicalConnection.getCharBuffer(PhysicalConnection.java:7698)
    at oracle.jdbc.driver.OracleStatement.prepareAccessors(OracleStatement.java:1013)
    at oracle.jdbc.driver.T4CTTIdcb.receiveCommon(T4CTTIdcb.java:277)
    at oracle.jdbc.driver.T4CTTIdcb.receive(T4CTTIdcb.java:146)
    at oracle.jdbc.driver.T4C8Oall.readDCB(T4C8Oall.java:916)
    at oracle.jdbc.driver.T4CTTIfun.receive(T4CTTIfun.java:421)
    at oracle.jdbc.driver.T4CTTIfun.doRPC(T4CTTIfun.java:227)
    at oracle.jdbc.driver.T4C8Oall.doOALL(T4C8Oall.java:531)
    at oracle.jdbc.driver.T4CPreparedStatement.doOall8(T4CPreparedStatement.java:208)
    at oracle.jdbc.driver.T4CPreparedStatement.executeForDescribe(T4CPreparedStatement.java:886)
    at oracle.jdbc.driver.OracleStatement.executeMaybeDescribe(OracleStatement.java:1175)
    at oracle.jdbc.driver.OracleStatement.doExecuteWithTimeout(OracleStatement.java:1296)
    at oracle.jdbc.driver.OraclePreparedStatement.executeInternal(OraclePreparedStatement.java:3613)
    at oracle.jdbc.driver.OraclePreparedStatement.executeQuery(OraclePreparedStatement.java:3657)
    at oracle.jdbc.driver.OraclePreparedStatementWrapper.executeQuery(OraclePreparedStatementWrapper.java:1495)
    at org.apache.sqoop.mapreduce.db.DBRecordReader.executeQuery(DBRecordReader.java:111)
    at org.apache.sqoop.mapreduce.db.DBRecordReader.nextKeyValue(DBRecordReader.java:235)
    at org.apache.hadoop.mapred.MapTask$NewTrackingRecordReader.nextKeyValue(MapTask.java:556)
    at org.apache.hadoop.mapreduce.task.MapContextImpl.nextKeyValue(MapContextImpl.java:80)
    at org.apache.hadoop.mapreduce.lib.map.WrappedMapper$Context.nextKeyValue(WrappedMapper.java:91)
    at org.apache.hadoop.mapreduce.Mapper.run(Mapper.java:145)
    at org.apache.sqoop.mapreduce.AutoProgressMapper.run(AutoProgressMapper.java:64)
    at org.apache.hadoop.mapred.MapTask.runNewMapper(MapTask.java:787)
    at org.apache.hadoop.mapred.MapTask.run(MapTask.java:341)
    at org.apache.hadoop.mapred.YarnChild$2.run(YarnChild.java:164)
    at java.security.AccessController.doPrivileged(Native Method)
    at javax.security.auth.Subject.doAs(Subject.java:422)
    at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1657)
    at org.apache.hadoop.mapred.YarnChild.main(YarnChild.java:158)can

 

以上是关于解决java.sql.SQLException: null, message from server: “Host ‘XXX‘ is not allowed to connect异常的主要内容,如果未能解决你的问题,请参考以下文章

java.sql.SQLException: No suitable driver 问题解决

解决sqoop导入报错:Caused by: java.sql.SQLException: Protocol violation

java.sql.SQLException: 关闭的连接 解决办法

更新MySQL数据库( java.sql.SQLException: No value specified for parameter 1) 异常 解决方法

java.sql.SQLException:指定的 Oracle URL 无效错误

Java笔记-解决Cause: java.sql.SQLException: 试图在只读事务中修改数据(达梦数据库)