Reset your forgotten root MySQL password

If you’ve forgotten the root user’s password you created for your MySQL database, you can reset it.

Step 1: Turn off MySQL:

CentOS 6: # service mysqld stop

CentOS 7: # systemctl stop mysqld.service

Step 2: Reset the root password through safe mode:

Start up safe mode

# mysqld_safe –skip-grant-tables

Step 3: Log into MySQL as root

# mysql -u root

At the mysql> prompt, reset the password. To do this, type the following command, replacing NEW-PASSWORD with the new root password:

Mysql> UPDATE mysql.user SET Password=PASSWORD(‘NEW-PASSWORD’) WHERE User=’root’;

At the mysql> prompt, type the following commands:

Mysql> FLUSH PRIVILEGES;

Mysql> exit;

Step 4: Stop the MySQL server using the following command. You will be prompted to enter the new MySQL root password before the MySQL server shuts down:

# mysqladmin -u root -p shutdown

Step 5: Start the MySQL server normally. To do this, type the appropriate command for your Linux distribution:

For CentOS 6:

# service mysqld start

For Centos 7:

# systemctl start mysqld.service