由于mysql密码规范,导致密码较为复杂,难免会遇到忘记密码的情况,今天一起来学习如何在忘记密码的情况下修改密码。 进入配置文件/etc/my.cnf,添加 skip-grant-tables。
[root@slave ~]
1 [client]
2 port = 3306
3 socket = /tmp/mysql.sock
4
5 [mysqld]
6 server_id=2
7 relay-log=relay-log
8 relay-log-index=relay-log.index
9 skip-grant-tables
10 port = 3306
11 user = mysql
………………
重启mysql
[root@slave ~]
[root@slave ~]
此时可以不用密码直接进入mysql
[root@slave ~]
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 8.0.15 MySQL Community Server - GPL
Copyright (c) 2000, 2019, 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>
重新设置密码。
mysql> flush privileges;
Query OK, 0 rows affected (0.10 sec)
mysql> alter user "root"@"localhost" identified by "WWW13@me";
Query OK, 0 rows affected (0.11 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
知识点补充:
flush privileges原理:
flush privileges 命令本质上的作用是将当前user和privilige表中的用户信息权限设置从mysql库(MySQL数据库的内置库)中提取到内存里。MySQL用户数据和权限有修改后,希望在"不重启MySQL服务"的情况下直接生效,那么就需要执行这个命令。通常是在修改ROOT帐号的设置后,怕重启后无法再登录进来,那么直接flush之后就可以看权限设置是否生效。而不必冒太大风险。
进入配置文件linux 忘记密码解决方法,将刚才加入的参数删除或注释,不然还是可以免密登录。
cat /etc/my.cnf
[client]
port = 3306
socket = /tmp/mysql.sock
[mysqld]
server_id=2
relay-log=relay-log
relay-log-index=relay-log.index
………………
最后重启mysql
[root@slave ~]
[root@slave ~]
好了,到此密码重置完毕。
从此再也不用担心密码忘记了。
(编辑:应用网_常德站长网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|