If you need a super easy way to reset your MySQL or MariaDB root password because you locked yourself out, this is how it can be done.
- Login as root@yourhost
- Shutdown any remote access as your server will be without password for a few moments.
- Edit /etc/my.cnf, and under the [server] section, add
- Restart MySQL
- Login and update the password with a query like this:
# mysql MariaDB> use mysql; MariaDB> update user set Password=PASSWORD("yourpass"), authentication_string=PASSWORD("yourpass") where User='root';
- Remove the “skip-grant-tables” line from /etc/my.cnf
- Restart mysql
You are back in action! Don’t forget to re-enable remote access.