views:

634

answers:

2

I accidentally removed some of the privileges from my MySQL root user, including the ability to alter tables. Is there some way I can restore this user to its original state(with all privileges)?

UPDATE mysql.user SET Grant_priv = 'Y', Super_priv = 'Y' WHERE User = 'root';# MySQL returned an empty result set (i.e. zero rows). FLUSH PRIVILEGES ;# MySQL returned an empty result set (i.e. zero rows).

1045 - Access denied for user 'root'@'localhost' (using password: YES)

GRANT ALL ON . TO 'root'@'localhost'

+1  A: 
GRANT ALL ON *.* TO 'root'@'localhost';
Trevor
#1045 - Access denied for user 'root'@'localhost' (using password: YES)
Steven
+5  A: 

If the GRANT ALL doesn't work, try:

  1. Stop mysqld and restart it with the --skip-grant-tables option.
  2. Connect to the mysqld server with just: mysql (i.e. no -p option, and username may not be required).
  3. Issue the following commands in the mysql client:

    UPDATE mysql.user SET Grant_priv='Y', Super_priv='Y' WHERE User='root';

    FLUSH PRIVILEGES;

After that, you should be able to run GRANT ALL ON *.* TO 'root'@'localhost'; and have it work.

Dave
1.How to connect to the mysqld server with just:mysql2.When I issued UPDATE mysql.user SET Grant_priv='1' WHERE User='root'; FLUSH PRIVILEGES;I got Query ok, 0 rows affected(0.00 sec)rows matched:2 changed:0 warnings:0Query ok, 0 rows affected(0.00 sec).When I logged in to phpMyAdmin as root user, I still see "No privileges".
Steven
Sorry, after the steps above you should be able to run the GRANT ALL command. To connect to mysqld, I meant you won't need a password -- I can't remember whether any username will work, or whether it will need to be "root".
Dave
Also note that I've updated the solution to grant the SUPER privilege too, and to provide an alternative syntax. Don't forget to remove the "skip-grant-tables" option before testing!
Dave
+1 this solution was a lifesaver.
scotts