pyspark 1.6.2 API http://spark.apache.org/docs/1.6.2/api/python/pyspark.sql.html?highlight=jdbc#pyspark.sql.DataFrameWriter.jdbc
1. 数据库以Mysql为例
url = “jdbc:mysql://localhost:3306/test”
table = “test”
properties = {"user":"root","password":"111111"}
df = sqlContext.read.jdbc(url,table,properties) #读
df.write.jdbc(url,table,properties) #写
# 写入时候需要把RDD转为dataframe类型 可用rdd.toDF()
# 如果导入数据有中文
# mysql的表的编码格式设置成utf8 ALTER TABLE tablename CONVERT