Tencent cloud server forgot (reset) mysql password - root account

1. Skip the MySQL password authentication process

  • Enter the my.cnf file,
# vim /etc/my.cnf   (Linux)
  • In vim editing state, press“i”Enter the editing state, add
    skip-grant-tables
    insert image description here
  • After editing isesc, exit edit mode,
    and enter:wqYou can save the modified content

The function is to skip the login authentication when logging in. In other words, root can log in with any password.

2. Restart MySQL:

service mysqld restart

3. Enter mysql to enter the mysql operation directory

# mysql -u root -p  (弹出输入密码直接回车就可以登录进去)
mysql> use mysql; 
mysql> update user set password=password('你的密码') where user='root'; 
mysql> flush privileges; 

ps:
If update user set password=password('your password') where user='root'; report an error and replace it with

 update mysql.user set authentication_string=password('你的密码') where user='root';

4. Edit my.cnf, delete the content "skip-grant-tables" just added, and then restart MySQL.

5. Then re-enter the server and re-enter

# mysql -u root -p 

Guess you like

Origin blog.csdn.net/weixin_38746118/article/details/104137991