10.异步mysql

2022-12-12,

python中操作mysql连接、操作、断开都是网络IO

#安装支持异步aiomysql的模块
pip3 install aiomysql
async def execute():
# 网络IO操作,连接数据库,遇到IO切换任务
conn = await aiomysql.connect('host', 3306, 'root', 'password', 'db')
# 网络IO操作,遇到IO自动切换任务
cur = await conn.cursor()
# 网络IO操作,遇到IO自动切换任务
await cur.execute('select f from table')
res = await cur.fetchall()
print(res)
# 网络IO操作,遇到IO自动切换任务
await cur.close()
conn.close()

10.异步mysql的相关教程结束。

《10.异步mysql.doc》

下载本文的Word格式文档,以方便收藏与打印。