Python异步操作MySQL(aiomysql)
参考文档:aiomysql官方文档
安装模块
pip3 install aiomysql
代码案例
import asyncio import aiomysql async def execute(): # 连接mysql conn = await aiomysql.connect(host='10.144.75.7', port=3306, user='customer_test', password='ec45c', db='customer_test') # 创建游标 cur = await conn.cursor() # 执行sql await cur.execute('select * from meter_table') # 获取结果 result = await cur.fetchall() print(result) # 关闭连接 await cur.close() conn.close() asyncio.run(execute())