2021-01-20 16:48
1. 免密码登陆
[wyhcli]➜ ~ vim /etc/my.cnf #配置文件目录
skip-grant-tables #添加
[wyhcli]➜ ~ systemctl restart mysqld
2. 将旧密码置空
[wyhcli]➜ ~ mysql -uroot -p
Enter password: #直接回车
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 8.0.22 MySQL Community Server - GPL
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> use mysql; # 选择数据库
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> update user set authentication_string = '' where user = 'root'; #将密码置空
Query OK, 1 row affected (0.00 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> quit
Bye
3. 去除免密码登陆
- 删除
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>
```
- 原文作者:老鱼干🦈
- 原文链接://www.tinyfish.top:80/post/Linux_%E8%BF%90%E7%BB%B4/%E6%95%B0%E6%8D%AE%E5%BA%93/MySql/MySQL8%E4%BF%AE%E6%94%B9%E5%AF%86%E7%A0%81/
- 版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议. 进行许可,非商业转载请注明出处(作者,原文链接),商业转载请联系作者获得授权。