import pymysql #连接数据库 conn=pymysql.connect(host='101.133.225.166', user='root', password="123456",database='test', port=3306) # # 获取游标 cursor=conn.cursor(cursor=pymysql.cursors.DictCursor) # 查出来数据是字典格式 # 操作 定义一个sql # sql='select id,name from book' # cursor.execute(sql) # ret=cursor.fetchall() # print(ret) # 插入 # sql='insert into book(id,name) values (%s,%s)' # cursor.execute(sql,[3,'lqz']) # conn.commit() # 删除 # sql='delete from book where name=%s' # cursor.execute(sql,['lqz']) # conn.commit() # 更新 # sql='update book set name=%s where id=%s' # cursor.execute(sql,['xxx',1]) # conn.commit()
标签:execute,使用,pymysql,cursor,book,sql,conn From: https://www.cnblogs.com/shclbear/p/16930367.html