Score:1

MySQL does not create socket when launched at boot

ve flag

After a reboot, mysqld is running, but no socket gets created and you cannot connect to the MySQL server:

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

If you restart the MySQL service, then you can connect to the database as expected. The service takes about one minute to restart:

# 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> 

Logs from journalctl show a reboot at 19:24, a startup at 19:27 and then me manually restarting the service at 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.

Here's the output of 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.

How can I get MySQL to start cleanly after a reboot?

Config is Ubuntu 22.10/x86_64/Linux 5.19.0-28. Problem also occurred with 22.04. Upgrading to 22.10 yesterday did not resolve the problem.

in flag
How large are the databases? It *shouldn't* take MySQL a full minute to get going after a reboot unless you're working with thousands of databases, thousands of gigabytes, or one really persistent error ...
Paul Schreiber avatar
ve flag
Nothing over 600 MB. Most are 6-10 MB.
in flag
In that case, there should be some specific error messages in `/var/log/mysql/error.log` that points to why the daemon cannot start at boot, and why it takes so long to manually start.
Paul Schreiber avatar
ve flag
The daemon does start at boot. `ps` shows it is running. (This is my first sentence in the question.) But no socket is created in `/var/run/mysql`.
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.