Solution for root password forgetting of mysql under linux
- 2021-06-28 14:22:25
- OfStack
Five easy steps to solve the mysql root password forgotten problem, I hope you can help.
1. Modify MySQL's login settings:
# vi /etc/my.cnf
Add a sentence to the paragraph [mysqld], skip-grant-tables
For example:
[mysqld]
datadir=/var/lib/mysql
socket=/var/lib/mysql/mysql.sock
skip-grant-tables
2. Restart mysql
# service mysql start
3. Log in and modify root password for MySQL
# mysql
mysql> USE mysql ;
mysql> UPDATE user SET Password = password ( 'new-password' ) WHERE User = 'root' ;
mysql> flush privileges ;
mysql> quit
4. Modify MySQL's login settings back
# vi /etc/my.cnf
Delete the skip-grant-tables just added to the paragraph [mysqld]
5. Restart mysqld
# service mysql start