How to 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: 1 Average: 5]

3 Responses to “How to Compile MariaDB From Source on Raspbian Jessie

  • Lewis Cowles
    8 years ago

    Fantastic guide, I’ve used it to build from source the latest stable 10.1 using git instead of tar, and manually specifying packages instead of using build-dep. Very helpful guide, if you want to just sit-back and wait, you can use

    I’m unaware of how much disk space the process uses on your pi, but sadly mine takes up more space than a 4GB memory card provides, I use 8GB & 16GB without issue (I also use the latest raspbian)…

    • Xiao Guo-An (Admin)
      8 years ago

      I use a 8GB SD card for my pi without problem.

  • thanks for your tutorial, very helpful for me, but why service mariadb inactive after few second ?

Leave a Comment

  • Comments with links are moderated by admin before published.
  • Your email address will not be published.
  • Use <pre> ... </pre> HTML tag to quote the output from your terminal/console.
  • Please use the community ( for questions unrelated to this article.
  • I don't have time to answer every question. Making a donation would incentivize me to spend more time answering questions.

The maximum upload file size: 2 MB. You can upload: image. Links to YouTube, Facebook, Twitter and other services inserted in the comment text will be automatically embedded. Drop file here