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.
wget http://mirrors.opencas.cn/mariadb//mariadb-10.1.12/source/mariadb-10.1.12.tar.gz
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
Begin the compilation process with make command.
make
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.
PATH=$PATH:/usr/local/mysql/bin
Also root user’s PATH.
su PATH=$PATH:/usr/local/mysql/bin
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.
[Unit] Description=MariaDB database server After=network.target After=syslog.target [Service] Type=simple PrivateNetwork=false User=mysql Group=mysql CapabilityBoundingSet=CAP_IPC_LOCK PermissionsStartOnly=true 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 Restart=on-abort RestartSec=5s UMask=007 PrivateTmp=false LimitNOFILE=16364 [Install] WantedBy=multi-user.target Alias=mysql.service Alias=mysqld.service
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
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.
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 https://gist.githubusercontent.com/Lewiscowles1986/27cfeda001bb75a9151b5c974c2318bc/raw/cbaf69aef3c93b4ef85ce732e5c0bb670591ebe5/rPi3-mariadb-10.1.sh
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)…
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 ?