300字范文,内容丰富有趣,生活中的好帮手!
300字范文 > python调用sparksql 使用Python从MySQL数据库表读取SparkSQL

python调用sparksql 使用Python从MySQL数据库表读取SparkSQL

时间:2019-11-08 15:24:13

相关推荐

python调用sparksql 使用Python从MySQL数据库表读取SparkSQL

I have a 'user' table in MySQL. I want to read it to my Spark SQL program. How can I read the table from MySQL to the Apache Spark's SparkSQL module using Python? Is there a connector I can use for this task?

Thanks.

解决方案

There is a similar question answered. Start pyspark like this

./bin/pyspark --packages mysql:mysql-connector-java:5.1.38

Then just run

sqlContext.read.format("jdbc").options(

url ="jdbc:mysql://localhost/mysql",

driver="com.mysql.jdbc.Driver",

dbtable="user",

user="root",

password=""

).load().take(10)

This would most likely just work. But this depends on your mysql set-up, so if it doesn't try changing password, username, db-url and other settings.

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。