Categories

ID #1321

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

Forgotten root mysql password

 

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, 8.0, 8.1, 8.2


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'
User='root';
mysql> exit;

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



Tags: -

Related entries:

You cannot comment on this entry