python import asyncio import aiomysql python async def create_pool(): pool = await aiomysql.create_pool(host='localhost', port=3306, user='root', password='your_password', db='your_database') conn = await pool.acquire() return conn, pool async def close_pool(pool): pool.close() await pool.wait_closed() python async def execute_query(conn): async with conn.cursor() as cursor: await cursor.execute("SELECT * FROM your_table") result = await cursor.fetchall() return result python async def main(): conn, pool = await create_pool() result = await execute_query(conn) print(result) await close_pool(pool) loop = asyncio.get_event_loop() loop.run_until_complete(main())


上一篇:
下一篇:
切换中文