Mysql failes at boot - needs a delay

My Odroid-based server is up and running. But the reboot-test showed, that mariadb was started at a time when the database was not yet available. If I login as root and run systemctl start mysqld, mariadb starts without any failure and everything is fine.

The database is stored on the via USB connected harddisk and I think, that’s the problem.

How can I achive that mysqld starts some seconds later?


It looks like you are running mariadb under systemd.

  1. Find out the mount name of your USB-drive:
  • From the console as root type: “systemctl list-units --type=mount”
    The above command will list all available mounts of your system.

Let us assume your USB is mounted as “mnt-myusb.mount”

  1. Edit the systemd startup-script. With Debian/Ubuntu you will find it under /lib/systemd/system as mariadb.service or mysql.service
  • Under the container [Unit] you should see something like:
    Description=Mariadb Database Server


  • Append “mnt-myusb.mount” to “” like the following:
    Description=Mariadb Database Server mnt-myusb.mount


  1. Save the file and restart the server.

From now on mariadb should get started after the OS has mounted the USB-drive.

1 Like

That is not working …

systemctl list-units type mount:
media-Datenbanken.mount    loaded active mounted /media/Datenbanken

Edited startscript:

cat /lib/systemd/system/mariadb.service media-Datenbanken.mount

Output of systemctl status mariadb after reboot:

  Process: 1413 ExecStart=/usr/sbin/mysqld $MYSQLD_OPTS $_WSREP_NEW_CLUSTER $_WSREP_START_POSITION (code=exited, status=1/FAILURE)
  Process: 1052 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= ||   VAR=`/usr/bin/galera_recovery`; [ $? -eq 0 ]   && systemctl set-env
  Process: 1004 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
  Process: 943 ExecStartPre=/usr/bin/install -m 755 -o mysql -g root -d /var/run/mysqld (code=exited, status=0/SUCCESS)
 Main PID: 1413 (code=exited, status=1/FAILURE)
   Status: "MariaDB server is down"
Nov 30 11:00:09 Wolke7 systemd[1]: Starting MariaDB 10.1.37 database server...
Nov 30 11:00:10 Wolke7 mysqld[1413]: 2018-11-30 11:00:10 3063255040 [Note] /usr/sbin/mysqld (mysqld 10.1.37-MariaDB-0+deb9u1) starting as process 1413 ...
Nov 30 11:00:10 Wolke7 mysqld[1413]: 2018-11-30 11:00:10 3063255040 [Warning] Can't create test file /media/Datenbanken/ncdatabase/Wolke7.lower-test

And systemctl start mariadb gives nothing unusual, just an ordinary start …


You probably need to run

systemctl daemon-reload

before the changes to the unit file will be picked up. Then it should work as expected on reboot. If not, see if the answers at can help.

Does a reboot not reload?

This worked for me. Thanks Tamsy!