1. 免密码登陆

[wyhcli]➜  ~ vim /etc/my.cnf skip-grant-tables  [wyhcli]➜  ~ systemctl restart mysqld

2. 将旧密码置空

[wyhcli]➜ ~ vim /etc/my.cnf skip-grant-tables 
[wyhcli]➜ ~ systemctl restart mysqld

3. 去除免密码登陆

  • 删掉步骤1的语句 skip-grant-tables
  • 重启服务 `service mysqld restart

4. 修改密码

[wyhcli]➜ ~ mysql -uroot -p # 提示输入密码时直接敲回车,刚刚已经将密码置空了
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.22

Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> alter user 'root'@'localhost' identified by '新密码(码形式过于简单则会报错)';
Query OK, 0 rows affected (0.01 sec)


mysql>