1.问题所示
发现密码验证错误,遗失密码
2. 基本知识
- 停止mysql服务:
sudo systemctl stop mysql
- 以跳过权限表模式启动mysql:
sudo mysqld_safe --skip-grant-tables &
- 登录mysql:
mysql -u root
- 重置root用户密码:(不同版本不一,如果执行出错,可看下文)
alter user 'root'@'localhost' identified by 'new_password'; flush privileges;
- 重新启动mysql服务:
sudo systemctl start mysql
3. 解决方法
根据上述的基本知识操作进行演示,过程中可能会出现个别bug
3.1 跳过验证bug
跳过验证的时候,如果出现如下提示:
root@iz7xv98hm4hq0dd3xv23vuz:~# sudo mysqld_safe --skip-grant-tables & [1] 720919 root@iz7xv98hm4hq0dd3xv23vuz:~# 2024-09-02t14:05:11.207426z mysqld_safe logging to '/var/log/mysql/error.log'. 2024-09-02t14:05:11.233525z mysqld_safe a mysqld process already exists [1]+ exit 1 sudo mysqld_safe --skip-grant-tables
截图如下:
先确保所有 mysql 相关的进程都被停止:ps aux | grep mysqld
如果看到任何运行中的 mysql 进程,使用 kill 或 kill -9 命令手动终止它们:sudo kill -9 <pid>
3.2 设定初始密码
使用的是 mysql 5.7 或更高版本,密码字段通常是 authentication_string,但 password() 函数可能已被弃用
update mysql.user set authentication_string='123456' where user='root' and host='localhost';
使用的是 mysql 5.6 或更低版本,密码字段可能是 password,可以使用以下命令:
update mysql.user set password=password('123456') where user='root' and host='localhost';
之后统一执行:`flush privileges;``
到此这篇关于linux中mysql跳过密码验证以及bug的解决方法(图文)的文章就介绍到这了,更多相关linux mysql跳过密码验证bug内容请搜索代码网以前的文章或继续浏览下面的相关文章希望大家以后多多支持代码网!
发表评论