Python学习记录-连接mysql
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数据库完成。
相关推荐
emmm00 2020-11-17
王艺强 2020-11-17
aydh 2020-11-12
世樹 2020-11-11
zry 2020-11-11
URML 2020-11-11
spurity 2020-11-10
yifangs 2020-10-13
Andrea0 2020-09-18
Ida 2020-09-16
ltd00 2020-09-12
tufeiax 2020-09-03
xjd0 2020-09-10
greatboylc 2020-09-10
adsadadaddadasda 2020-09-08
疯狂老司机 2020-09-08
CoderToy 2020-11-16
ribavnu 2020-11-16
bianruifeng 2020-11-16