忘记 MySQL root 密码的解决方法:通过 mysqld_safe 选项停止和启动 MySQL 服务,在启动时添加 skip-grant-tables 选项,连接服务器后重置 root 密码。停止 MySQL 服务,编辑配置文件添加 init-file 选项,在 /var/lib/mysql/ 目录中创建 init_root_password.sql 文件,包含重置 root 密码的命令,然后启动 MySQL 服务即可。停止 MySQL 服务,以 root 用户启动 MySQL,在 MyS

忘记 MySQL root 密码怎么办?
恢复密码的方法:
方法 1:使用 mysqld_safe 选项
sudo systemctl stop mysql
skip-grant-tables 选项:sudo mysqld_safe --skip-grant-tables &
mysql -u root
FLUSH PRIVILEGES;
exit
sudo systemctl restart mysql
方法 2:使用重置文件
sudo systemctl stop mysql
/etc/mysql/mysql.cnf):在 [mysqld] 段落中,添加以下行:
<code>init-file=/var/lib/mysql/init_root_password.sql</code>
/var/lib/mysql/ 目录中创建一个名为 init_root_password.sql 的文件。在 init_root_password.sql 文件中,输入以下内容:
<code>ALTER USER 'root'@'localhost' IDENTIFIED BY '新密码';</code>
init_root_password.sql 文件。sudo systemctl start mysql
方法 3:使用低级修复工具
sudo systemctl stop mysql
sudo mysqld --user=root --console
在 MySQL 控制台中输入以下命令:
<code>mysql> UPDATE mysql.user SET Password=PASSWORD('新密码') WHERE User='root';
mysql> FLUSH PRIVILEGES;
mysql> quit</code>sudo systemctl start mysql
以上就是mysql忘记root密码怎么办的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号