### 方法一
# /etc/init.d/mysql stop
# mysqld_safe --user=mysql --skip-grant-tables --skip-networking &
# mysql -u root mysql
mysql> UPDATE user SET Password=PASSWORD('newpassword') where USER='root';
mysql> FLUSH PRIVILEGES;
mysql> quit
# /etc/init.d/mysql restart
# mysql -uroot -p
Enter password: <输入新设的密码newpassword>
### 方法二
# /etc/init.d/mysql stop
# /usr/bin/mysqld_safe --skip-grant-tables
# mysql -u root
mysql> set global read_only=1;//(读写属性)
mysql> flush privileges;
mysql> grant all privileges on *.* to 'root'@'localhost' identified by 'root' with grant option;
mysql> flush privileges;
[mysql]修复root无法登陆
最新推荐文章于 2025-04-15 00:11:28 发布
本文提供了两种重置MySQL root用户密码的方法。方法一通过禁用权限表并直接更新root用户的密码实现;方法二则是在跳过权限表的情况下设置全局只读属性,并重新授予root用户所有权限。
1380

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



