pymysql的使用

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()

 

posted @ 2022-11-27 19:09  shclbear  阅读(21)  评论(0)    收藏  举报