Aiomysql pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on '127.0.0.1'")
Aiomysql pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on '127.0.0.1'")
我是新来的,遇到了问题。当 运行 我的代码出现错误 pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on 'localhost'"), 告诉我它可能是什么
import aiomysql
import asyncio
loop = asyncio.get_event_loop()
async def search_tel(telephone):
conn = await aiomysql.connect(host="localhost", port="3306",
user="root", password="password",
db="bill", loop=loop)
cursor = await conn.cursor()
await cursor.execute(f"SELECT TRUE FROM users WHERE telefon={telephone}")
print(cursor.description)
result = await cursor.fetchall()
print(result)
if result == 1:
conn.close()
return True
else:
conn.close()
return False
tel = "000000000"
loop.run_until_complete(search_tel(telephone=tel))
问题解决了,问题是连接的端口有问题,是通过int
写的
我是新来的,遇到了问题。当 运行 我的代码出现错误 pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on 'localhost'"), 告诉我它可能是什么
import aiomysql
import asyncio
loop = asyncio.get_event_loop()
async def search_tel(telephone):
conn = await aiomysql.connect(host="localhost", port="3306",
user="root", password="password",
db="bill", loop=loop)
cursor = await conn.cursor()
await cursor.execute(f"SELECT TRUE FROM users WHERE telefon={telephone}")
print(cursor.description)
result = await cursor.fetchall()
print(result)
if result == 1:
conn.close()
return True
else:
conn.close()
return False
tel = "000000000"
loop.run_until_complete(search_tel(telephone=tel))
问题解决了,问题是连接的端口有问题,是通过int
写的