-
python使用pymysql在mysql的student表查询数据
- 网站名称:python使用pymysql在mysql的student表查询数据
- 网站分类:技术文章
- 收录时间:2025-07-08 14:43
- 网站地址:
“python使用pymysql在mysql的student表查询数据” 网站介绍
import pymysql
# 链接数据库
db = pymysql.connect(host='localhost', port=3306, user='root', password='root', \
db='student_info', charset='utf8')
# 获取游标
cursor = db.cursor()
# sql语句
sql_cmd = "SELECT sno,sname, ssex, sage FROM student WHERE sno = '%s';"
# 数据
data = ('95002',)
# 执行语句
cursor.execute(sql_cmd % data)
# 获取数据
data = cursor.fetchall()
# 打印数据
for item in data:
print("学号:%s;\t姓名:%s;\t性别:%s;\t年龄:%d" % item)
print("共查找出", cursor.rowcount, "条数据")
# 关闭数据库链接
cursor.close()
db.close()
- 最近发表
- 标签列表
-
- mydisktest_v298 (35)
- sql 日期比较 (33)
- document.appendchild (35)
- 头像打包下载 (35)
- 梦幻诛仙表情包 (36)
- java面试宝典2019pdf (26)
- disk++ (30)
- 加密与解密第四版pdf (29)
- iteye (26)
- centos7.4下载 (32)
- intouch2014r2sp1永久授权 (33)
- jdk1.8.0_191下载 (27)
- axure9注册码 (30)
- 兔兔工程量计算软件下载 (27)
- ccproxy破解版 (31)
- aida64模板 (28)
- engine=innodb (33)
- shiro jwt (28)
- segoe ui是什么字体 (27)
- head first java电子版 (32)
- clickhouse中文文档 (28)
- jdk-8u181-linux-x64.tar.gz (32)
- 计算机网络自顶向下pdf (34)
- -dfile.encoding=utf-8 (33)
- jdk1.9下载 (32)