Re-Creating Damaged Grant Tables

If you cannot restore your mysql grants database from backup, you will need to create a fresh one. With Windows, you can extract the mysql directory from the installation package and place it under the MySQL data directory.

Under Linux or Mac OS X, you can use the mysql_install_db script to regenerate the mysql database and the privilege tables in it. This is particularly handy if your mysql database has somehow become corrupted. Note that if the user table has to be created, the root password for the server will be reset to the default value (blank).

If mysql_install_db isn’t already in your system path, you can generally find it in the scripts directory under your MySQL installation directory. Run mysql_install_db the same way you ran it in Chapter 2. If you’re not sure how to run the script, try logging in as the system superuser and running it with no parameters:

# mysql_install_db

or optionally with the user=mysql parameter so that MySQL is configured to run under the mysql system user account:

# mysql_install_db --user=mysql

Get Learning MySQL now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.