Installing & Configuring Mariadb for Arch Linux

Tags: mariadb linux database arch


This website runs on a Digital Ocean Ubuntu VPS, and uses MySQL as it's backend database. I want to use my Arch Linux laptop to develop and test new code for the website so I need a database to use for the test environment. I could use Docker which would probably be the better option if I wanted to emulate the production database on this VPS as closely as possible but I've never used Mariadb so I want to give it a try.

Special Considerations

My laptop is setup with separate partitions for root, home, and swap with the home partition being the largest so I'm going to be configuring Mariadb to use a location on my home partition as the data directory.


Following along with the official Arch Linux docs on Mariadb, we install the mariadb package:

pacman -S mariadb

We need to set the datadir in /etc/my.cnf.d/server.cnf so we'll back up that file and make the change:

cp /etc/my.cnf.d/server.cnf /etc/my.cnf.d/server.cnf.bak
vi /etc/my.cnf.d/server.cnf
cp /etc/my.cnf.d/client.cnf /etc/my.cnf.d/client.cnf.bak
vi /etc/my.cnf.d/client.cnf

Now we can run the mariadb-install-db command:

sudo mariadb-install-db --user=myuser --basedir=/usr --datadir=/home/myuser/mariadb

Create an override for the mariadb systemd unit file and run it as my user with ProtectHome set to false:

sudo systemctl edit mariadb

Now we can run the service and if it's successful, we can enable it to start automatically.

sudo systemctl start mariadb
sudo systemctl enable mariadb