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 @   shclbear  阅读(18)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 全程不用写代码,我用AI程序员写了一个飞机大战
· DeepSeek 开源周回顾「GitHub 热点速览」
· 记一次.NET内存居高不下排查解决与启示
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
点击右上角即可分享
微信分享提示