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:
    root# service mysqld stop
  2. Then, start MySQL in safe mode:
    root# mysqld_safe --skip-grant-tables &
  3. Log into MySQL as root:
    root# mysql -u root
  4. Reset the password using the following command:
    mysql> update mysql.user set password=PASSWORD("YourNewPassW0RD") where User='root';

    or for MySQL 5.7 and later:

    ALTER USER 'root'@'localhost' IDENTIFIED BY 'YouNetPassWORD';
  5. Do flush privileges and logout mysql:
    mysql> flush privileges; exit;
  6. Restart the service:
    root# service mysqld restart

That’s it 🙂

Leave a Reply