spark on yarn报错找不到mysql驱动 com.mysql.cj.jdbc.Driver

spark 读取mysql数据库表,master指定使用本地模式"local[*]"没问题,但指定yarn模式报错 not found com.mysql.cj.jdbc.Driver

spark read mysql table to hive ods task Error, error info: An error occurred while calling o51.load.
	: java.lang.ClassNotFoundException: com.mysql.cj.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:46)
		at org.apache.spark.sql.execution.datasources.jdbc.JDBCOptions.$anonfun$driverClass$1(JDBCOptions.scala:101)
		at org.apache.spark.sql.execution.datasources.jdbc.JDBCOptions.$anonfun$driverClass$1$adapted(JDBCOptions.scala:101)
		at scala.Option.foreach(Option.scala:407)
		at org.apache.spark.sql.execution.datasources.jdbc.JDBCOptions.<init>(JDBCOptions.scala:101)
		at org.apache.spark.sql.execution.datasources.jdbc.JDBCOptions.<init>(JDBCOptions.scala:39)
		at org.apache.spark.sql.execution.datasources.jdbc.JdbcRelationProvider.createRelation(JdbcRelationProvider.scala:34)
		at org.apache.spark.sql.execution.datasources.DataSource.resolveRelation(DataSource.scala:350)
		at org.apache.spark.sql.DataFrameReader.loadV1Source(DataFrameReader.scala:228)
		at org.apache.spark.sql.DataFrameReader.$anonfun$load$2(DataFrameReader.scala:210)
		at scala.Option.getOrElse(Option.scala:189)
		at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:210)
		at org.apache.spark.sql.DataFrameReader.load(DataFrameReader.scala:171)
		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:282)
		at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)
		at py4j.commands.CallCommand.execute(CallCommand.java:79)
		at py4j.ClientServerConnection.waitForCommands(ClientServerConnection.java:182)
		at py4j.ClientServerConnection.run(ClientServerConnection.java:106)
		at java.lang.Thread.run(Thread.java:748)

解决方案: 把mysql驱动jar包拷贝到集群各节点jdk1.8/jre/lib/ext目录下面 [我这里以我自己的目录jdk1.8为例]

注意:
spark yarn目录也需要上传mysql驱动包 目录一般默认是hdfs目录/spark/jars/

你可能感兴趣的:(spark,mysql)