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

Hello I’ve a major issue here that the server diskspace got full days ago, then all services turned off
I managed to clear some space and have 48GB free space, but the issue I face now is that I can’t start Apache, MariaDB, and nginx services

Every time I start Apache, MariaDB, or nginx it turns off and I get an error in the email:

Can’t connect to MySQL localhost
ERROR 2002 (HY000): Can’t connect to local MySQL server through socket ‘/run/mysqld/mysqld.sock’ (2)

service mysql restart
Job for mysql.service failed because the control process exited with error code.
See "systemctl status mysql.service" and "journalctl -xe" for details.
root/home/admin# systemctl status mysql.service
● mysql.service - MySQL Community Server
     Loaded: loaded (/lib/systemd/system/mysql.service; disabled; vendor preset>
     Active: failed (Result: exit-code) since Fri 2023-07-21 23:47:07 CEST; 1mi>
    Process: 5983 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=e>

Jul 21 23:47:07 systemd[1]: mysql.service: Scheduled restart job, r>
Jul 21 23:47:07 systemd[1]: Stopped MySQL Community Server.
Jul 21 23:47:07 systemd[1]: mysql.service: Start request repeated t>
Jul 21 23:47:07 systemd[1]: mysql.service: Failed with result 'exit>
Jul 21 23:47:07 systemd[1]: Failed to start MySQL Community Server.

Then I tried

systemctl status mariadb.service

Warning: The unit file, source configuration file or drop-ins of mariadb.servic>
● mariadb.service
     Loaded: masked (Reason: Unit mariadb.service is masked.)
    Drop-In: /etc/systemd/system/mariadb.service.d
             └─migrated-from-my.cnf-settings.conf
     Active: inactive (dead) since Fri 2023-07-21 23:42:42 CEST; 26min ago
   Main PID: 826 (code=exited, status=0/SUCCESS)
     Status: "MariaDB server is down"

Jul 21 23:42:42 mariadbd[826]: 2023-07-21 23:42:42 0 [Note] InnoDB:>
Jul 21 23:42:42 mariadbd[826]: 2023-07-21 23:42:42 0 [Note] InnoDB:>
Jul 21 23:42:42 mariadbd[826]: 2023-07-21 23:42:42 0 [Note] InnoDB:>
Jul 21 23:42:42 mariadbd[826]: 2023-07-21 23:42:42 0 [Note] InnoDB:>
Jul 21 23:42:42 mariadbd[826]: 2023-07-21 23:42:42 0 [Note] InnoDB:>
Jul 21 23:42:42 mariadbd[826]: 2023-07-21 23:42:42 0 [Note] InnoDB:>
Jul 21 23:42:42 mariadbd[826]: 2023-07-21 23:42:42 0 [Note] InnoDB:>
Jul 21 23:42:42 mariadbd[826]: 2023-07-21 23:42:42 0 [Note] /usr/sb>
Jul 21 23:42:42 systemd[1]: mariadb.service: Succeeded.
Jul 21 23:42:42 systemd[1]: Stopped MariaDB 10.5.21 database server.
lines 1-19/19 (END)...skipping...
Warning: The unit file, source configuration file or drop-ins of mariadb.servic>
● mariadb.service
     Loaded: masked (Reason: Unit mariadb.service is masked.)
    Drop-In: /etc/systemd/system/mariadb.service.d
             └─migrated-from-my.cnf-settings.conf
     Active: inactive (dead) since Fri 2023-07-21 23:42:42 CEST; 26min ago
   Main PID: 826 (code=exited, status=0/SUCCESS)
     Status: "MariaDB server is down"

Jul 21 23:42:42 mariadbd[826]: 2023-07-21 23:42:42 0 [Note] InnoDB:>
Jul 21 23:42:42 mariadbd[826]: 2023-07-21 23:42:42 0 [Note] InnoDB:>
Jul 21 23:42:42 mariadbd[826]: 2023-07-21 23:42:42 0 [Note] InnoDB:>
Jul 21 23:42:42 mariadbd[826]: 2023-07-21 23:42:42 0 [Note] InnoDB:>
Jul 21 23:42:42 mariadbd[826]: 2023-07-21 23:42:42 0 [Note] InnoDB:>
Jul 21 23:42:42 mariadbd[826]: 2023-07-21 23:42:42 0 [Note] InnoDB:>
Jul 21 23:42:42 mariadbd[826]: 2023-07-21 23:42:42 0 [Note] InnoDB:>
Jul 21 23:42:42 mariadbd[826]: 2023-07-21 23:42:42 0 [Note] /usr/sb>
Jul 21 23:42:42 systemd[1]: mariadb.service: Succeeded.
Jul 21 23:42:42 systemd[1]: Stopped MariaDB 10.5.21 database server.

nginx :

nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: [emerg] open() "/var/log/apache2/domains/domain.com.error.log" failed (2: No such file or directory)
nginx: configuration file /etc/nginx/nginx.conf test failed

I checked the space now

root: df -h
Filesystem Size Used Avail Use% Mounted on
udev 1.9G 0 1.9G 0% /dev
tmpfs 383M 892K 382M 1% /run
/dev/sda1 75G 25G 48G 34% /
tmpfs 1.9G 0 1.9G 0% /dev/shm
tmpfs 5.0M 0 5.0M 0% /run/lock
tmpfs 1.9G 0 1.9G 0% /sys/fs/cgroup
/dev/sda15 61M 2.7M 58M 5% /boot/efi
tmpfs 383M 0 383M 0% /run/user/1000

checked the memory too

root# free -h
total used free shared buff/cache available
Mem: 3.7Gi 294Mi 2.5Gi 11Mi 979Mi 3.2Gi
Swap: 0B 0B 0B

I also tried

sudo tail -f /var/log/apache2/error.log
[Sat Jul 22 00:28:29.156692 2023] [mpm_event:notice] [pid 2027:tid 1396530985873 92] AH00492: caught SIGWINCH, shutting down gracefully
[Sat Jul 22 00:29:26.864621 2023] [mpm_event:notice] [pid 4398:tid 1398630996472 32] AH00489: Apache/2.4.57 (Ubuntu) configured – resuming normal operations
[Sat Jul 22 00:29:26.864729 2023] [core:notice] [pid 4398:tid 139863099647232] A H00094: Command line: ‘/usr/sbin/apache2’
[Sat Jul 22 00:29:27.069516 2023] [mpm_event:notice] [pid 4398:tid 1398630996472 32] AH00492: caught SIGWINCH, shutting down gracefully
[Sat Jul 22 00:29:33.810002 2023] [mpm_event:notice] [pid 4946:tid 1401744768053 76] AH00489: Apache/2.4.57 (Ubuntu) configured – resuming normal operations
[Sat Jul 22 00:29:33.810084 2023] [core:notice] [pid 4946:tid 140174476805376] A H00094: Command line: ‘/usr/sbin/apache2’
[Sat Jul 22 00:29:34.229990 2023] [mpm_event:notice] [pid 4946:tid 1401744768053 76] AH00492: caught SIGWINCH, shutting down gracefully
[Sat Jul 22 00:42:05.642805 2023] [mpm_event:notice] [pid 10850:tid 140220855149 824] AH00489: Apache/2.4.57 (Ubuntu) configured – resuming normal operations
[Sat Jul 22 00:42:05.642900 2023] [core:notice] [pid 10850:tid 140220855149824] AH00094: Command line: ‘/usr/sbin/apache2’
[Sat Jul 22 00:42:06.527493 2023] [mpm_event:notice] [pid 10850:tid 140220855149 824] AH00492: caught SIGWINCH, shutting down gracefully

is there anyway to fix this?
Thank you in advance

Up up, please I need help

looks like wrong templates, the path shows apache2 on nginx service…

Nginx in proxy mode does it for nginx

This worked for me.

First create the mysqld/ directory in /var/run/ like this:

sudo mkdir -p /var/run/mysqld/

Then create a mysqld.pid file with touch:

sudo touch /var/run/mysqld/mysqld.pid

Next create a mysqld.sock file with touch:

sudo touch /var/run/mysqld/mysqld.sock

Now change the ownerships of the directory and files to mysql:mysql like this:

sudo chown mysql:mysql -R /var/run/mysqld

And restart MySQL like this to get those files set and created:

sudo service mysql restart

When that’s all done, MySQL will be able to to create the mysqld.pid and mysqld.sock files as expected.

Hey, sorry about ‘old threads’ I don’t really understand the etiquette about old threads

  • I’m having periodic ‘MySQL can’t start / connect’ messages’.
  • It’s happened 3-4 times in the last year.
  • WordPress comes up and says ‘Database Connection Error’

Are these suggestions still relevant?
I’d rather CHECK the status of all these things instead of touching an existing file, will that overwrite it?

I’ve done a server reboot. Works for about 3-4 months.

Background

  • I’ve got about 60 WordPress sites
  • I BROKE my server 6-9 months ago on the PHP Repository problem (was it called Yuri, his repos went away or something)

So yeah, I know that I need to rebuild my server, but I just don’t have the time to do it anytime soon.