Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

I had the same issue: only one user account worked to access the mysql databases via the administration console or the query browser. When I used the skip-grant-tables suddenly all accounts could log in, including root.

I saw it as a bug as far back as 2006, but the final entry there isn't a command that can be executed when in skip-grant-tables mode, so I still hadn't solved the issue.

What helped me
This answer is similar to one described by Ben Bakelaar in the above link. 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.

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;

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'.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top