环境:CentOS7 MySQL5.7
mysql -uroot -p,后输入密码后提示
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)
- 停止mysql服务
sudo systemctl mysqld stop 跳过验证
编辑mysql配置文件
sudo vim /etc/my.cnf在最后添加一行,使其登录时跳过权限检查
skip_grant_tables修改密码
启动MySQL服务,
sudo systemctl mysqld start登录MySQL
mysql -uroot -p此时提示输入密码,输入任意密码回车即可进入MySQL。
将数据库切换至mysql库
mysql>USE mysql;修改密码
mysql>update user set authentication_string = password(‘newpasswd’) where user='root';刷新MySQL权限相关的表
mysql>flush privileges;退出
mysql>exit;重启服务
将my.cnf文件中加入的跳过权限语句删除或加#号注释重启服务,使用修改后的密码登录即可。
sudo systemctl mysqld restart
本文提供了一种在CentOS7环境下针对MySQL5.7版本的密码重置方法,通过修改配置文件使MySQL跳过权限检查,然后更新root用户的密码。
7951





