可以尝试使用 mysqld
来进行安全模式启动。
但是要注意,使用 mysqld
进行安全模式启动的过程要复杂一些。以下是一个基本的步骤:
-
找到
my.cnf
文件:my.cnf
是 MySQL 的配置文件,通常位于/etc/my.cnf
,/etc/mysql/my.cnf
或~/.my.cnf
。 -
编辑
my.cnf
文件: 在文件的[mysqld]
部分下方添加以下行:skip-grant-tables
这将允许 MySQL 在下次启动时跳过权限表,使你可以直接登录。
-
重启 MySQL 服务:
sudo systemctl stop mysqld sudo systemctl start mysqld
-
连接到 MySQL 并重置密码:
mysql -u root USE mysql; UPDATE user SET authentication_string=PASSWORD("newpassword") WHERE User='root'; FLUSH PRIVILEGES; EXIT;
将
"newpassword"
替换为你想要的新密码。 -
恢复原始的
my.cnf
设置: 编辑my.cnf
文件,移除skip-grant-tables
行,然后再次重启 MySQL 服务。
请记住,在编辑任何配置文件之前,最好先做一个备份,以防止出现问题。.