Spark读取mysql
import org.apache.log4j.{Level, Logger}
import org.apache.spark.sql.SparkSession
object SparkSql {
def main(args: Array[String]): Unit ={
Logger.getLogger("org").setLevel(Level.ERROR)
val spark = SparkSession.builder().appName("test").master("local[2]").getOrCreate()
val df = spark.read
.format("jdbc")
.option("url", "jdbc:mysql://localhost:3306/要访问的数据库名")
.option("driver", "com.mysql.jdbc.Driver")
.option("dbtable", "表名")
.option("user", "用户名")
.option("password", "密码")
.load()
df.show()
}
}