I am trying to connect MySQL(8.0.25) and python(3.9.6) using mysql.connector but getting error.
Error:
mysql.connector.errors.ProgrammingError: 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
Code:
import mysql.connector as sql
s =sql.connect(host='localhost',user='root', password='<correct password>',database='<existing database>')
The password I entered is the one I use to successfully login to MySQL 8.0 Command line client.
Same code is working for pymysql.connect without any error.
I checked out the Host and User Name by logging in to MYSQL 8.0 Command Line client with my password and typing:
that’s the point where I would check with wireshark what connecting stinrg gets used by your code to connect or the MySQL service. But I guess that’s not an option for you?
Plan b would be to debug into the sql.connect function call and to find out how the connection that the mysql library creates looks like. Do you know how you can debug Python code?
If not, please tell us what IDE or code edtor you use. So maybe we can get you started into this road.
Debugging is a very important skill that you will need as a software developer. So the sooner you learn it, the better.
Sorry that there is no immediate suggestion what is wrong with your code or setup. We can only speculate because we have not enough information to really figure it out.
Perhaps a few side notes about VsCode. VsCode is a code editor that supports a plethora of Plugins. It is one of the most popular code editors and supports many programming languages. It is also completely free and supported under Windows, Linux and MacOs.
It might be a good idea to use VsCode if you want to make programming your profession at some point. I worked with different programming languages using VsCode in different companies. It hasn’t failed me yet.