先设置免密登录
vim /etc/my.cnf
skip-grant-tables #在[mysqld]下面添加这一行,忽略权限表
重启MySQL
/etc/init.d/mysqld restart
或
service mysql stop
service mysql start
登录
MySQL-uroot -p (提示输入密码直接按Enter)
use mysql; #进入mysql库
更新密码
alter user root@localhost identified by '新密码';
or
update mysql.user set password=PASSWORD('新密码') where User='root';
or
update mysql.user set authentication_string=password('新密码') where user='root';
FLUSH PRIVILEGES #刷新
注释skip-grant-tables 重启MySQL
vim /etc/my.cnf
skip-grant-tables
本文介绍如何通过临时禁用MySQL权限表来重置丢失的root密码,包括修改配置文件、重启服务、登录数据库并更新root用户的密码。
1361

被折叠的 条评论
为什么被折叠?



