4

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?

Max Kim
  • 1,104
  • 4
  • 14
  • 27

2 Answers2

8

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:

Community
  • 1
  • 1
Rohit Jain
  • 195,192
  • 43
  • 369
  • 489
0

I suggest to everyone to always use mysql_setpermission rather than direct MySQL statements, mysql_setpermission does everything for you including FLUSHing. Any other way is prone to mistakes.

Noam Rathaus
  • 3,695
  • 1
  • 22
  • 33