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:[bash]root# service mysqld stop[/bash]
- Then, start MySQL in safe mode:[bash]root# mysqld_safe –skip-grant-tables &[/bash]
- Log into MySQL as root:[bash]root# mysql -u root[/bash]
- 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]
- Do flush privileges and logout mysql:[bash]mysql> flush privileges; exit;[/bash]
- Restart the service:[bash]root# service mysqld restart[/bash]
That’s it 🙂