views:

452

answers:

5

Hi all,

I have a problem with the MySQL root user in My MySQL setup, and I just can't for the life of me work out how to fix it. It seems that I have somehow messed up the root user, and my access to databases is now very erratic.

For reference, I'm using MAMP on OS X to provide the MySQL server. I'm not sure how much that matters though - I'd guess that whatever I've done will require a command-line fix to solve it.

I can start MySQL using MAMP as usual, and access databases using the 'standard' users I have created for my PHP apps. However, the root user, which I use in my MySQL GUI client, and also in phpMyAdmin, can only access the "information_schema" database, as well as two I have created manually, and presumably (and mistakenly) left permissions wide open for. My 15 or so other databases cannot be accessed my the root user. When I load up phpMyAdmin, the home screen says: "Create new database: No Privileges".

I certainly did at some stage change my root user's password using the MAMP dialog. But I don't remember if I did anything else which might have caused this problem. I've tried changing the password again, and there seems to be no change in the issue.

I've also tried resetting root password using the command line, including starting mysql manually with --skip-grant-tables then flushing privs, but again, nothing seems to fix the issue.

I've come to the end of my ideas, and would very much appreciate some step-by-step advice and diagnosis from one of the experts here!

Many thanks for your help.

+1  A: 

Try starting the server with --skip-grant-tables and then checking the privilege tables in the mysql database:

select * from user where User='root';
select * from tables_priv where User='root';
select * from db where User='root';

You could also try:

show grants for root@localhost;
show grants for root@'%';
show grants for root@'hostname';

Once in you could do this to attempt to give root full privileges:

grant all privileges on *.* to root@localhost identified by 'password' with grant option;
Craig
Hi Craig,Thanks for your post. here are the results of your suggestions: select * from user where User='root';gives 1 row: "localhost", "root", "*503872B3FA065DCF60<snip>B67224E" then a load of 'Y's--- select * from tables_priv where User='root';and select * from db where User='root'; both give an "Empty Set"---All the "Show grants" commands give the error: "The MySQL server is running with the --skip-grant-tables option so it cannot execute this statement"---The "grant all privileges" command gives the same error
George Crawford
Wow, I thought the comments here would allow formatting, but the obviously don't! Hope you can read all that.
George Crawford
When I start the server WITHOUT --skip-grant-tables, I get the following: "show grants for root@localhost;" gives: "GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' IDENTIFIED BY PASSWORD '*503872B3FA065D<snip>B67224E' WITH GRANT OPTION" --- "show grants for root@'%';" gives: "There is no such grant defined for user 'root' on host '%'" --- Does that shed any light at all? I still have absolutely no idea what's wrong.
George Crawford
Can you access the databases via the command line command: mysql -u root -p -h localhost DBNAME
Craig
what about mysql -u root -p -h 127.0.0.1 DBNAME
Craig
MAMP uses a socket in an unusual location, so 127.0.0.1 doesn't work (Can't connect to MySQL server on '127.0.0.1'). However, I tried both "-h localhost" and the following command: "/Applications/MAMP/Library/bin/mysql -u root -p -S /Applications/MAMP/tmp/mysql/mysql.sock DBNAME" and for both I got: "Access denied for user 'root'@'localhost' to database 'DBNAME'"
George Crawford
Any more ideas? I'm still totally stuck!
George Crawford
A: 

Hi,

sorry to post an 'answer' rather than another comment, but I was wondering if anyone else might be able to help me, as I'm still totally stuck!

Thanks

George Crawford
A: 

Thats because MAMP and the command line mysql (and the mysql everything except MAMP) are different.

MAMP has its own built in mysql and you can't get to it via the command line, only the build in phpmyadmin.

this has been my experience, I have MAMP and use the other mysql for ruby on rails and other stuff.

jerome stonebridge
+1  A: 

Your comment shows your current root privileges (without --skip-grant-tables). It's fine that you do not have any entry for 'root'@'%', you do not have that by default and you can consider it a security measure.

It looks like you've messed up your 'root'@'localhost' privileges. GRANT ALL PRIVILEGES ON . is weird. Usually, you have something like GRANT ALL PRIVILEGES ON *.* or GRANT ALL PRIVILEGES ON myDatabase.myTable. Your GRANT does not specify the databases and/or tables to grant the privileges for. I have no idea how your client managed to produce it. I cannot reproduce it with the mysql commandline client (tried empty strings, whitespace, any kind of quotes...), mysql refuses the GRANT statement (which, of course, is the correct behaviour). Looks like MAMP is doing something really strange. Since I cannot reproduce a GRANT like yours, I cannot say how mysql interprets that, but I guess it has set the privileges to 'N' on the global level.

To fix it, you need a user with appropiate privileges. Usually, you have a user 'root'@'localhost' and a 'root'@'your-hostname'. If you're lucky, 'root'@'your-hostname' is still fine. Afair, mysql connections work as follows: If you connect to localhost, you connect as 'root'@'localhost' (not sure about 127.0.0.1, I guess it is also 'root'@'localhost'). If you connect to your-hostname, you connect as 'root'@'your-hostname'. If this user's privileges are still ok, you can update the privileges for 'root'@'localhost' and you are done.

In your comment, you say you cannot connect via 127.0.0.1 since the socket is in an unusual place. I guess you misinterpret the error. IIRC you connect via socket if you connect to 'localhost', but via TCP/IP if you connect to 127.0.0.1 or your-hostname. If mysql tries to connect via socket and cannot find the socket (because you did not specify the correct location), the error message mentions where mysql tried to find the socket. Your error message does not. I guess your error is a networking error. Maybe you've started the mysql-server with the --skip-networking option, or your configuration specifies an incorrect bind-address. You need to fix that first, otherwise you can't connect as 'root'@'your-hostname'.

titanoboa
A: 

I am getting this same issue. Only 1 user account works to access the mysql databases via the administration console or the query browser. If I use the skip-grant-tables suddenly all accounts can log in, including root.

Anyone else having this issue? I saw it as a bug as far back as 2006:

http://bugs.mysql.com/bug.php?id=22118

But the final entry there isn't a command that can be executed when in skip-grant-tables mode, so I still haven't solved the issue.

Edit: Found solution. The problem comes when your my.ini has the name resolution flag disabled (skip-name-resolve). This kills mysql's ability to resolve 'localhost' and the mysql.user table only has an entry for localhost / root.

Update your mysql.user table's localhost entry to be 127.0.0.1 instead, and you can log in to the local consoles even with the skip-name-resolve feature enabled.

This answer is similar to one found the above link, from a Ben Bakelaar.

Mysql User