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?