MariaDB on Ubuntu mysteriously goes away after 15 minutes

All we need is an easy explanation of the problem, so here it is.

I have an issue I’ve never seen before…my MariaDB goes away after 1800 seconds, despite having the default configuration for wait_timeout of 28800 seconds.

I checked all my my.cnf files, and there was no specific configuration for wait_timeout.

MariaDB [andrew]> SHOW VARIABLES LIKE 'wait_%';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| wait_timeout  | 28800 |
+---------------+-------+
1 row in set (0.005 sec)

I also added it explicitly and restarted and there was no change.

Here is what I am consistently experiencing after 15 minutes:

MariaDB [andrew]> select * from images where file_name like '%test%';
ERROR 2006 (HY000): MySQL server has gone away
No connection. Trying to reconnect...
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)
ERROR: Can't connect to the server

When I run sudo service mysql status at the CLI I get:

โ— mariadb.service - MariaDB 10.3.30 database server
     Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
     Active: failed (Result: timeout) since Thu 2021-08-05 13:03:52 UTC; 5min ago
       Docs: man:mysqld(8)
             https://mariadb.com/kb/en/library/systemd/
    Process: 27498 ExecStartPre=/usr/bin/install -m 755 -o mysql -g root -d /var/run/mysqld (code=exited, status=0/SUCCESS)
    Process: 27505 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
    Process: 27512 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= ||   VAR=`cd /usr/bin/..; /usr/bin/galera_recovery`; [ $? -eq 0 ]   && systemctl set-environment >
    Process: 27561 ExecStart=/usr/sbin/mysqld $MYSQLD_OPTS $_WSREP_NEW_CLUSTER $_WSREP_START_POSITION (code=exited, status=0/SUCCESS)
   Main PID: 27561 (code=exited, status=0/SUCCESS)

Aug 05 12:48:50 andrew systemd[1]: Starting MariaDB 10.3.30 database server...
Aug 05 12:48:50 andrew mysqld[27561]: 2021-08-05 12:48:50 0 [Note] /usr/sbin/mysqld (mysqld 10.3.30-MariaDB-0ubuntu0.20.04.1) starting as process 27561 ...
Aug 05 13:03:50 andrew systemd[1]: mariadb.service: start operation timed out. Terminating.
Aug 05 13:03:52 andrew systemd[1]: mariadb.service: Failed with result 'timeout'.
Aug 05 13:03:52 andrew systemd[1]: Failed to start MariaDB 10.3.30 database server.

Stack is Ubuntu 20.04.2 LTS, PHP 7.4.3 (cli), 10.3.30-MariaDB-0ubuntu0.20.04.1. No web server.

Does anyone know why this is happening? Thanks ๐Ÿ™

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

Turns out that I had previously installed MySQL (as opposed to Maria) on this machine, and AppArmor was interfering.

I googled mariadb.service: start operation timed out. Terminating. and found this SO article:

https://stackoverflow.com/questions/40997257/mysql-service-fails-to-start-hangs-up-timeout-ubuntu-mariadb

…this solved it.

Note: Use and implement method 1 because this method fully tested our system.
Thank you ๐Ÿ™‚

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply