pyspark调mysqljdbc读取了参数出来,待续
from __future__ import print_function
from pyspark.sql import SparkSession
from pyspark.sql import SQLContext
import os, time,sys
def main(argv):
print(argv[1])
print(argv[2])
print(argv[3])
spark = SparkSession.builder
.appName("test")
.master("local")
.getOrCreate()
sc = spark.sparkContext
sqlContext=SQLContext(sc)
jdbcDf=sqlContext.read.format("jdbc").options(url="jdbc:mysql://ip:3306/test",
driver="com.mysql.jdbc.Driver",
dbtable="(SELECT * FROM test LIMIT 5) tmp",
user="test",password="1111123").load()
#print(jdbcDf.select("job_name").show(2))
print(jdbcDf)
print("hjzFinish")
if __name__ == "__main__":
# 设置spark_home环境变量,路径不能有中文、空格
#os.environ["SPARK_HOME"] = "E:/data_page/spark-2.0.2-bin-hadoop2.7"
# 运行在本地(local),2个线程,一行写不完换行时用“”
main(sys.argv)
以上是 pyspark调mysqljdbc读取了参数出来,待续 的全部内容, 来源链接: utcz.com/z/512902.html