时间:2021-07-01 10:21:17 帮助过:4人阅读
2.增
import pymysql user=‘egon‘ pwd=123 conn = pymysql.connect(host=‘localhost‘,user=‘root‘,password=‘‘,database=‘db666‘) cursor = conn.cursor() sql = ‘insert into user_info(username,password) values (%s,%s)‘ cursor.execute(sql,(user,pwd)) cursor.executemany(sql,[(user,pwd),(user+‘1‘,pwd+1)]) conn.commit() cursor.close() conn.close()
3.查
import pymysql conn=pymysql.connect(host=‘localhost‘,user=‘root‘,password=‘‘,database=‘db666‘) cursor = conn.cursor(cursor=pymysql.cursors.DictCursor) sql = ‘select * from user_info‘ cursor.execute(sql) result = cursor.fetchall() print(result) cursor.close() conn.close()
4.新插入的自增ID
import pymysql conn = pymysql.connect(host=‘localhost‘,user=‘root‘,password=‘‘,database=‘db666‘) cursor = conn.cursor(cursor=pymysql.cursors.DictCursor) sql=‘insert into user_info(username,password) values ("sss",123)‘ r = cursor.execute(sql) conn.commit() print(cursor.lastrowid,r) cursor.close() conn.close()
MySQL——4
标签:and root def 数字类型 mysql 其他 时间 last mys