从sparkyr和/或pyspark连接到mysql

vx6bjr1n  于 2021-06-21  发布在  Mysql
关注(0)|答案(1)|浏览(450)

这个问题在这里已经有答案了

如何使用jdbc源代码在(py)spark中写入和读取数据(3个答案)
两年前关门了。
我正在尝试连接到本地托管的mysql数据库。我尝试了两个系统-r和python。
这是我的个人资料的截图

还有。bashèu简介

以下是我所做的:
尝试将pyspark连接到本地mysql,我得到的错误如下(pyspark的跟踪错误)
py4jjavaerror traceback(最近一次调用last)in()5 sparkclasspath=os.getenv('spark\u classpath','/users/me/mysql-connector-java-8.0.11/mysql-connector-java-8.0.11.jar')6 sqlcontext=sqlcontext(sparkcontext.getorcreate())--->7 sqlcontext.read.format(“jdbc”).options(url=”jdbc:mysql://127.0.0.1:4040”,driver=“com.mysql.jdbc.driver”,dbtable=“product”,user=“root”,password='').load()

~/Documents/spark/spark-2.2.1-bin-hadoop2.7/python/pyspark/sql/readwriter.py in load(self, path, format, schema,**options)
        163             return self._df(self._jreader.load(self._spark._sc._jvm.PythonUtils.toSeq(path)))
        164         else:
    --> 165             return self._df(self._jreader.load())
        166 
        167     @since(1.4)

~/Documents/spark/spark-2.2.1-bin-hadoop2.7/python/lib/py4j-0.10.4-src.zip/py4j/java_gateway.py in __call__(self, *args)
   1131         answer = self.gateway_client.send_command(command)
   1132         return_value = get_return_value(
-> 1133             answer, self.gateway_client, self.target_id, self.name)
   1134 
   1135         for temp_arg in temp_args:

~/Documents/spark/spark-2.2.1-bin-hadoop2.7/python/pyspark/sql/utils.py in deco(*a,**kw)
     61     def deco(*a,**kw):
     62         try:
---> 63             return f(*a,**kw)
     64         except py4j.protocol.Py4JJavaError as e:
     65             s = e.java_exception.toString()

~/Documents/spark/spark-2.2.1-bin-hadoop2.7/python/lib/py4j-0.10.4-src.zip/py4j/protocol.py in get_return_value(answer, gateway_client, target_id, name)
    317                 raise Py4JJavaError(
    318                     "An error occurred while calling {0}{1}{2}.\n".
--> 319                     format(target_id, ".", name), value)
    320             else:
    321                 raise Py4JError(

Py4JJavaError: An error occurred while calling o93.load.
: java.lang.ClassNotFoundException: com.mysql.jdbc.Driver
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at org.apache.spark.sql.execution.datasources.jdbc.DriverRegistry$.register(DriverRegistry.scala:38)
    at org.apache.spark.sql.execution.datasources.jdbc.JDBCOptions$$anonfun$6.apply(JDBCOptions.scala:78)
    at org.apache.spark.sql.execution.datasources.jdbc.JDBCOptions$$anonfun$6.apply(JDBCOptions.scala:78)
    at scala.Option.foreach(Option.scala:257)
    at org.apache.spark.sql.execution.datasources.jdbc.JDBCOptions.<init>(JDBCOptions.scala:78)
    at org.apache.spark.sql.execution.datasources.jdbc.JDBCOptions.<init>(JDBCOptions.scala:34)
    at org.apache.spark.sql.execution.datasources.jdbc.JdbcRelationProvider.createRelation(JdbcRelationProvider.scala:34)
    at org.apache.spark.sql.execution.datasources.DataSource.resolveRelation(DataSource.scala:307)
    at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:178)
    at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:146)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at py4j.reflection.MethodInvoker.invoke(MethodInvoker.java:244)
    at py4j.reflection.ReflectionEngine.invoke(ReflectionEngine.java:357)
    at py4j.Gateway.invoke(Gateway.java:280)
    at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)
    at py4j.commands.CallCommand.execute(CallCommand.java:79)
    at py4j.GatewayConnection.run(GatewayConnection.java:214)
    at java.lang.Thread.run(Thread.java:748)

试图连接到sparlyr到本地mysql,我得到错误,见下文(sparlyr的跟踪错误)
跟踪误差

问:如何从pyspark或sparkyr连接到mysql?

igetnqfo

igetnqfo1#

SPARK_CLASSPATH 已在几年前被弃用,不再受支持。假设jar包含有效的驱动程序版本,请使用: spark.jars 配置选项。
或组合:
spark.driver.extraClassPath spark.executor.extraClassPath 选项。

相关问题