使用Python从MySQL数据库表读取SparkSQL [英] SparkSQL read from MySQL database table using Python
本文介绍了使用Python从MySQL数据库表读取SparkSQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在MySQL中有一个用户"表.我想将其读取到我的Spark SQL程序中.如何使用Python从MySQL读取表到Apache Spark的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.
推荐答案
有一个然后运行
sqlContext.read.format("jdbc").options(
url ="jdbc:mysql://localhost/mysql",
driver="com.mysql.jdbc.Driver",
dbtable="user",
user="root",
password=""
).load().take(10)
这很可能会起作用.但这取决于您的mysql设置,因此如果不尝试更改密码,用户名,db-url和其他设置.
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.
这篇关于使用Python从MySQL数据库表读取SparkSQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文