DEV Community

Cover image for Install MariaDB 10.4 on an Ubuntu 22.04 server
Anish Ghimire
Anish Ghimire

Posted on • Originally published at cleavr.io

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. 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
Enter fullscreen mode Exit fullscreen mode

MySQL Add 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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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

Create a symlink to point to MySQL

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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/
Enter fullscreen mode Exit fullscreen mode
cat > /etc/systemd/system/mariadb.service.d/datadir.conf <<EOF
[Service]
ReadWritePaths=/usr/local/mysql/data
EOF
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

Check MariaDB status

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

systemctl status mariadb
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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

This blog was originally posted on Cleavr Slice

Top comments (2)

Collapse
 
thankyouman profile image
Sam

Thank you man!

This does actually work.

I don't get why the "how to" section in mariadb.org is so sloppy.

Yet, this here is premium service.

Collapse
 
thankyouman profile image
Sam

...For other installer: When finished, you might have to install a legacy library with the following commands:

sudo apt update
sudo apt search libncurses5
sudo apt install libncurses5