当前位置: 首页 > news >正文

异步读写mysql依赖pymysql (asyncio/ aiomysql)

代码

`import asyncio
import aiomysql

settings = {
"host": "127.0.0.1",
"port": 3306,
"user": "root",
"password": "123456",
"db": "test",
}

async def main():
pool = await aiomysql.create_pool(
host=settings["host"],
port=settings["port"],
user=settings["user"],
password=settings["password"],
db=settings["db"],
)
async with pool.acquire() as conn:
async with conn.cursor() as cur:
await cur.execute("SELECT id,user_name FROM user")
# print(cur.description)
data = await cur.fetchone()
print(data)
pool.close()
await pool.wait_closed()

if name == 'main':
loop = asyncio.get_event_loop()
loop.run_until_complete(main())`

http://www.hskmm.com/?act=detail&tid=25297

相关文章:

  • Linux发行版切换技术全解析
  • 手把手教你用 Docker 部署 Redis
  • 悟空博弈单元(WBUC)与广域统一计算(WAUC)研究:价值共生的技术基石——声明Ai研究
  • 掌握形式验证工具,提升芯片验证效率
  • 长租公寓的生存越来越难了 - 智慧园区
  • Spring Boot中保存前端上传的图片 - 教程
  • P2724 [IOI 1998 / USACO3.1] 联系 Contact 做题笔记
  • 深入解析:Linux运维笔记:服务器感染 netools 病毒案例
  • 设计模式——命令设计模式(行为型) - 详解
  • 港专专利申请量被反超,背后是谁在“偷家”?
  • 版权诉讼下的MiniMax:AI独角兽的上市迷途
  • HTB Eureka靶机渗透实战 - Spring Boot堆转储与Bash算术注入漏洞利用
  • 手机照片太多了存哪里? - 实践
  • 时隔十六年的南京之旅
  • 高贵的北上广深,没有父母托举,90后很难成家
  • 使用AI图像服务规模化视觉内容生产
  • 实用指南:基于贝叶斯优化神经网络的光伏功率预测综述
  • 详细介绍:ROS2与Unitree机器人集成指南
  • 布尔类型
  • 安装iTrustSSL证书 去除此网站不支持安全连接提示
  • 2025钻机厂家最新推荐榜:岩芯钻机,勘探钻机,地质钻机,取样钻机,空气反循环钻机公司推荐
  • 在AI技术快速实现创意的时代,挖掘游戏开发框架新需求成为关键
  • iNaturalist开放自然数据与计算机视觉挑战
  • macOS 编辑字幕
  • reLeetCode 热题 100- 438. 找到字符串中所有字母异位词 - MKT
  • Flutter 251006
  • [MCP] Register Prompt
  • [Node.js] Server-Sent Events
  • day1 Gitlab Runner 学习
  • Software Foundations Vol.I : 使用结构化的数据(Lists)