Python MySQL Spark(java.lang.ClassNotFoundException:com.mysql.jdbc.Driver)

问题描述 投票:0回答:1

我正在尝试使用PySpark,但面临以下问题。我不是很了解这个问题,但似乎我的计算机找不到“ com.mysql.jdbc.Driver”驱动程序。我使用的是Mac OS,因此我已经在https://dev.mysql.com/downloads/connector/python/上下载了“ .pkg” MySQL连接器,然后安装了它。但是它仍然不起作用,并且出现以下错误。

Py4JJavaError: An error occurred while calling o36.load.
: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
    at java.base/java.net.URLClassLoader.findClass(URLClassLoader.java:466)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:563)
    at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496)
    at org.apache.spark.sql.execution.datasources.jdbc.DriverRegistry$.register(DriverRegistry.scala:45)
    at org.apache.spark.sql.execution.datasources.jdbc.JDBCOptions$$anonfun$5.apply(JDBCOptions.scala:99)
    at org.apache.spark.sql.execution.datasources.jdbc.JDBCOptions$$anonfun$5.apply(JDBCOptions.scala:99)
    at scala.Option.foreach(Option.scala:257)
    at org.apache.spark.sql.execution.datasources.jdbc.JDBCOptions.<init>(JDBCOptions.scala:99)
    at org.apache.spark.sql.execution.datasources.jdbc.JDBCOptions.<init>(JDBCOptions.scala:35)
    at org.apache.spark.sql.execution.datasources.jdbc.JdbcRelationProvider.createRelation(JdbcRelationProvider.scala:32)
    at org.apache.spark.sql.execution.datasources.DataSource.resolveRelation(DataSource.scala:318)
    at org.apache.spark.sql.DataFrameReader.loadV1Source(DataFrameReader.scala:223)
    at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:211)
    at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:167)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:564)
    at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244)
    at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357)
    at py4j.Gateway.invoke(Gateway.java:282)
    at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)
    at py4j.commands.CallCommand.execute(CallCommand.java:79)
    at py4j.GatewayConnection.run(GatewayConnection.java:238)
    at java.base/java.lang.Thread.run(Thread.java:844)

我的python代码如下:

dataframe_mysql = sqlContext.read.format("jdbc").options(
url ="jdbc:mysql://XXXXXXXXX:PWDDDDDD@XXXXXXXXJDDD/"+newDatabaseName,
driver="com.mysql.jdbc.Driver",
dbtable="Scores",
user="XXXXXXXXX",
password="PWDDDDDD"
).load()
python mysql apache-spark jdbc pyspark
1个回答
0
投票

下载MySql JDBC驱动程序,并在spark Submit命令中添加jar。

spark-submit --jars spark_code.py

© www.soinside.com 2019 - 2024. All rights reserved.