python链接mysql查询数据实例
使用 MySQLdb 模块连接 MySQL
# coding=utf-8
#引入mysql python客户端模块
import MySQLdb
import sys
#进行数据库连接
conn = MySQLdb.connect(host="localhost", user="root", passwd="123456", db="pythontab", charset="utf8")
cursor = conn.cursor()
#执行sql
cursor.execute("select * from test")
#列出数据
records = cursor.fetchall()
for row in records:
for r in row:
print r
来源:PY学习网:原文地址:https://www.py.cn/article.html

![python链接mysql查询数据实例[python基础教程]](https://www.zixueka.com/wp-content/uploads/2023/10/1697036355-fbc3ad352a1fcaa.jpg)
