1. first, run these bash commands
sudo /etc/init.d/mysql stop # stop mysql service
sudo mysqld_safe --skip-grant-tables & # start mysql without password
# enter -> go
mysql -uroot # connect to mysql
2. then run mysql commands => copy paste this to cli manually
use mysql; # use mysql table
update user set authentication_string=PASSWORD("") where User='root'; # update password to nothing
update user set plugin="mysql_native_password" where User='root'; # set password resolving to default mechanism for root user
flush privileges;
quit;
3. run more bash commands
sudo /etc/init.d/mysql stop
sudo /etc/init.d/mysql start # reset mysql
# try login to database, just press enter at password prompt because your password is now blank
mysql -u root -p
本文提供了一种在忘记MySQL root用户密码的情况下,通过一系列bash和MySQL命令重新设置密码的方法。首先,停止并以不检查权限的方式启动MySQL服务,然后通过MySQL命令更新root用户的认证字符串为空,并设置默认的密码解析机制,最后重启MySQL服务。
3243

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



