centos mysql8解决Access denied for user ‘root‘@‘localhost‘ (using password: YES)

环境

系统:CentOS Stream release 9

mysql版本:mysql Ver 8.0.34 for Linux on x86_64

问题

mysql登录提示

复制代码
 Access denied for user 'root'@'localhost' (using password: YES)

解决方法

编辑 /etc/my.cnf ,在[mysqld] 部分最后添加一行

bash 复制代码
skip-grant-tables  

保存后重启mysql

systemctl restatus mysqld

输入以下命令,回车后输入密码再回车登录Mysql

mysql -uroot -p mysql

重新设置密码,其中 your_pwd 部分改为你自己想要设置的密码

update user set password=password("your_pwd") where user='root';

刷新权限

flush privileges;

修改完成后my.cnf删除skip-grant-tables

想要修改成简单密码

修改密码策略

set global validate_password.policy=LOW;

set global validate_password.length=6;

刷新权限

flush privileges;

相关推荐
硅基导游8 分钟前
Linux内核观测与跟踪的利器BPF环境测试
linux·服务器·性能监控·bpf
YXXY31318 分钟前
Linux进程概念(四)
linux
了一梨1 小时前
[T113] 交叉编译 OpenCV 4.5.2 + face 模块
linux·笔记·opencv
我是谁??1 小时前
在 Rocky Linux 9 无桌面环境中通过 SSH 安装 KVM 虚拟机(Rocky9含 XFCE 桌面/xubuntu20)完整指南
linux·服务器·ssh
3DVisionary1 小时前
突破3C质检产能瓶颈:XTOM蓝光扫描仪配合自动化转台实现精密件批量检测
运维·人工智能·自动化·xtom扫描仪·自动化检测·消费电子质检·良率控制
困死,根本不会1 小时前
VMware Ubuntu 显示有线连接却无法上网|完整排查与解决笔记
linux·笔记·ubuntu
Luke Ewin1 小时前
Linux中部署Qwen3.5大模型
linux·运维·服务器·ai·llm·qwen3.5
xin_yao_xin1 小时前
Windows 下 Docker Desktop 安装教程及常用命令(2026 最新)
运维·docker·容器