Spark报错:ClassNotFoundException: com.mysql.jdbc.Driver和Public Key Retrieval is not allowed

Posted 目标博客专家

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Spark报错:ClassNotFoundException: com.mysql.jdbc.Driver和Public Key Retrieval is not allowed相关的知识,希望对你有一定的参考价值。

Spark报错:ClassNotFoundException: com.mysql.jdbc.Driver和Public Key Retrieval is not allowed


执行下面这条往mysql数据库插入数据的语句,触发了下面两条错误:

data_df.write.jdbc(url,tablename,'append', prop)

错误一: ClassNotFoundException: com.mysql.jdbc.Driver

  • ClassNotFoundException: com.mysql.jdbc.Driver

错误一解决方法

  • 把mysql的jar包mysql-connector-java-5.1.49.jar放到pyspark的jars目录下/site-packages/pyspark/jars

错误二:Public Key Retrieval is not allowed

  • Public Key Retrieval is not allowed

错误二解决方法

  • 配置连接数据库的url时,加上&allowPublicKeyRetrieval=true
  • 代码中既可以加在url后面,也可以加在prop中,如下所示
  • “allowPublicKeyRetrieval”:“true”
prop="user":user,"password":password,"driver":"com.mysql.jdbc.Driver","allowPublicKeyRetrieval":"true"
data_df.write.jdbc(url,tablename,'append', prop)

错误三:Establishing SSL connection without server’s identity verification is not recommended

  • Establishing SSL connection without server’s identity verification is not recommended

错误三解决方法

  • url后面加上如下一串参数
  • ?useUnicode=true&characterEncoding=utf-8&useSSL=false
url='jdbc:mysql://10.10.128.146/unified_view_test?useUnicode=true&characterEncoding=utf-8&useSSL=false'

至此,并能够成功往mysql数据库中插入数据

以上是关于Spark报错:ClassNotFoundException: com.mysql.jdbc.Driver和Public Key Retrieval is not allowed的主要内容,如果未能解决你的问题,请参考以下文章

Spark SQL 报错总结

hive启动报错(整合spark)

Apache Spark启动spark-sql报错

实战技巧通过Spark日志文件定位作业报错或异常

spark编译报错信息简介

Spark 报错解决--Error initializing SparkContext