1

I am trying to establish a connection with a MySQL database in a python program

import mysql.connector
cnx = mysql.connector.connect(
    host='localhost',
    user='admin',
    password='admin1234',
    database='meu_banco'
)
cnx.close()

print(cnx)

but keep getting the following error:

mysql.connector.errors.ProgrammingError: 1045 (28000): Access denied for user 'admin'@'localhost' (using password: YES)

Im am pretty sure that the username is admin and that I've setted 'admin1234' as the password. Anyone knows what might be happening?

Notes:

-I've also tried to use 'passwd' and 'db' instead of 'password' and 'database' keyword arguments.

-I'm using MySQL that comes with XAMPP version 8.0.2 / PHP 8.0.2 for Linux.

2
  • What do you mean by "I am pretty sure the username is admin". Did you set the username as admin or you are guessing it is admin? PS: As the error says, it looks like an error resulting from invalid credentials... Commented Feb 19, 2021 at 9:22
  • Oh I'm sorry for the inaccurate explanation. I meant that wrong credentials are not the cause of the problem. I am 100% sure that e set the username and password as above. Commented Feb 19, 2021 at 10:52

1 Answer 1

1

You are connecting to the database and afterwards you are closing the connection.

Only use cnx.close() when you want to close the database connection, it may cause an error.

If that's not the problem, you may have the user wrong, try to use the default username that MySQL Workbench has, it is root.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.