pip install aiomysql python import asyncio import aiomysql python db_config = { "host": "localhost", "port": 3306, "user": "root", "password": "password", "db": "mydatabase" } python async def query_database(): pool = await aiomysql.create_pool(**db_config) async with pool.acquire() as conn: async with conn.cursor() as cursor: await cursor.execute("SELECT * FROM mytable") result = await cursor.fetchall() return result python if __name__ == "__main__": loop = asyncio.get_event_loop() result = loop.run_until_complete(query_database()) print(result)


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