[Answered ]-Django tutorial 5 , 1044 Access denied for user @'localhost' database error

1👍

The name for the test database is formed by adding ‘test_’ to the name of the database specified in NAME.

If you are using Django < 1.7 then:

'TEST_NAME': 'test_myproject',

If you are using Django >= 1.7: then you should use TEST as a dictionary in settings:

'TEST' : {    
    'NAME': 'test_myproject', 
}

Currently you have:

'TEST_NAME': 'test_database_myprojecttest',

However you should specify the test database name in settings only if it differs from default one with “test_yourDbName”.

If this won’t help then you can switch to Sqlite ENGINE. With Sqlite the test database should be created in memory without accessing to a real db.

1👍

While setting a database you have run:

CREATE USER 'myprojectuser'@'localhost' IDENTIFIED BY 'password';
GRANT ALL PRIVILEGES ON myproject TO 'myprojectuser'@'localhost'; 

Which means your user don’t have access to other databases.
Yet the test is trying to create it’s own database ‘test_myproject’ (as per your error text). So you have to grant privileges on that database as well AFTER you created user myprojectuser. Just run these commands in your database console:

GRANT ALL PRIVILEGES ON test_myproject TO 'myprojectuser'@'localhost';
FLUSH PRIVILEGES;

0👍

Try adding a .* to your SQL query to include tables:

GRANT ALL PRIVILEGES ON test_myproject.* TO 'myprojectuser'@'localhost' IDENTIFIED BY 'password';

Leave a comment