标签:ESS ext water imp delete commit 查询 fetch 打印
表结构:#Author Kang
import pymysql
#连接方法
conn = pymysql.connect(host=‘10.3.152.35‘,port=3306,user=‘kang‘,passwd=‘123456‘,db=‘test‘)
#创建当前游标
cursor = conn.cursor()
#effect_row 为结果行数
effect_row = cursor.execute("select * from student")
#打印当前游标语句查询的结果
print(cursor.fetchall())
#建立需要插入的数据
data = [
(‘MM‘,33),
(‘BearBear‘,4),
(‘KK‘,10)
]
#执行插入语句
cursor.executemany(‘insert into student(name,age) values(%s,%s)‘,data)
#提交语句
conn.commit()
#执行更新语句
cursor.execute(‘update student set name="MK" where id = 1‘)
conn.commit()
#执行删除语句
cursor.execute(‘delete from student where name = "KK"‘)
conn.commit()
cursor.close()
conn.close()
标签:ESS ext water imp delete commit 查询 fetch 打印
原文地址:https://blog.51cto.com/12965094/2361750