Reset MySQL Root Password in CentOS

mysql-reset-passwordIn your development work, there are sometimes you forgot the mysql root password so you cannot make any system-level change to the mysql server. This quick tutorial tells you how to reset mysql root password in CentOS.

  1. First, need to stop MySQL:[bash]root# service mysqld stop[/bash]
  2. Then, start MySQL in safe mode:[bash]root# mysqld_safe –skip-grant-tables &[/bash]
  3. Log into MySQL as root:[bash]root# mysql -u root[/bash]
  4. Reset the password using the following command:[bash]mysql> update mysql.user set password=PASSWORD(“YourNewPassW0RD”) where User=’root’;[/bash] or for MySQL 5.7 and later: [bash]ALTER USER ‘root’@’localhost’ IDENTIFIED BY ‘YouNetPassWORD’;[/bash]
  5. Do flush privileges and logout mysql:[bash]mysql> flush privileges; exit;[/bash]
  6. Restart the service:[bash]root# service mysqld restart[/bash]

That’s it 🙂

Leave a comment

Your email address will not be published. Required fields are marked *