SparkSQL 使用 Python 从 MySQL 数据库表中读取数据 [英] SparkSQL read from MySQL database table using Python

查看:30
本文介绍了SparkSQL 使用 Python 从 MySQL 数据库表中读取数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 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.

推荐答案

有一个回答类似问题.像这样启动 pyspark

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

然后运行

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.

这篇关于SparkSQL 使用 Python 从 MySQL 数据库表中读取数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆