"""
create time:2022-11-18 14:42:40
@Author :wyk
"""
import MySQLdb
connect = MySQLdb.connect(
host='localhost',
port=3306,
user='root',
passwd='******',
db='wyk',
use_unicode=True,
charset='utf8'
)
cursor = connect.cursor()
sql = 'insert into Student (name, age) values (%s, %s);'
data = [('e','30'), ('f', '31')]
cursor.executemany(sql, data)
connect.commit()
sql2 = 'select * from Student'
cursor.execute(sql2)
print(cursor.fetchone())
print(cursor.fetchmany(2))
print(cursor.fetchall())
sql3 = "update Student set age = '12' where id = 1"
cursor.execute(sql3)
connect.commit()
sql4 = 'delete from Student where id = 1'
cursor.execute(sql4)
connect.commit()
cursor.close()
connect.close()