Reset MySQL Root Password in CentOS
In 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.
- First, need to stop MySQL:
root# service mysqld stop - Then, start MySQL in safe mode:
root# mysqld_safe --skip-grant-tables & - Log into MySQL as root:
root# mysql -u root - 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'; - Do flush privileges and logout mysql:
mysql> flush privileges; exit; - Restart the service:
root# service mysqld restart
That’s it 🙂