简体   繁体   中英

ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES) when connecting to MySQL through Python

I have been trying to connect to a MySQL server through Python, using:

try:
    with connect(
        host = "localhost",
        user = "root",
        password = "<password>",
    ) as connection:
        print(connection)
except Error as E:
    print(E)

It then throws the error:

1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

I've tried all the solutions I can find on similar threads but none of them seem to be working and I don't understand what I'm doing wrong. The password is correct and I can login with it to the MySQL Command Line Client.

Thanks to BerndBuffen for linking the docs which helped me figure out the issue I'm experiencing (and everyone else who tried to help).

I realised that my issue is the port default is 3306 and when configuring 3306 was in use, so I changed it to 3307. When I was trying to connect it was attempting to use the wrong port by default, adding --port 3307 solved this.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM