数据库的基本操作:
import mysql.connector
# 数据哭访问
# mysql 使用 %s占位符
# 执行INSERT等操作后要调用commit()提交事务;
con = mysql.connector.connect(user='root', password='admin', database='test')
cur=con.cursor()
#添加
#cur.execute("insert into contacts(name,email,phone) values('tianlei','email','phone')")
#删除
cur.execute('delete from contacts where id=%s',[6])
#更新
cur.execute("update contacts set name ='update' where id= 34")
#查询
cur.execute("select * from contacts")
row = cur.fetchall()
for r in row:
print (r)
con.commit()
cur.close()
con.close()