mysqldatabase-connectionpython-asynciopython-3.9aio-mysql

Aiomysql pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on '127.0.0.1'")


I'm new here and I'm having a problem. When running my code, an error occurs pymysql.err.OperationalError: (2003, "Can't connect to MySQL server on 'localhost'"), tell me what it might be

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))


Solution

  • Solved the issue, the problem was that there was a problem with the port in the connection, it is written through the int