标签:连接mysql nec format park mysql数据库 databases created cal 驱动
spark连接mysql数据库
cd /usr/local/hive/lib
ls mysql*
cp mysql-connector-java-5.1.40-bin.jar /usr/local/spark/jars/
cd /usr/local/spark/jars/
ls mysql*
netstat -tunpl
create table student(id bigint auto_increment,name char(20),sex char(4),age int (4),primary key(id) using btree);
insert into student(name,age,sex) values("Mosse",18,"M"),("Make",20,"M"),("Junny",18,"F"),("Zuly",21,"F");
select * from student;
jdbcDF=spark.read\
... .format("jdbc")\
... .option("url","jdbc:mysql://localhost:3306/spark?useUnicode=true&characterEncoding=utf-8")\
... .option("driver","com.mysql.jdbc.Driver")\
... .option("dbtable","student")\
... .option("user","root")\
... .option("password","123456")\
... .load()
jdbcDF.show()
attr = {"user":"root","password":"123456","driver":"com.mysql.cj.jdbc.Driver"}
truncate table student;
select * from student;
spark.createDataFrame(records).write\... .jdbc("jdbc:mysql://localhost:3306/spark?useSSL=false","student","append",attr)
select * from student;
标签:连接mysql nec format park mysql数据库 databases created cal 驱动
原文地址:https://www.cnblogs.com/vicry/p/14832873.html