import pymysql
conn = pymysql.connect(
host='127.0.0.1',
port=3306,
user='root',
passwd='123',
db='xiao',
charset='utf8'
)
cur = conn.cursor()
create1 = """create table xiao(
xiao_id INT ,xiao_name CHAR (20),
PRIMARY KEY (xiao_id)
)"""
conn.commit(create1)
insert1 = 'insert into xiao values(%s,%s)'
a = (1,'a1')
b = (2,'b1')
c = (3,'c1')
cur.executemany(insert1,[a,b,c])
select1 = 'select * from xiao order by xiao_id'
cur.execute(select1)
r1 = cur.fetchone()
r2 = cur.fetchmany(2)
r3 = cur.fetchall()
update1 = 'update xiao set xiao_name=%s where xiao_name=%s'
cur.execute(update1,('xiaodada','xiao'))
delete1 = 'delete from xiao where xiao_id=%s'
cur.execute(delete1,(2,))
conn.commit()
cur.close()
conn.close()