Issue
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
Solution
As @suchislife suggested in his comment to my question, I followed his advice and rented a DigitalOcean MySQL Managed Database instead of the self-hosted database that I had on my DigitalOcean Droplet. I wrote my experience at https://jaimemontoya.com/blog/2023/10/17/23/21/ in terms of pricing when following the managed database route, emphasizing a comparison of the infrastructure as a service (IaaS) versus platform as a service (PaaS) models.
My conclusion: Self-hosted databases and/or mail servers is not advisable because of their inherent challenges.
Answered By - Jaime Montoya Answer Checked By - Marilyn (WPSolving Volunteer)