0x00 MySQL 用户密码位置:
-
MySQL 下密码保存在 mysql 数据库 user 表中;
user 表 - 表 user 中在5.7(大致是)以前有字段Password保存密码,之后,改成了 authentication_string保存密码;
authentication_string
0x01 修改密码
- 忘记密码:
[root@master1 ~]# mysql -uroot -p Enter password: ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)
- 更改配置
vi /etc/my.cnf #在mysqld模块下添加 skip-grant-tables
- 重启 mysql 服务
systemctl restart mysqld
- 传统修改密码语句无效
mysql> update user set password=password('123') where user='root'; ERROR 1054 (42S22): Unknown column 'password' in 'field list'
- 新的修改密码语句
mysql> update user set authentication_string=password('123') where user='root'; Query OK, 1 row affected, 1 warning (0.00 sec) Rows matched: 1 Changed: 1 Warnings: 1
- 更改配置重启mysql 成功登陆
[root@master1 ~]# vi /etc/my.cnf注释 # skip-grant-tables [root@master1 ~]# systemctl restart mysqld [root@master1 ~]# mysql -uroot -p123 mysql: [Warning] Using a password on the command line interface can be insecure. Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 2 Server version: 5.7.21-log Copyright (c) 2000, 2018, 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>