如何重置或恢复 MySQL 的管理员帐户密码?

slo*_*ife 14 mysql password reset

我有一个“继承”的 MySQL 数据库,但我没有获得管理员凭据。但是,我确实可以访问它运行的盒子。有没有办法恢复管理员凭据或创建新凭据?

Dav*_*itt 15

阅读并执行MySQL 参考手册中关于重置 root 密码的章节

此过程在未经授权的情况下启动 mysql 守护程序,允许您在不提供凭据的情况下进行连接。在此模式下,您可以正常连接,并重置密码和授权。之后不要忘记在适当的授权下再次启动mysql。


Bre*_*nt 6

如果这是 Debian/Ubuntu 机器,则有一个特殊的 root 等效帐户,称为debian-sys-maint。您可以在/etc/mysql/debian.cnf 中读取密码

使用该密码,您可以使用 debian-sys-maint 登录 mysql:

mysql --defaults-file=/etc/mysql/debian.cnf mysql
Run Code Online (Sandbox Code Playgroud)

登录后,请执行以下操作:

update user set password=password('<new password>') where user='root';
flush privileges;
quit;
Run Code Online (Sandbox Code Playgroud)

现在应该可以使用您的新密码访问 root:

mysql -uroot -p
Run Code Online (Sandbox Code Playgroud)