MySQL works correctly on my server for several days. But all of a sudden, it stops working and my PHP application cannot connect to it anymore. The solution is easy: start/restart the MySQL service. However, it is a problem because my PHP application becomes unreliable if the MySQL service will suddenly stop working. Any ideas about what the root cause of this may be? When MySQL is down and I check the status, this is what I get:
root@jaimemontoya:~# systemctl status mysql.service
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: failed (Result: exit-code) since Wed 2023-07-26 17:24:51 UTC; 1 day 19h ago
Process: 11197 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid (code=exited, status=1/FAILURE)
Process: 11176 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
Main PID: 15388 (code=killed, signal=KILL)
Jul 26 17:24:51 jaimemontoya systemd[1]: mysql.service: Control process exited, code=exited status=1
Jul 26 17:24:51 jaimemontoya systemd[1]: mysql.service: Failed with result 'exit-code'.
Jul 26 17:24:51 jaimemontoya systemd[1]: Failed to start MySQL Community Server.
Jul 26 17:24:51 jaimemontoya systemd[1]: mysql.service: Service hold-off time over, scheduling restart.
Jul 26 17:24:51 jaimemontoya systemd[1]: mysql.service: Scheduled restart job, restart counter is at 6.
Jul 26 17:24:51 jaimemontoya systemd[1]: Stopped MySQL Community Server.
Jul 26 17:24:51 jaimemontoya systemd[1]: mysql.service: Start request repeated too quickly.
Jul 26 17:24:51 jaimemontoya systemd[1]: mysql.service: Failed with result 'exit-code'.
Jul 26 17:24:51 jaimemontoya systemd[1]: Failed to start MySQL Community Server.
I am using Ubuntu 18.04.2 LTS:
root@jaimemontoya:~# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04.2 LTS
Release: 18.04
Codename: bionic
Maybe upgrading MySQL and/or Ubuntu could help to fix this issue?
As I said, the solution is simply restarting MySQL (see below) but I should not need to be manually restarting it after a few days, and MySQL should not suddenly stop working.
root@jaimemontoya:~# systemctl restart mysql.service
root@jaimemontoya:~# systemctl status mysql.service
● mysql.service - MySQL Community Server
Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
Active: active (running) since Fri 2023-07-28 14:37:58 UTC; 8s ago
Process: 11668 ExecStart=/usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid (code=exited, status=0/SUCCESS)
Process: 11647 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
Main PID: 11670 (mysqld)
Tasks: 27 (limit: 1103)
CGroup: /system.slice/mysql.service
└─11670 /usr/sbin/mysqld --daemonize --pid-file=/run/mysqld/mysqld.pid