Skip to main content

How to Compile MariaDB From Source on Raspbian Jessie

compile mariadb from source on Raspbian Jessie

This tutorial explains how to compile MariaDB from source on Raspbian Jessie and how to use Systemd to manage MariaDB daemon. The latest stable version of MariaDB is 10.1.12.

Compile MariaDB From Source

Download the MariaDB source code from official MariaDB website or download it with wget. SSH into your Raspberrry Pi if you have a headless setup.


Extract the tarball.

tar xvf mariadb-10.1.12.tar.gz

Install build tools that are required for building MariaDB on Raspbian Jessie.

sudo apt-get build-dep mariadb-server

cd to the newly-created directory.

cd mariadb-10.1.12/

Use cmake to configure the build.

cmake . -DBUILD_CONFIG=mysql_release
 Compile MariaDB From Source on Raspbian Jessie

Begin the compilation process with make command.

 Compile MariaDB From Source on Raspbian Jessie

This compilation phase could take 6 hours on a low end Raspberry Pi.  So please be patient. Once it’s completed, install it onto your Raspberry Pi.

sudo make install

Things to Do Before Starting MariaDB

Create the mysql user.

sudo useradd -r mysql

Make the mysql user the owner of /usr/local/mysql. MariaDB is installed to this directory.

sudo chown -R mysql /usr/local/mysql/

Initializes the MariaDB data directory and creates the system and help tables with mysql_install_db. The MariaDB server, mysqld, needs to access the data directory when it runs later.

sudo /usr/local/mysql/scripts/mysql_install_db --user=mysql

Add /usr/local/mysql/bin to user pi’s PATH.


Also root user’s PATH.



Start the MariaDB daemon with:

sudo /usr/local/mysql/bin/mysqld_safe --datadir='/usr/local/mysql/data'

Set a password for the MariaDB root user.

sudo mysql_secure_installation

This command also gives you the option of removing the test databases and anonymous users created by default. It’s strongly recommended for production servers.

Create Systemd MariaDB Service File

sudo nano /etc/systemd/system/mariadb.service

Paste the following text into the file.

Description=MariaDB database server

ExecStart=/usr/local/mysql/bin/mysqld_safe --basedir=/usr/local/mysql --datadir=/usr/local/mysql/data
ExecReload=/bin/kill -s HUP $MAINPID
ExecStop=/bin/kill -s QUIT $MAINPID



Save and close the file. Kill the current running MariaDB daemon and start it again with systemctl.

sudo pkill mysqld
sudo systemctl start mariadb

Check status.

sudo systemctl status mariadb
 Compile MariaDB From Source on Raspbian Jessie

Enable auto-start when Raspberry Pi is powered on.

sudo systemctl enable mariadb

Congrats! You have successfully compiled MariaDB 10.1.12 and installed it on Raspbian Jessie. Also we created a mariadb.service file and can easily manage MariaDB daemon with Systemd.

Rate this tutorial
[Total: 0 Average: 0]