标签:database 光标移动 insert pre mysql imp ted 数据 游标
1 #!/usr/bin/env python 2 #created by Baird 3 4 import pymysql 5 6 #自动注册事件 7 conn = pymysql.connect(host = "192.168.10.128",port=3306,user="Baird",passwd="1234567",database="my_test") 8 9 cursor = conn.cursor() #创建游标 10 11 count = cursor.execute("select * from student") #返回数据数目 12 print(count) 13 14 print(cursor.fetchone()) #读一条,光标移动 15 print(cursor.fetchall()) #读所有 16 17 cursor.execute("insert into student(name,age,date) values(‘wangwu‘,24,‘2018-3-29‘)") 18 19 data = [ 20 ("name1",22,"2018-1-1"), 21 ("name2",22,"2018-1-2"), 22 ("name3",22,"2018-1-3") 23 ] 24 cursor.executemany("insert into student(name,age,date) values(%s,%s,%s)",data) 25 conn.commit() #提交事件,否则不会保存 26 27 cursor.close() 28 conn.close()
标签:database 光标移动 insert pre mysql imp ted 数据 游标
原文地址:https://www.cnblogs.com/baird/p/9542633.html