<-- Back to The Cleavr Slice

06 April 2023



Install MariaDB 10.4 on an Ubuntu 22.04 server

In this blog, we’ll show you how to install MariaDB 10.4 on Ubuntu 22.04 servers.

We ran into some issues with MariaDB 10.4 installations on Ubuntu 22.04 servers. The MariaDB team stopped producing the deb package of MariaDB 10.04 for Ubuntu 22.04 servers. In Cleavr, we always want our users to have a better experience, so we planned to implement an alternate installation to either downgrade the versions of some security-related packages or a straightforward installation which takes almost 25-30 minutes 😬.

However, We didn’t want to compromise installations nor to take so much of users time. So we decided not to support MariaDB 10.4 moving forward.

However, if you still need to install MariaDB 10.4 on your Ubuntu 22.04 server, we’ll show you how you can do this using [MariaDB Binary Tarballs](https://mariadb.com/kb/en/installing-mariadb-binary-tarballs/. If you want to download any other unsupported versions of MariaDB, you can still follow this blog.

Here’s a summary of what we will be doing throughout this blog:

SSH into the server

As a first step, SSH into the server as a root user and add create a mysql user so that we can install MariaDB under the user and group mysql.

Create system user and group

Run the following command to create a new group and user called mysql:

groupadd mysql

useradd -g mysql

Create mysql user

Download MariaDB binary tarballs

Now, we'll change our directory to /usr/local with cd /usr/local. This is the default directory where MariaDB is installed. So we’ll be downloading the binary tarballs in this directory. To download the tar file run the following wget command:

wget https://mirrors.aliyun.com/mariadb//mariadb-10.4.28/bintar-linux-systemd-x86_64/mariadb-10.4.28-linux-systemd-x86_64.tar.gz

If you’re following this blog and intending to download 10.3, or any other versions, just replace the version number and run the command.

For example, if you want to install MariaDB 10.3.38 the command will be:

wget https://mirrors.aliyun.com/mariadb//mariadb-10.3.38/bintar-linux-systemd-x86_64/mariadb-10.4.28-linux-systemd-x86_64.tar.gz

Download MariaDB Tarball

The download may take around 25-30 minutes to complete depending on your internet connection.

Extract the archive

Once the file is downloaded, extract the files using the tar command.

tar -zxvpf mariadb-10.4.28-linux-systemd-x86_64.tar.gz

Let's rename the extracted file to mariadb10.4 for convenience.

mv mariadb-10.4.28-linux-systemd-x86_64 mariadb10.4

Now let's create a symlink of the mariadb10.4 and point to mysql. /usr/local/mysql is the default location for MariaDB though it may be different in some platforms. Creating the symlink will also help you if you decide to change the MariaDB version.

ln -s /usr/local/mariadb10.4 mysql

Initialize the MariaDB data directory

We need to initialize the MariaDB data directory and create the system tables. Run the following command to change the directory to mysql, initialize the MariaDB data directory, and create the system tables:

cd mysql && ./scripts/mysql_install_db --user=mysql

Initialize MariaDB Data Directory

Fix ownership

We need to fix the ownership of our new files. Run the following chown commands:

chown -R root .

chown -R mysql data

Export path to include mysql binary

We’ll now export the path where mysql exists by updating the .bashrc file. We’ll then be able to test the connection by invoking clients such as mysql.

Run the following command to add the export path to .bashrc file:

echo "export PATH=$PATH:/usr/local/mysql/bin/" >> ~/.bashrc

Run source ~/.bashrc so that you don’t have to restart your shell to reflect the new changes.

Configure MariaDB server

You can configure mysqld (the MariaDB server) by copying the mysql.server file to the right place.

cp support-files/mysql.server /etc/init.d/mysql.server

Next, we need to copy the mariadb.service file to its proper place.

cp support-files/systemd/mariadb.service /usr/lib/systemd/system/mariadb.service

Configure data directory

By default the /usr/ directory is write protected by systemd, so let's make our data directory writable.

mkdir /etc/systemd/system/mariadb.service.d/
cat > /etc/systemd/system/mariadb.service.d/datadir.conf <<EOF

Once you run the above command reload the systemd manager configuration by running systemctl daemon-reload command.

Start MariaDB service

Finally, we can start the MariaDB service using:

systemctl start mariadb.service

Check MariaDB status

Let's verify our installation by checking the status of MariaDB by running:

systemctl status mariadb

MariaDB Status

Enable MariaDB service

If you want MariaDB to start automatically when you boot up your device enable the service by running:

systemctl enable mariadb.service

That’s all for this blog. I hope it helps you with MariaDB 10.4 installation on your Ubuntu 22.04 server.

Take control of your servers and deployments.Without breaking a sweat.

Sign up for a 5-day free trial of Cleavr Pro. No credit card required until you decide to subscribe.

Sign up for free