0

我无法连接到 MySQL 服务器,所以我停止了 MySQL:

sudo /etc/init.d/mysql stop
# Stopping mysql (via systemctl): mysql.service.

然后,使用 root 登录并再次启动 MySQL:

sudo -s
mysqld_safe --skip-grant-tables &
# .... mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
# 2021-05-29T03:01:11.967630Z mysqld_safe mysqld from pid file /var/lib/mysql...... ended

之后我执行:

mysqld_safe --skip-grant-tables
# Logging to '/var/lib/mysql/......err'.
# 2021-05-29T03:03:40.507375Z mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
# 2021-05-29T03:03:40.834556Z mysqld_safe mysqld from pid file /var/lib/mysql/...... ended
# [1]+  Done                    mysqld_safe --skip-grant-tables

最后我执行了:

mkdir -p /var/run/mysqld
chown mysql:mysql /var/run/mysqld
mysql -u root
# ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

我也忘记了我的root密码。

4

1 回答 1

0

哈,欢迎。

你不需要调用mysqld_safe两次,只需要一次。该参数--skip-grant-tables使任何与 MySQL 的本地连接都无需​​密码即可发生。

消息:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock'

意味着您的服务器没有监听位于/var/run/mysqld/mysqld.sock.

使用以下命令杀死每个mysqld实例:

ps -ef | grep mysql
# copy every id and...
kill <id>

在 MySQL 日志中寻找任何线索,可能在/var/log/mysql/error.log,然后尝试以mysqld_start --skip-grant-tables.

于 2021-05-29T22:30:42.003 回答