How to Reset/Recover MySQL root Password Step by Set on Linux (RHEL/Centos 6.x) :
Use the below steps to reset/recover a MySQL root password :
Step 1. Log in as root user.
Step 2. Stop the mysql service if service is running.
# /etc/init.d/mysqld stop
Or
# service mysqld stop
Output :
Stopping mysqld: [ OK ]
Step 3. Started MySQL in safe mode.
# mysqld_safe --skip-grant-tables &
Output:
160924 15:28:01 mysqld_safe Logging to ‘/var/log/mysqld.log’.
160924 15:28:01 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
Step 4. Connect to MySQL Server with command
mysql
Output:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MariaDB connection id is 1
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
Step 5. Use mysql database for change password.
mysql>Use mysql; mysql> update user set password=PASSWORD("password-New") where User='root'; mysql> flush privileges; mysql> exit;
Step 6. Stop MySQL in safe mode.
# /etc/init.d/mysql stop
Or
# service mysqld stop
Output :
14653 13:42:12 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
Stopping mysqld: [ OK ]
[1]+ Done mysqld_safe –skip-grant-tables
Step 7. Start MySQL server
# /etc/init.d/mysql start
Or
# service mysqld start
Step 8. Log in with the new password
# mysql -u root –p