Resetting privileges for MySQL root account

I played around with the HeidiSQL front-end for MySQL and somehow managed to remove all privileges from the database’s root account while editing other user accounts. Needless to say, none of the other accounts had access to the administrative internals of MySQL, so that I essentially threw away the master key to my database server.

Solution

Luckily, MySQL provides the option to bypass privileges for all user accounts, as is necessary in situations like these. Here are the steps to enable this option:

  1. Browse to the MySQL installation directory
    i.e. C:/Program Files/MySQL/MySQL Server 5.1
  2. Open the file my.ini in your favorite text editor
    Note: in earlier versions of MySQL this file is called my.cnf
  3. In the [mysqld] of this file add the following line:
    skip-grant-tables
  4. Restart the MySQL server, for example in the Service Manager in Windows

You should now be able to log into the MySQL server using any of your acounts, including the root account. Use your favorite tool to fix up the privileges table for root or add other user accounts as needed.

IMPORTANT: Don’t forget to take out the added line from my.ini when you are done fixing up the database and restart the service once again. Otherwise your database will grant access to anyone attempting to login, which is obviously a major security hole.

  1. No comments yet.

  1. No trackbacks yet.