@pyspark 连接mysql 读取数据
from pyspark import SparkConf
from pyspark import SparkContext
conf=SparkConf().setAppName(“miniProject”).setMaster(“local[*]”)
sc = SparkContext(appName=“mysqltest”)
sqlContext = SQLContext(sc)
df = sqlContext.read.format(“jdbc”).options(
url=“jdbc:mysql://localhost:3306/data_collection?user=root&password=1qaz2wsx”, dbtable=“catalog”).load()
#df.show()
df=sqlContext.read.jdbc(url=“jdbc:mysql://localhost:3306?user=root&password=1qaz2wsx”,table=“data_collection.catalog”)
#df.show()
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()