mysql密码找回 不修改密码 mysql找回帐号密码

导读:忘记MySQL帐号密码是一件很常见的事情,但不用担心 , 有多种方法可以找回 。本文将介绍几种找回MySQL帐号密码的方法 。
1. 使用root帐号重置密码
如果你记得root帐号的密码,可以使用root帐号登录MySQL,然后重置你忘记密码的帐号的密码 。具体步骤如下:
a. 登录MySQL:mysql -u root -p
b. 选择要重置密码的数据库:use mysql;
c. 更新用户密码:update user set authentication_string=password('new_password') where user='username';
d. 刷新权限:flush privileges;
2. 修改my.cnf文件
如果你无法使用root帐号重置密码,可以尝试修改my.cnf文件来跳过密码验证 。具体步骤如下:
a. 打开my.cnf文件:sudo vi /etc/mysql/my.cnf
b. 在[mysqld]部分添加skip-grant-tables:[mysqld] skip-grant-tables
c. 保存并退出文件
d. 重启MySQL:sudo service mysql restart
e. 进入MySQL:mysql -u root
f. 更新用户密码:update user set authentication_string=password('new_password') where user='username';
g. 移除skip-grant-tables:sudo vi /etc/mysql/my.cnf [mysqld] #skip-grant-tables
h. 保存并退出文件
i. 重启MySQL:sudo service mysql restart
3. 重置root密码
如果你连root帐号的密码都忘记了,可以尝试重置root帐号的密码 。具体步骤如下:
a. 停止MySQL:sudo service mysql stop
b. 启动MySQL并跳过密码验证:sudo mysqld_safe --skip-grant-tables &
c. 登录MySQL:mysql -u root
d. 更新root密码:update mysql.user set authentication_string=password('new_password') where user='root';
e. 刷新权限:flush privileges;
f. 退出MySQL:exit
g. 停止MySQL:sudo service mysql stop
h. 启动MySQL:sudo service mysql start
【mysql密码找回 不修改密码 mysql找回帐号密码】总结:忘记MySQL帐号密码不必惊慌失措,可以通过使用root帐号重置密码、修改my.cnf文件或重置root密码等方法来找回密码 。

    推荐阅读