gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-29 15:32:38 25 4
gpt4 key购买 nike

我正在尝试使用 PySpark,但遇到以下问题。我不太明白这个问题,但我的计算机似乎找不到“com.mysql.jdbc.Driver”驱动程序。我使用的是 Mac 操作系统,因此我在 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()

最佳答案

下载MySql JDBC驱动程序并在spark提交命令中添加--jar。

spark-submit --jars Spark_code.py

关于Python MySQL Spark(java.lang.ClassNotFoundException : com. mysql.jdbc.Driver),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58572161/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com