views:

458

answers:

6

I am trying to set the permissions for a MySQL user using the following command.

GRANT ALL ON joomla.* to user@localhost;

I have tried so many versions but they all return: ERROR 1044 (42000): Access denied for user ''@'localhost' to database 'joomla2'

Which seems to indicate that the username "user" is not getting passed? I have tried many versions of the command above, is there something else I need to be aware of.

PS: my name is not actually "user" just in case someone mentions that it is a reserved word or something similar.

+1  A: 

Try having a look in the privilege tables. For instance:

> use mysql;
> select * from db;

That might give you a hint as to what's going wrong.

You might also try connecting over tcp rather than unix socket by specifying user@'127.0.0.1' and connecting with the -H 127.0.0.1 flag (if you're using the mysql cmd line client).

Have you tried specifying a password using the 'IDENTIFIED BY "mypwd"' part of the GRANT statement?

scooterXL
+1  A: 

This has worked for me:

GRANT ALL PRIVILEGES ON joomla.* TO 'username'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;

I believe that the problem is that you are not giving a password.

Also, are you using a user that can grant privileges to other users? Do you connect as root or as a regular user?

kgiannakakis
yep still same thing - with password, i've tried every combo, tried what you gave me as well just to quadruple check
Ankur
+1  A: 

According to the MySQL Ref Manual I'd say you missed the ' in the above statement.

Did you try:

GRANT ALL ON joomla.* to 'user'@'localhost';
Peter
yes tried it many times, but thanks
Ankur
+1  A: 

Are you logged into MySQL as user@localhost when you try and run this command?

If so you won't be able to assign yourself the privileges you will need to do it while logged in as the root user, or another user who is able to assign the privileges.

BenM
my root user has no username and password. When I initially login it does not ask for any username or password so I am assuming I am the root user at this time
Ankur
it sounds like your not logging in as the root user.If you're using the command line MySQL try using the command "mysql -u root -h 127.0.0.1" to start.
BenM
A: 

Thanks everyone. It doesn't answer the question, but I am going to reinstall mysql and give it a proper root username and password this time. Last time I left these empty. The long solution but it will solve the problem.

Ankur
Hold your horses! The root user is automatically created, if you didn't specify a password then you should just be able to login but you'll have to explicitly do it as root.See the MySQL docs for information on resetting the root password, http://dev.mysql.com/doc/refman/5.1/en/resetting-permissions.html
BenM
Thanks - this looks like what I really need.
Ankur
A: 

Have you restarted the server afterwards? If not, you need to issue FLUSH PRIVILEGES

soulmerge