The Startup
Published in

The Startup

Build MariaDB 10.5 on Raspberry Pi

MariaDB is advertised as being one of the most popular open source relational databases valuing “performance, stability, and openness”. This is why it’s the default MySQL variant for Debian and as a result it’s often viewed as the relational database of choice for the Raspberry Pi .

The latest version of the Raspberry Pi OS runs Debian 10 (Buster) which offers MariaDB 10.3 with a simple install. However, this was released three years ago, meaning you are missing out on three years worth of new features and improvements. An example of some of those improvements include:

The Raspberry Pi runs on the ARMHF architecture but there are currently no official MariaDB downloads available for this architecture. This means you will need to build MariaDB from source if you wish to gain access to the latest version.

Unfortunately the official documentation only provides a general guide for Debian users and assumes the MariaDB version you are building is already available from your repository. On top of that the MariaDB source code needs to be patched before it will compile on the the Raspberry Pi.

At the time of writing this guide builds MariaDB 10.5.9 on Raspberry Pi OS (Buster) with Linux Kernel 5.10.16.

Before continuing make sure your Raspberry Pi OS is up to date:

sudo apt-get update
sudo apt-get upgrade
sudo apt-get dist-upgrade

If you run into problems further down the line you can try updating the firmware but it is generally not needed unless for specific reasons:

sudo rpi-update

If your Raspberry Pi is limited to 1GB of RAM then you will need to increase the Swap memory to a minimum of 1GB. I ran the entire build process on a freshly installed Raspberry Pi OS (32-bit) Lite edition which used 90% of the allocated 1GB of Swap memory. You might need to increase this further if you are already consuming more RAM.

You can see how much memory you have by running the free -h command:

As you can see my total amount of RAM and Swap memory is 924MB and 99MB respectively. To increase the Swap memory to 1024MB (1GB) simply edit /etc/dphys-swapfile and modify the CONF_SWAPSIZE variable to:


Then restart the Swap file service:

sudo /etc/init.d/dphys-swapfile restart

You can run free -h again to confirm the changes were made successfully.

Now that the Raspberry Pi is up to date with enough memory go ahead and install devscripts. This package contains a bunch of packages and scripts that will help with the build process:

sudo apt-get install devscripts

Create a mariadb folder within the home directory and change to it’s directory so we can work within it:

mkdir ~/mariadb && cd ~/mariadb

Now go ahead and download version 10.5 (--branch 10.5) of the MariaDB source code and its submodules (--recursive) but without any of its previous commits (--depth 1) then move into the newly created server folder:

git clone --recursive --depth 1 --branch 10.5
cd server

Please note: The source code must be downloaded using Git and not as a ZIP file from GitHub as the ZIP file doesn’t include any of the submodules.

Due to a bug in GCC the source code needs to be patched to manually link the atomic library. This patch is currently in review so you need to apply it yourself. To do this we download the official patch file and apply it using the patch command:

patch -p1 < c11_atomics.patch

We now need to install the packages used to build MariaDB. These packages are listed within a control file and can be installed using the mk-build-deps command that will remove the packages once installed (--remove) to keep things tidy:

sudo mk-build-deps debian/control --install --remove

To start the build process simply run the script which follows the same build process used in the official release:


Please note: It took my Raspberry Pi 4 hours and 45 minutes to complete this process.

MariaDB Galera Cluster is a virtually synchronous multi-master cluster for MariaDB and since MariaDB 10.1 the Galera packages and their dependencies get installed when installing MariaDB. Even if Galera remains unused it is still required as part of the MariaDB installation.

This means we need to build Galera 4 so lets get our hands on the source code by downloading the mariadb-4.x branch from GitHub then move into the newly created galera folder:

cd ~/mariadb
git clone --recursive --depth 1 --branch mariadb-4.x
cd galera

We can then install the packages required for the build process just like we did for MariaDB:

sudo mk-build-deps debian/control --install --remove

The same GCC bug also affects Galera (26.4.7) which requires a patch before it can be compiled on the Raspberry Pi. The patch was developed by a contributor of the Galera project which I have repackaged so it can be easily applied by running the following commands:

patch -p1 < galera_atomic.patch

The patch should already be applied in newer releases after version 26.4.7 allowing you to skip the previous step. However, if you still come across compilation errors in the next step try applying the above patch.

You can see the current version by running cat GALERA_VERSION which should show something similar to this:


Then to start the build process simply run the file with the -p switch to build the deb packages. I also set the number of threads to one (-j 1) since I ran into some system crashes while trying to compile it on multiple threads:

./scripts/ -p -j 1

Please note: The build process took 1 hour 50 minutes.

In order to install the newly created deb files we need to move them all to a local repository:

mkdir -p /usr/local/repo/binary
mv ~/mariadb/*.deb /usr/local/repo/binary
cd /usr/local/repo
dpkg-scanpackages binary /dev/null | gzip -9c > binary/Packages.gz

We then add this repository to the list of APT repositories followed by an APT update:

sudo su -c "echo 'deb [trusted=yes] file:///usr/local/repo binary/' > /etc/apt/sources.list.d/mariadb.list"
sudo apt-get update

With that all done we can now see that version 10.5.9 is now available:

apt show mariadb-server

Package: mariadb-server
Version: 1:10.5.9+maria~buster

Now go ahead and install MariaDB:

sudo apt install mariadb-server

Make any edits to the /etc/mysql/mariadb.conf.d/50-server.cnf configuration file then restart the service with:

sudo systemctl restart mariadb

Finally secure the installation by running the secure script:

sudo mysql_secure_installation



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store