首页 > 数据库技术 > 详细

在 Python代码中操作mysql数据

时间:2018-01-13 20:09:18      阅读:193      评论:0      收藏:0      [点我收藏+]
# 创建Connection连接
conn = connect(host=‘localhost‘, port=3306, user=‘root‘, password=‘mysql‘, database=‘python1‘, charset=‘utf8‘)
# 得Cursor对象
cs = conn.cursor()
# 更新
# sql = ‘update students set name="name" where id=1‘
# 删除
# sql = ‘delete from students where id=1‘
# 执行select语句,并返回受影响的行数:查询一条学生数据
sql = ‘select id,name from students where id = 7‘
# sql = ‘SELECT id,name FROM students WHERE id = 7‘
count=cs.execute(sql)
# 打印受影响的行数
print(count)

在 Python代码中操作mysql数据

原文:https://www.cnblogs.com/leedw/p/8280034.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!