MySQL 在启动时不创建套接字

MySQL 在启动时不创建套接字

重启后,mysqld正在运行,但没有创建套接字,并且您无法连接到 MySQL 服务器:

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

如果您重新启动 MySQL 服务,则可以按预期连接到数据库。服务重新启动大约需要一分钟:

# service mysql restart
# ls -l /var/run/mysqld/
total 8.2k
srwxrwxrwx 1 mysql mysql 0 Jan  8 19:35 mysqld.sock=
-rw------- 1 mysql mysql 5 Jan  8 19:35 mysqld.sock.lock
srwxrwxrwx 1 mysql mysql 0 Jan  8 19:35 mysqlx.sock=
-rw------- 1 mysql mysql 5 Jan  8 19:35 mysqlx.sock.lock
# mysql
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 11
Server version: 8.0.31-0ubuntu2 (Ubuntu)

Copyright (c) 2000, 2022, Oracle and/or its affiliates.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> 

日志显示,journalctl服务在 19:24 重启,在 19:27 启动,然后我在 19:33 手动重启了该服务


Jan 08 19:23:58 green systemd[1]: Stopping MySQL Community Server...
Jan 08 19:24:03 green systemd[1]: mysql.service: Deactivated successfully.
Jan 08 19:24:03 green systemd[1]: Stopped MySQL Community Server.
Jan 08 19:24:03 green systemd[1]: mysql.service: Consumed 23.311s CPU time.
-- Boot 31bd3ef983b445389647be5c53761256 --
Jan 08 19:27:31 green systemd[1]: Starting MySQL Community Server...
Jan 08 19:33:29 green systemd[1]: mysql.service: Deactivated successfully.
Jan 08 19:33:29 green systemd[1]: Stopped MySQL Community Server.
Jan 08 19:33:29 green systemd[1]: mysql.service: Consumed 10.711s CPU time.
Jan 08 19:33:29 green systemd[1]: Starting MySQL Community Server...
Jan 08 19:34:20 green systemd[1]: Started MySQL Community Server.
Jan 08 19:34:30 green systemd[1]: mysql.service: Deactivated successfully.
Jan 08 19:34:30 green systemd[1]: mysql.service: Consumed 6.314s CPU time.
Jan 08 19:34:41 green systemd[1]: Starting MySQL Community Server...
Jan 08 19:35:19 green systemd[1]: Started MySQL Community Server.

以下是 的输出systemctl

# systemctl status mysql
● mysql.service - MySQL Community Server
     Loaded: loaded (/lib/systemd/system/mysql.service; enabled; preset: enabled)
     Active: active (running) since Sun 2023-01-08 19:35:19 EST; 3h 23min ago
    Process: 2588 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
   Main PID: 2596 (mysqld)
     Status: "Server is operational"
      Tasks: 59 (limit: 28700)
     Memory: 1.7G
        CPU: 2min 35.515s
     CGroup: /system.slice/mysql.service
             └─2596 /usr/sbin/mysqld

Jan 08 19:34:41 green systemd[1]: Starting MySQL Community Server...
Jan 08 19:35:19 green systemd[1]: Started MySQL Community Server.

如何让 MySQL 在重启后正常启动?

配置是 Ubuntu 22.10/x86_64/Linux 5.19.0-28。22.04 也出现了问题。昨天升级到 22.10 也没有解决问题。

相关内容