Starting and Stopping MariaDB Automatically

You are viewing an old version of this article. View the current version here.

Need additional support? We're here to help!

  Contact Us

When running MariaDB in a server environment it is almost always desirable to have MariaDB start automatically when the server is powered on, for it to stay running while the server is running, and for it to be shutdown gracefully when the server is shut down.

The actual MariaDB server binary is called mysqld. Like other MariaDB binaries, it is so named to preserve compatibility with upstream MySQL.

You have the option of starting the mysqld server several different ways:

  1. Run or invoke mysqld itself. An example of doing this is described more in Running MariaDB from the Source Directory.
  2. Use the mysqld_safe startup script
  3. Use the mysql.server startup script

The mysql.server script starts mysqld by first changing to the MariaDB install directory and then calling mysqld_safe. Adding an appropriate user line to the [mysqld] group in your my.cnf file will cause the server to be run as that user.

If you have installed MariaDB to a non-standard location, you may need to edit the mysql.server script to get it to work right.

mysql.server works as a standard SysV-style init script. As such you use the script with start and stop arguments like so:

mysql.server start
mysql.server stop

To configure MariaDB to start and stop automatically on Linux using the mysql.server script you need to add it to your distribution's init system, usually by copying it to /etc/init.d/ and then creating specially named symlinks in the appropriate /etc/rcX.d/ directories (where 'X' is a number between 0 and 6).

In the examples below we will follow the historical convention of renaming the mysql.server script to 'mysql' when we copy it to /etc/init.d/.

The first step for most Linux distributions is to copy the mysql.server script to /etc/init.d/ and make it executable:

cd /path/to/your/mariadb-version/support-files/
cp mysql.server /etc/init.d/mysql
chmod +x /etc/init.d/mysql

Now all that is needed is to create the specially-named symlinks. On both RPM and Debian-based Linux distributions there are tools which do this for you. Consult your distribution's documentation if neither of these work for you and follow their instructions for generating the symlinks or creating them manually.

On RPM-based distributions (like Fedora and CentOS), you use chkconfig:

chkconfig --add mysql
chkconfig --level 345 mysql on

On Debian-based distributions you use update-rc.d:

update-rc.d mysql defaults

On FreeBSD, the location for startup scripts is /usr/local/etc/rc.d/ and when you copy the mysql.server script there you should rename it so that it matches the *.sh pattern, like so:

cd /path/to/your/mariadb/support-files/
cp mysql.server /usr/local/etc/rc.d/mysql.server.sh

As stated above, consult your distribution's documentation for more information on starting services like MariaDB at system startup.

See mysqld startup options for information on configuration options for mysqld.

Comments

Comments loading...
Content reproduced on this site is the property of its respective owners, and this content is not reviewed in advance by MariaDB. The views, information and opinions expressed by this content do not necessarily represent those of MariaDB or any other party.