MySQL Recover / Change root Password | Drupal 8

MySQL Recover / Change root Password

Submitted by editor on Mon, 06/27/2016 - 21:19
Question

How to recover and/or change the MySQL root password on linux ?

1. Stop the MySQL service of started

sudo /etc/init.d/mysql stop #On Debian based linux systems (Ubuntu, Mint ...)
sudo /etc/init.d/mysqld stop #On Red Hat Enterprise based Linux systems (CentOS, Fedora, Suse ...)

2. Start MySQL without a password

sudo mysqld_safe --skip-grant-tables & # Add '&' to start process on new thread

3. Connect to MySQL

mysql -uroot

4. Set a new MySQL root password

use mysql;
update user set password=PASSWORD("mynewpassword") where User='root';
flush privileges;
quit

5. Stop and start the MySQL service

#On Debian based linux systems (Ubuntu, Mint ...)
sudo /etc/init.d/mysql stop
sudo /etc/init.d/mysql start

#On Red Hat Enterprise based Linux systems (CentOS, Fedora, Suse ...)
sudo /etc/init.d/mysqld stop
sudo /etc/init.d/mysqld start

Now you can login to the database using new password

mysql -u root -p

 

Change MySQL Root password using mysqladmin

Example:
mysqladmin -u root -p'root' password 'newpassword'

 

Change password use mysql cli
mysql mysql -u root -p
UPDATE user SET password=PASSWORD('YourNewRootPassword') WHERE user="root";
flush privileges;
quit

Add new comment