scala – 如何将DataFrame写入MySQL表

前端之家收集整理的这篇文章主要介绍了scala – 如何将DataFrame写入MySQL表前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
很抱歉,如果它听起来模糊,但可以解释将现有的DataFrame“df”写入 MySQL表中的步骤,说“product_MysqL”,反之亦然.

解决方法

请看 this databricks article : Connecting to SQL Databases using JDBC.

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)

猜你在找的Scala相关文章