如果您在Ubuntu上忘记了MySQL的密码,可以通过以下步骤重置密码:
打开终端,以root用户身份登录。
停止MySQL服务:
sudo systemctl stop mysql使用以下命令启动MySQL并跳过权限检查:sudo mysqld_safe --skip-grant-tables &使用以下命令登录到MySQL:mysql -u root选择MySQL数据库:use mysql;更新root用户密码:update user set authentication_string=PASSWORD('新密码') where user='root';(在MySQL 5.7版本之后,密码字段已更名为authentication_string)
刷新权限:flush privileges;退出MySQL:exit;停止MySQL服务:sudo systemctl stop mysqld重新启动MySQL服务:sudo systemctl start mysql现在您应该可以使用新密码登录到MySQL了。请确保将“新密码”替换为您想要设置的新密码。


