pyspark 连接mysql读取数据

@pyspark 连接mysql 读取数据

from pyspark import SparkConf
from pyspark import SparkContext

conf=SparkConf().setAppName(“miniProject”).setMaster(“local[*]”)
sc = SparkContext(appName=“mysqltest”)
sqlContext = SQLContext(sc)

sql 1

df = sqlContext.read.format(“jdbc”).options(
url=“jdbc:mysql://localhost:3306/data_collection?user=root&password=1qaz2wsx”, dbtable=“catalog”).load()
#df.show()

sql 2

df=sqlContext.read.jdbc(url=“jdbc:mysql://localhost:3306?user=root&password=1qaz2wsx”,table=“data_collection.catalog”)
#df.show()

sql 3

sql="(select catalog_id from catalog where catalog_id <‘5’) t"
df=sqlContext.read.format(“jdbc”).options(url=“jdbc:mysql://localhost:3306/data_collection”,dbtable=sql,user=“root”,password=“1qaz2wsx”).load()
#df.show()

你可能感兴趣的:(python)