How to get all privileges back to the root user in MySQL?

Steven picture Steven · Nov 10, 2009 · Viewed 125.4k times · Source

I am using MySQL. My root user doesn't have all privileges. How can I get all privileges back to the root user? How to do it step by step?

Answer

Joe picture Joe · Feb 9, 2013

This worked for me on Ubuntu:

Stop MySQL server:

/etc/init.d/mysql stop

Start MySQL from the commandline:

/usr/sbin/mysqld

In another terminal enter mysql and issue:

grant all privileges on *.* to 'root'@'%' with grant option;

You may also want to add

grant all privileges on *.* to 'root'@'localhost' with grant option;

and optionally use a password as well.

flush privileges;

and then exit your MySQL prompt and then kill the mysqld server running in the foreground. Restart with

/etc/init.d/mysql start