1 安装python的mysql驱动
$ conda install mysql-connector-python
2 测试mysql驱动是否安装成功
import不报错,即说明安装成功
>>> import mysql.connector
3 查询数据
# 导入MySQL驱动:
import mysql.connector
# 连接本地mysql
conn = mysql.connector.connect(user='userName', password='passWord', database='sakila')
cursor = conn.cursor()
cursor.execute('select * from actor limit 10')
values = cursor.fetchall()
values
# 关闭Cursor和Connection:
cursor.close()
conn.close()
查询被mysql数据库完成。
来源:https://www.cnblogs.com/wooluwalker/p/12244535.html