MySQL 5.7.9 reset root password

      Record the steps below:

Modify the my.cnf configuration file

# sudo vi /etc/my.cnf

Add a sentence to the [mysqld] section: skip-grant-tables, as follows:

[mysqld] 
datadir=/var/lib/mysql  
socket=/var/lib/mysql/mysql.sock  
skip-grant-tables 

# ON/OFF/FORCE/FORCE_PLUS_PERMANENTvalidate-password=OFF 
# 是否使用密码验证该插件(及强制/永久强制使用)
validate-password=OFF  

restart the service

# sudo systemctl restart mysqld

Login and change password

# mysql -uroot

# mysql> use mysql

change Password

MySQL 5.7.6 and latest:

# mysql> update user set authentication_string=PASSWORD('newpass') where User='root';

MySQL 5.7.5 or earlier versions r:

# mysql> update user set password=PASSWORD('newpass') where User='root';

login test

Modify the settings of my.cnf back, restart the MySQL service, and log in to test:

# mysql -u root -p

Enter the set password and test the modification successfully.

refer to

How to Reset the Root Password

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326240957&siteId=291194637