tags:

views:

203

answers:

1

I accidentally removed most of the privileges from my MySQL root user, including the ability to grant privileges. Is there some way I can restore this user to its original state?

+1  A: 

You might still be able to do an UPDATE on table user in database mysql:

USE mysql;
UPDATE user SET Grant_priv='1' WHERE User='root';
FLUSH PRIVILEGES;

If step 3 doesn't work, restarting the MySQL server will have the same effect. If step 2 doesn't work, you need to restore mysql.user from backup. If you don't have a backup, make a backup, reinstall MySQL and then selectively restore your backup, leaving out tables within the mysql database.

UPDATE

You're getting Access Denied during the first step. At this point, you're down to the alternative solutions with backups. There's no way (that I know of or can easily imagine) that you're recovering those tables any other way.

UPDATE 2

The exact error message is basically saying that in addition to losing root's grant privileges, you've dropped root's access to the mysql DB. Without having access to that DB and without having grant privileges, the only way I can see back is to somehow obtain a fresh copy of the mysql DB.

Any chance you have a replication slave set up?

Jon Bright
Access denied during the first step.
LogicWolfe
In case the exact error message is in some way more useful: ERROR 1044 (42000): Access denied for user 'root'@'localhost' to database 'mysql'
LogicWolfe
Got this working by using temporarily --skip-grant-tables for mysqld. Once that was done granting privileges worked fine. http://dev.mysql.com/doc/refman/5.1/en/resetting-permissions.html has details for anyone else who might run into the same issue.
LogicWolfe