1. Home
  2. Cluster Management
  3. I’ve forgotten my MySQL root password. How do I get it back?

I’ve forgotten my MySQL root password. How do I get it back?

Getting the MySQL root password back is diffiicult (sha-1 hash).

Resetting the password is a better solution.
The below instructions are known to work with Bright 7.3 and later.

CentOS 7 instructions:

To do a reset of the password, stop all applications that use the MySQL service during the reset operation. Stop the mysql service and start it in safe mode during the reset.

The following commands on the head node (tested for CentOS 7) show how such a reset session can be carried out:

# systemctl stop mariadb.service  
# mysqld_safe --skip-grant-tables &
# mysql -u root
MariaDB [(none)]> use mysql;
MariaDB [(none)]> update user set password=PASSWORD("newpass") where
User='root';
MariaDB [(none)]> flush privileges;
MariaDB [(none)]> quit
# pkill mysqld_safe
# systemctl start mariadb.service

Ubuntu 16.04 instructions:

# systemctl stop mysql 
# mkdir /var/run/mysqld 
# chown mysql.mysql /var/run/mysqld 
# mysqld_safe --skip-grant-tables

mysql> flush privileges;
mysql> alter user 'root'@'localhost' identified by 'MyNewPass';
mysql> exit;

Once password has been changed, kill the mysql and mysqld_safe processes and start the mysql service again. 

# pkill mysqld_safe && sleep 10 &&systemctl start mysql 

Updated on August 15, 2022

Was this article helpful?

Related Articles

Leave a Comment