java.sql.SQLException: null, message from server: "Host 'XXXXX' is not allowed to connect
2020-02-29 22:54
465 查看
本人问题出现在,在linux的spark shell上,使用JDBC从其他数据库读取数据时,已导入mysql-connector-java-5.1.47-bin.jar包,运行代码时报错。
//以下xxx.xxx.xx.x为本机ip,saprksqltest为mysql的数据库名,data为数据库中表名 val jdbcDF = spark.read .format("jdbc") .option("url","jdbc:mysql://xxx.xxx.xx.x:3306/sparksqltest") .option("dbtable", "data") .option("user", "root").option("password","000000").load()
报错信息:
java.sql.SQLException: null, message from server: "Host 'xxx-xxx' 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) ...
查询确认为数据库服务器不允许远程连接,解决方法为:
-
如果安装有mysql的可视化界面:
1). 打开可视化界面并登陆
2). 找到mysql数据库,找到并打开其中的user表,修改host的值从localhost改为%(localhost表示只支持本地连接,不支持外网连接)
3). 执行代码刷新权限flush privileges; -
如果未安装mysql的可视化界面
1). 找到本地安装mysql的位置
2). 在bin目录下执行:mysql -u root -p 密码 登陆到mysql数据库
3). 执行代码use mysql,使用mysql数据库
4). 执行代码update user set host=’%’ where user =‘root’;
5). 执行代码刷新权限flush privileges;
以上执行完毕,即可用外网进行mysql连接测试
继续执行代码
//以下xxx.xxx.xx.x为本机ip,saprksqltest为mysql的数据库名,data为数据库中表名 val jdbcDF = spark.read .format("jdbc") .option("url","jdbc:mysql://xxx.xxx.xx.x:3306/sparksqltest") .option("dbtable", "data") .option("user", "root").option("password","000000").load()
显示连接成功
jdbcDF: org.apache.spark.sql.DataFrame = [id: int, name: string]
- 点赞 1
- 收藏
- 分享
- 文章举报
相关文章推荐
- java.sql.SQLException: null, message from server: “Host ‘xxx’ is not allowed to connect异常解决
- java.sql.SQLException: null, message from server: "Host 'xxx' is not allowed to connect
- java.sql.SQLException: null, message from server: “Host ‘xxx’ is not allowed to connect
- 远程mysql_java.sql.SQLException: null, message from server: "Host 'xxx' is not allowed to connect
- java.sql.SQLException:null, message from server: "Host '192.168.0.131' is not allowed to connect.
- java.sql.SQLException: null, message from server: “Host ‘xxx’ is not allowed to connect
- java.sql.SQLException: null, message from server: "Host '192.168.1.101' is not allowed to connect
- java.sql.SQLException: null, message from server: "Host 'xxx' is not allowed to connect
- 远程mysql_java.sql.SQLException: null, message from server: "Host 'xxx' is not allowed to connect
- java.sql.SQLException: null, message from server: "Host 'xxx' is not allowed to connect
- java.sql.SQLException: null, message from server: “Host ‘xxx’ is not allowed to connect
- 解决java.sql.SQLException: null, message from server: "Host 'XXX' is not allowed to connect异常
- java.sql.SQLException: null, message from server: "Host 'xxx' is not allowed to connect to this MySQ
- java.sql.SQLException: null, message from server: "Host 'xxx' is not allowed to connect
- java.sql.SQLException: null, message from server: "Host '10.11.3.67' is not allowed to connect to t
- java.sql.SQLException: null, message from server: “Host ‘xxx’ is not allowed to connect
- 远程mysql_java.sql.SQLException: null, message from server: "Host 'xxx' is not allowed to connect
- java.sql.SQLException: null, message from server: “Host ‘xxx’ is not allowed to connect
- Solr java.sql.SQLException: null, message from server: "Host 'xxx' is not allowed to connect to this MySQL server
- 远程mysql_java.sql.SQLException: null, message from server: "Host 'xxx' is not allowed to connect