我在用
df.write.mode("append").jdbc("jdbc:mysql://ip:port/database","table_name",properties)
插入MySQL中的表.
另外,我在我的代码中添加了Class.forName(“com.mysql.jdbc.Driver”).
当我提交我的Spark应用程序时:
spark-submit --class MY_MAIN_CLASS
--master yarn-client
--jars /path/to/mysql-connector-java-5.0.8-bin.jar
--driver-class-path /path/to/mysql-connector-java-5.0.8-bin.jar
MY_APPLICATION.jar
这种纱线客户端模式适合我.
但是当我使用纱线群集模式时:
spark-submit --class MY_MAIN_CLASS
--master yarn-cluster
--jars /path/to/mysql-connector-java-5.0.8-bin.jar
--driver-class-path /path/to/mysql-connector-java-5.0.8-bin.jar
MY_APPLICATION.jar
它不起作用.我也试过设置“–conf”:
spark-submit --class MY_MAIN_CLASS
--master yarn-cluster
--jars /path/to/mysql-connector-java-5.0.8-bin.jar
--driver-class-path /path/to/mysql-connector-java-5.0.8-bin.jar
--conf spark.executor.extraClassPath=/path/to/mysql-connector-java-5.0.8-bin.jar
MY_APPLICATION.jar
但仍然得到“找不到适合jdbc的驱动程序”错误.