如何将DataFrame写入MySQL表

ada*_*h16 6 scala dataframe apache-spark apache-spark-sql

很抱歉,如果它听起来模糊,但可以解释将现有的DataFrame"df"写入MySQL表格中的步骤说"product_mysql",反之亦然.

Ram*_*ram 6

请参阅此databricks文章:使用JDBC连接到SQL数据库.

import org.apache.spark.sql.SaveMode

val df = spark.table("...")
println(df.rdd.partitions.length)
// given the number of partitions above, users can reduce the partition value by calling coalesce() or increase it by calling repartition() to manage the number of connections.
df.repartition(10).write.mode(SaveMode.Append).jdbc(jdbcUrl, "product_mysql", connectionProperties)
Run Code Online (Sandbox Code Playgroud)