Skip to content

Instantly share code, notes, and snippets.

@johnlewisdesign
Created June 18, 2020 19:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save johnlewisdesign/23c5ea7cb1b6151cbdeadd7fbfff4594 to your computer and use it in GitHub Desktop.
Save johnlewisdesign/23c5ea7cb1b6151cbdeadd7fbfff4594 to your computer and use it in GitHub Desktop.
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