温馨提示×

ubuntu上mysql忘记密码怎么办

小樊
83
2024-06-19 15:01:06
栏目: 云计算

如果您在Ubuntu上忘记了MySQL的密码,可以通过以下步骤重置密码:

  1. 打开终端,以root用户身份登录。

  2. 停止MySQL服务:

sudo systemctl stop mysql
  1. 使用以下命令启动MySQL并跳过权限检查:
sudo mysqld_safe --skip-grant-tables &
  1. 使用以下命令登录到MySQL:
mysql -u root
  1. 选择MySQL数据库:
use mysql;
  1. 更新root用户密码:
update user set authentication_string=PASSWORD('新密码') where user='root';

(在MySQL 5.7版本之后,密码字段已更名为authentication_string)

  1. 刷新权限:
flush privileges;
  1. 退出MySQL:
exit;
  1. 停止MySQL服务:
sudo systemctl stop mysqld
  1. 重新启动MySQL服务:
sudo systemctl start mysql

现在您应该可以使用新密码登录到MySQL了。请确保将“新密码”替换为您想要设置的新密码。

0