一、spark连接mysql数据库

1.安装启动检查Mysql服务。
 netstat -tunlp (3306)

2.spark 连接mysql驱动程序。
 –cp /usr/local/hive/lib/mysql-connector-java-5.1.40-bin.jar /usr/local/spark/jars

3.启动 Mysql shell,新建数据库spark,表student。
 select * from student;

4.spark读取MySQL数据库中的数据

 spark.read.format("jdbc").option("url", "jdbc:mysql://localhost:3306/spark?useSSL=false") ...  .load()

5.spark向MySQL数据库写入数据
 studentDF.write.format(‘jdbc’).option(…).mode(‘append’).save() 

posted on 2021-05-30 01:26  多吃外卖  阅读(67)  评论(0编辑  收藏  举报