How to prevent MySQL restarts by disabling unattended upgrades on Ubuntu 24.04
When investigating random restarts of the MySQL server, the first step is to understand their cause. They could result from either a host restart or a MySQL service restart. To check if the host was restarted, run uptime:
uptime
The output shows that the host has stable uptime of over a month without interruptions. This clearly indicates that the issue is with the MySQL service itself, not the host:
10:50:05 up 31 days, 11:53, 1 user, load average: 0.50, 0.50, 0.80
To investigate further, check the MySQL error log:
cat /var/log/mysql/error.log | grep mysqld
The output reveals that the server was restarted. Note the timestamp 06:44:43 as it will be referenced below:
2026-02-04T06:44:43.764859Z 0 [System] [MY-013172] [Server] Received SHUTDOWN from user <via user signal>. Shutting down mysqld (Version: 8.4.7).
2026-02-04T06:44:55.431352Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.4.7) MySQL Community Server - GPL.
2026-02-04T06:44:55.901011Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.4.7) starting as process 1268916
2026-02-04T06:45:00.153965Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.4.7' socket: '/var/run/mysqld/mysqld.sock' port: 3306 MySQL Community Server - GPL.
The reason for this restart can be found in the APT history log. Check the last entries:
tail -n 8 /var/log/apt/history.log
The output shows that an upgrade completed at 06:44:43. This timestamp matches exactly when the MySQL server received the shutdown signal:
Start-Date: 2026-02-04 06:44:38
Commandline: /usr/bin/unattended-upgrade
Upgrade: libc6:amd64 (2.39-0ubuntu8.6, 2.39-0ubuntu8.7), locales:amd64 (2.39-0ubuntu8.6, 2.39-0ubuntu8.7), libc-dev-bin:amd64 (2.39-0ubuntu8.6, 2.39-0ubuntu8.7), libc-bin:amd64 (2.39-0ubuntu8.6, 2.39-0ubuntu8.7), libc-devtools:amd64 (2.39-0ubuntu8.6, 2.39-0ubuntu8.7), libc6-dev:amd64 (2.39-0ubuntu8.6, 2.39-0ubuntu8.7)
End-Date: 2026-02-04 06:44:43
The unattended-upgrades log also provides related information. Check the last entries:
tail -n 7 /var/log/unattended-upgrades/unattended-upgrades.log
The output shows the upgrade process:
2026-02-04 06:44:35,015 INFO Starting unattended upgrades script
2026-02-04 06:44:35,016 INFO Allowed origins are: o=Ubuntu,a=noble, o=Ubuntu,a=noble-security, o=UbuntuESMApps,a=noble-apps-security, o=UbuntuESM,a=noble-infra-security
2026-02-04 06:44:35,016 INFO Initial blacklist:
2026-02-04 06:44:35,016 INFO Initial whitelist (not strict):
2026-02-04 06:44:37,465 INFO Packages that will be upgraded: libc-bin libc-dev-bin libc-devtools libc6 libc6-dev locales
2026-02-04 06:44:37,465 INFO Writing dpkg log to /var/log/unattended-upgrades/unattended-upgrades-dpkg.log
2026-02-04 06:45:01,458 INFO All upgrades installed
Although the MySQL server restart completes in approximately seventeen seconds, this is not acceptable for a production system with a large number of users. Such unexpected restarts can result in errors and denial of service.
The reason for such unexpected behavior is the unattended-upgrades package that is installed by default in Ubuntu 24.04. While updates are a valuable part of keeping systems secure and up to date, production systems require predictable maintenance schedules. They should be maintained during previously announced maintenance windows, not randomly. To improve system stability and predictability, the unattended-upgrades package should be disabled and preferably removed to prevent it from being suddenly enabled later.
First, check if the service is running:
sudo systemctl status unattended-upgrades
The output shows that the service is active and running:
● unattended-upgrades.service - Unattended Upgrades Shutdown
Loaded: loaded (/usr/lib/systemd/system/unattended-upgrades.service; enabled; preset: enabled)
Active: active (running) since Sat 2026-01-03 22:56:39 UTC; 1 month 1 day ago
Docs: man:unattended-upgrade(8)
Main PID: 744 (unattended-upgr)
Tasks: 2 (limit: 19140)
Memory: 10.8M (peak: 11.3M)
CPU: 82ms
CGroup: /system.slice/unattended-upgrades.service
└─744 /usr/bin/python3 /usr/share/unattended-upgrades/unattended-upgrade-shutdown --wait-for-signal
Stop the service first. The command produces no output:
sudo systemctl stop unattended-upgrades
Next, disable the service:
sudo systemctl disable unattended-upgrades
The output shows confirmation messages:
Synchronizing state of unattended-upgrades.service with SysV service script with /usr/lib/systemd/systemd-sysv-install.
Executing: /usr/lib/systemd/systemd-sysv-install disable unattended-upgrades
Removed "/etc/systemd/system/multi-user.target.wants/unattended-upgrades.service".
Finally, remove the package:
sudo apt remove --purge unattended-upgrades
The output shows the removal process:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages will be REMOVED:
unattended-upgrades*
0 upgraded, 0 newly installed, 1 to remove and 28 not upgraded.
After this operation, 422 kB disk space will be freed.
Do you want to continue? [Y/n] y
(Reading database ... 75236 files and directories currently installed.)
Removing unattended-upgrades (2.9.1+nmu4ubuntu1) ...
Processing triggers for man-db (2.12.0-4build2) ...
(Reading database ... 75209 files and directories currently installed.)
Purging configuration files for unattended-upgrades (2.9.1+nmu4ubuntu1) ...
dpkg: warning: while removing unattended-upgrades, directory '/var/log/unattended-upgrades' not empty so not removed
This warning indicates that /var/log/unattended-upgrades is not empty.
If those logs are not needed, they can be removed together with the directory:
sudo rm -rf /var/log/unattended-upgrades
Optionally, run autoremove to clean up unused packages:
sudo apt autoremove
In this case, it does not perform any actions:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
0 upgraded, 0 newly installed, 0 to remove and 28 not upgraded.
Optionally, run autoclean to remove cached package files:
sudo apt autoclean
The output shows that one package was deleted:
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Del python3-urllib3 2.0.7-1ubuntu0.5 [95.1 kB]
To verify that unattended-upgrades was removed and won’t bring any further surprises, check that the service is absent:
sudo systemctl status unattended-upgrades
The output should show an error message:
Unit unattended-upgrades.service could not be found.
Also verify that the package is removed by checking the package list. The command should produce no output, confirming the package has been removed:
sudo dpkg -l | grep unattended-upgrades
This article identified issues with random restarts of the MySQL server and showed how to identify their source in the unattended-upgrades package. It also described the procedure for removing the package to prevent such issues in the future.