0

I configured MySQL as follows:

CREATE DATABASE IF NOT EXISTS foodb;

CREATE USER IF NOT EXISTS 'foo'@'localhost';
ALTER USER 'foo'@'localhost' IDENTIFIED BY 'qux';
GRANT ALL ON foodb.* to 'foo'@'localhost';
SHOW GRANTS FOR 'foo'@'localhost';

FLUSH PRIVILEGES;

SELECT user, host, authentication_string FROM mysql.user ORDER BY user, host;

When I run

python manage.py dbshell

I get the following error:

ERROR 1045 (28000): Access denied for user 'foo'@'localhost' (using password: YES)
CommandError: "mysql --user=foo --host=localhost foodb" returned non-zero exit status 1.

Also, this query

SHOW GRANTS for 'foo'@'localhost';

returns

+--------------------------------------------------------------+
| Grants for foo@localhost                                     |
+--------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'foo'@'localhost'                      |
| GRANT ALL PRIVILEGES ON `foodb`.* TO 'foo'@'localhost'       |
+--------------------------------------------------------------+
2 rows in set (0.00 sec)

Finally, switching user to root and the root account password works just fine. So I think the issue must be with the user permissions on MySQL itself.

What additional permissions does 'foo'@'localhost' need for this to work?

Vishal
  • 2,097
  • 6
  • 27
  • 45
  • check from your settings if you connecting to the correct database, maybe it point to another one like example postgresql ? or different mysql version? – Linh Nguyen May 17 '21 at 08:25
  • also check if you encountered the following case https://stackoverflow.com/a/52121387/11225821 . Of course root user will always have default access to a database – Linh Nguyen May 17 '21 at 08:26
  • ALTER USER 'user_name'@'localhost' IDENTIFIED WITH mysql_native_password BY 'password123' seems to have resolved the problem. Is it a MySQL version issue? – Vishal May 17 '21 at 08:29
  • maybe, i think you have to check if your django application connect to the right mysql database first – Linh Nguyen May 17 '21 at 08:58

0 Answers0