So i accidentally changed my password for my root account like a year ago and forgot what it was when I needed to add a new database. Very bad for a sysadmin I know but it will probably happen to you at some point in your career if it has not already!

Here’s how to reset it: 1) Stop mysqld and restart it with the –skip-grant-tables option.

mysqld –skip-grant-tables

2) Connect to the mysqld server with this command:

mysql

3) Issue the following statements in the mysql client. Replace the password (MyNewPass) with the password that you want to use.

mysql> UPDATE mysql.user SET Password=PASSWORD(‘MyNewPass’) WHERE User=‘root’; mysql> FLUSH PRIVILEGES;

The FLUSH statement tells the server to reload the grant tables into memory so that it notices the password change.

4) Kill mysqld and restart it the normal way (/etc/init.d/mysql start). Your root password will be the new one you have selected.

Mario Loria is a builder of diverse infrastructure with modern workloads on both bare-metal and cloud platforms. He's traversed roles in system administration, network engineering, and DevOps. You can learn more about him here.