Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Overriding MySQL root in emergency

A safer way to do this would be to add the "init-file=/tmp/grant.sql" to the [mysqld] section of your my.cnf file. In /tmp/grant.sql you would have...

SET PASSWORD FOR root@localhost = PASSWORD('xxxx');

or whatever SQL that would fix the root user.

Restart MySQL and the password is reset. You can then remove /tmp/grant.sql and remove the init-file line from your configuration.

Using the skip-grant-tables exposed your entire database to anyone or any service that has access to your mysql instance. If you make sure that the grant.sql file only is readable by the mysql daemon user, you will have less exposure.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment