I am trying to setup a MySQL server and when I went to create a second user it wouldn't give it permissions for the database. I can connect fine as long as I don't specify a database.

Access denied for user 'user'@'localhost' to database 'diddata'

The connection details are:

{ 'host' : 'localhost', 'user' : 'user', 'password' : 'password' , 'database': 'diddata' };

And to create the DB and table I did:

CREATE DATABASE IF NOT exists diddata;
CREATE USER 'user'@'localhost' IDENTIFIED BY 'password';
GRANT ALL ON user.* TO 'user'@'localhost';

Note that I've changed the username and password in this question.

I've already checked the privileges in MySQL workbench and they are there.


I found my mistake.

GRANT ALL ON user.*  << this should be diddata.

I noticed it when I went to change the database name in the question.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.