Skip to content

Instantly share code, notes, and snippets.

@shredder47
Created November 21, 2020 10:33
Show Gist options
  • Save shredder47/78119363c3d91df62d64eef1a3defa39 to your computer and use it in GitHub Desktop.
Save shredder47/78119363c3d91df62d64eef1a3defa39 to your computer and use it in GitHub Desktop.
Connect MySQL from Spark 2.x
val spark = SparkSession
.builder()
.appName("Spark")
.master("local[*]")
.enableHiveSupport()
.getOrCreate()
spark.sparkContext.setLogLevel("ERROR")
val properties = new Properties()
properties.put("user", "root")
properties.put("password", "123456")
val url = "jdbc:mysql://localhost:3306/sakila"
val df = spark.read.jdbc(url,"actor",properties = properties)
spark.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment