Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python MySQL OperationalError: 1045, "Access denied for user root@'localhost'

Tags:

python

mysql

I was trying to access the database from my python program by:

db = mysql.connect(host = 'localhost', user = 'Max', passwd = 'maxkim', db = 'TESTDB')
cursor = db.cursor()

But, I get an error message in the first line of code.

OperationalError: (1045, "Access denied for user 'Max'@'localhost' (using password: YES)")

To remedy the situation, I did the following:

$ mysql -u Max-p
Enter password: maxkim

mysql> create database TESTDB;
mysql> grant usage on *.* to Max@localhost identified by ‘maxkim’;
mysql> grant all privileges on TESTDB.* to Max@localhost ;
mysql> exit

If I have granted all access to the the database for the user "Max" (me), why can't I still connect in python?

like image 636
Max Kim Avatar asked Feb 17 '23 01:02

Max Kim


1 Answers

You can try adding GRANT OPTION at the end:

GRANT all privileges on TESTDB.* to 'Max'@'localhost' IDENTIFIED BY 'maxkim' WITH GRANT OPTION;

You can also use the below command to find the grants for a user:

SHOW GRANTS FOR 'Max'@'localhost';

Also See:

  • MySQL ERROR 1045 (28000): Access denied for user 'bill'@'localhost' (using password: YES)
like image 187
Rohit Jain Avatar answered Feb 18 '23 15:02

Rohit Jain