0

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.

OMG Ponies
  • 325,700
  • 82
  • 523
  • 502
Ankur
  • 50,282
  • 110
  • 242
  • 312
  • Looks like your granting privileges on one database (joomla) but try to connect to another database (joomla2). Typo? – Björn Apr 28 '09 at 07:36
  • yeah typo on my part in the question, wanted to get rid of the 2 so it was cleaner, but forgot it would popup in the error msg ... thanks – Ankur Apr 28 '09 at 07:52

6 Answers6

3

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?

scottynomad
  • 1,351
  • 11
  • 9
1

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
  • 103,016
  • 27
  • 158
  • 194
  • yep still same thing - with password, i've tried every combo, tried what you gave me as well just to quadruple check – Ankur Apr 28 '09 at 07:47
1

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';
Xn0vv3r
  • 17,766
  • 13
  • 58
  • 65
1

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
  • 4,056
  • 3
  • 24
  • 26
  • 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 Apr 28 '09 at 07:50
  • 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 Apr 28 '09 at 08:14
0

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
  • 50,282
  • 110
  • 242
  • 312
  • 1
    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 Apr 28 '09 at 08:12
  • Thanks - this looks like what I really need. – Ankur Apr 28 '09 at 08:25
0

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

soulmerge
  • 73,842
  • 19
  • 118
  • 155