李毛毛的技术专栏 An interesting software testing engineer

忘记mysql密码

2020-05-19


忘记mysql密码操作过程

1.修改/etc/my.cnf,加入skip-grant-tables;

vim /etc/my.cnf
--------------修改文件-------------
skip-name-resolve
skip-grant-tables
--------------修改完成-------------
systemctl restart mysql.server/mysqld

2.空密码进入mysql

mysql -u root -p;
Enter password:(直接回车)

进入MySQL库

use mysql;

3.修改密码

UPDATE user SET authentication_string=PASSWORD('newpassword') where USER='root';

4.还原/etc/my.cnf

5.新密码再次进入mysql

修改root密码:alter user 'root'@'localhost' identified by 'password';
修改用户密码:alter user testuser identified by 'password';
修改当前登录用户:alter user user() identified by 'password';

skip-name-resolve使用

功能:禁用dns解析,使得mysql的授权表中只能使用ip,不能使用主机名

mysql处理客户端解析过程: 1.当mysql的client连接过来的时候,服务器会主动去查找client的域名; 2.首先查找/etc/host文件,搜索域名和ip对应关系; 3.如何host文件没有,则查找DNS设置,如果没有设置DNS服务器,会立刻返回失败,此处等同于设置了skip-name-resolve参数; 4.如果设置了DNS服务器,就进行反向解析,直到timeout


上一篇 条件、循环

Comments

0 comments
Anonymous
Markdown is supported

Be the first person to leave a comment!