systemd is an init replacement that MariaDB uses on releases since 10.1.8. Distribution packages before this version may use a different configuration so consult their documentation if required.

systemd services are packaged on RPM and Debian based Linux distributions. When systemd is used, mysqld_safe is not used and settings in the mysqld_safe section of configuration files will not be read or applied.

systemd Overview

systemd service files are included in the MariaDB-server package. The service definition is installed in /usr/lib/systemd/system/mariadb.service. The service name is mariadb.service; however aliases to mysql.service and mysqld.service are included for convenience.

Unlike previous init scripts, the mysqld process is executed directly from the init script running as the mysql user. This places a couple of limitations on situations that were previously possible:

  • open-files-limit cannot be raised beyond the operating system limit (usually 1K) and hence the systemd configuration for mariadb has LimitNOFILE set to 16K by default;
  • memlock can be used from version 10.1.10; and
  • The start timeout from init scripts was quite large and special configuration may be required if there is a slow startup time (MDEV-9202).

Interacting with the MariaDB Server Process

The service can be interacted with by using the systemctl command.

Starting the MariaDB Server Process on Boot

systemctl enable mariadb

Starting the MariaDB Server Process

systemctl start mariadb

Stopping the MariaDB Server Process

systemctl stop mariadb

Checking the Status of the MariaDB Server Process

systemctl status mariadb

Interacting with Multiple MariaDB Server Processes

/usr/lib/systemd/system/mariadb@.service is installed on some systems. This service file allows you to interact with multiple instances of MariaDB on the same hardware. When you interact with a server process with this service file, you have to provide an instance name as a suffix. The configuration for that instance is found by looking for /etc/my.cnf.d/my%I.cnf where the %I is the instance name.

For example, if you executed the following:

systemctl start mariadb@node1

Then this would start a MariaDB Server process using the configuration file /etc/my.cnf.d/mynode1.cnf. The instance name, node1, is substituted in /etc/my.cnf.d/my%I.cnf where the %I is.

See mysqld_install_db for information on how to initialize the datadir for additional instances.

Systemd and Galera Cluster

Bootstrapping a New Cluster

When using Galera Cluster with systemd, the first node in a cluster has to be started with galera_new_cluster. See Getting Started with MariaDB Galera Cluster: Bootstrapping a New Cluster for more information.

Recovering a Node's Cluster Position

When using Galera Cluster with systemd, a node's position in the cluster can be recovered with galera_recovery. See Getting Started with MariaDB Galera Cluster: Determining the Most Advanced Node for more information.

SSTs and Systemd

MariaDB's systemd unit file has a fairly low timeout value by default. If your SST takes longer than about 2 minutes, this low default timeout can cause systemd to assume that mysqld startup has failed, which causes it to kill the mysqld process. See Introduction to State Snapshot Transfers (SSTs): SSTs and Systemd for more information.


If there are some systemd settings to override or to set, create a file /etc/systemd/system/mariadb.service.d/XXXX.conf file where XXXX is something meaningful to you and place the configuration option(s) in an appropriate section, usually [Service]. If a systemd option is a list you may need to set this to empty before you set the replacement values, e.g.:


ExecStart=/usr/bin/numactl --interleave=all  /usr/sbin/mysqld ${MYSQLD_OPTS} ${_WSREP_NEW_CLUSTER} ${_WSREP_START_POSITION}

After any configuration change systemctl daemon-reload will be required to pick up the changes.

A mapping of common mysqld_safe options to systemd options is provided below.

mysqld_safe optionsystemd optionComments
no optionProtectHome=falseIf any MariaDB files are in /home/
no optionPrivateDevices=falseIf any MariaDB storage references raw block devices
no optionProtectSystem=If any MariaDB write any files to anywhere under /boot, /usr or /etc
no optionTimeoutStartSec={time}Set if the systemd reports failure to start because of timeout. 0 disables any timeout
no option (ref MDEV-9264)OOMScoreAdjust={priority}e.g. -600 to lower priority of OOM killer for mysqld
LimitMEMLOCK={size} or infinityWhen large-pages or memlock is used
niceNice={nice value}
ExecStartPre=/usr/sbin/sysctl -q -w vm.drop_caches=3
numa-interleaveExecStart=/usr/bin/numactl --interleave=all /usr/sbin/mysqld ${MYSQLD_OPTS} ${_WSREP_NEW_CLUSTER} ${_WSREP_START_POSITION}

Note: systemd.service contains the official meanings for these systemd settings.

There are other options and the mariadb-service-convert script will attempt to convert these as accurately as possible.

In addition to the set of options previously provided by mysqld_safe, systemd.service has considerably more options.


systemd has its own logging system called the systemd journal. Logs that might have been found before in the default error log file or in syslog may instead be logged by systemd.

To read all the MariaDB server logs, use the following command: journalctl -u mariadb


mariadb-service-convert is a script included in the distribution. It is used by the package manager to read any explicit settings in the mysqld_safe section on the configuration file and its output can be directed to /etc/systemd/system/mariadb.service.d/migrated-from-my.cnf-settings.conf to keep the configuration the same. Implicitly high defaults of open-file-limit may be missed by the conversion script and require explicit configuration.


Comments loading...