Databases 22 min read

One‑Click MariaDB Binary Installation Across Major Linux Distros

This guide walks you through installing MariaDB from binary packages on various Linux distributions, covering user and group creation, downloading and extracting the tarball, configuring environment variables and my.cnf, initializing the database, securing the installation, testing the server, and using a ready-made shell script for automated deployment.

Raymond Ops
Raymond Ops
Raymond Ops
One‑Click MariaDB Binary Installation Across Major Linux Distros

2.3 Binary Installation of MariaDB

2.3.1 Users and Groups

# Rocky, AlmaLinux, CentOS, openEuler, AnolisOS, OpenCloudOS, Kylin Server, UOS Server, Ubuntu, Debian
useradd -r -s /sbin/nologin -d /data/mariadb mysql

# openSUSE
groupadd -r mysql
useradd -s /sbin/nologin -d /data/mariadb -r -g mysql mysql

2.3.2 Prepare Program Files

Download the MariaDB binary package from https://mariadb.org , select the desired version (e.g., 11.8.2), operating system (Linux), architecture (x86_64), init system (systemd), and a mirror such as Tsinghua University TUNA, then click “Download”.

MariaDB homepage
MariaDB homepage

After selecting the options, the download page appears.

MariaDB binary download page
MariaDB binary download page
# Install wget if missing
yum install -y wget

# Install tar if missing on certain distros
yum install -y tar

# Download and extract the binary package
wget https://mirrors.tuna.tsinghua.edu.cn/mariadb///mariadb-11.8.3/bintar-linux-systemd-x86_64/mariadb-11.8.3-linux-systemd-x86_64.tar.gz
tar xf mariadb-11.8.3-linux-systemd-x86_64.tar.gz -C /usr/local
ln -s /usr/local/mariadb-11.8.3-linux-systemd-x86_64/ /usr/local/mysql

2.3.3 Prepare Environment Variables

echo 'PATH=/usr/local/mysql/bin/:$PATH' > /etc/profile.d/mariadb.sh
. /etc/profile.d/mariadb.sh

2.3.4 Prepare Configuration File

cat > /etc/my.cnf <<-EOF
[mariadb]
datadir=/data/mariadb
socket=/data/mariadb/mariadb.sock
log-error=/data/mariadb/mariadb.log
pid-file=/data/mariadb/mariadb.pid

[client]
socket=/data/mariadb/mariadb.sock
EOF

2.3.5 Generate Database Files

mkdir -p /data/mariadb
chown -R mysql:mysql /data/mariadb

# Initialize the database (example for Rocky 10)
cd /usr/local/mysql
./scripts/mariadb-install-db --datadir=/data/mariadb/ --user=mysql

Install libxcrypt-compat on Rocky 10, AlmaLinux 10, and CentOS 10 if required, then start the server and verify the version.

2.3.6 Prepare Service Script and Start

# Copy systemd service file
cp /usr/local/mysql/support-files/systemd/mariadb.service /usr/lib/systemd/system/
systemctl daemon-reload && systemctl enable --now mariadb

2.3.7 Secure Initialization

# Create symlink for socket
ln -s /data/mariadb/mariadb.sock /tmp/mysql.sock

# Run secure installation
/usr/local/mysql/bin/mariadb-secure-installation <<EOF
y
n
y
y
y
y
EOF

2.3.8 Test Login

mariadb
SHOW DATABASES;
SELECT user,host FROM mysql.user;

2.3.9 One‑Click Installation Script

The following shell script automates the entire process for supported distributions (Rocky, AlmaLinux, CentOS, openEuler, Anolis, OpenCloudOS, Kylin, UOS, openSUSE, Ubuntu, Debian). It detects the OS, downloads the appropriate MariaDB binary, creates the mysql user, extracts files, configures the server, enables the service, and runs the secure installation.

#!/bin/bash
#**********************************************************************************
# Author: Raymond
# Date: 2025-09-10
# Description: The mariadb binary script install supports "Rocky Linux 8, 9 and 10, Almalinux 8, 9 and 10, CentOS 7, CentOS Stream 8, 9 and 10, openEuler 22.03 and 24.03 LTS, AnolisOS 8 and 23, OpencloudOS 8 and 9, Kylin Server v10, UOS Server v20, Ubuntu Server 18.04, 20.04, 22.04 and 24.04 LTS, Debian 11 , 12 and 13, openSUSE 15" operating systems.
#**********************************************************************************
COLOR="echo -e \\033[01;31m"
END='\\033[0m'

os(){
    . /etc/os-release
    MAIN_NAME=$(sed -rn 's/^NAME="?([A-Za-z]+).*"?$/\1/p' /etc/os-release)
    if [ "$MAIN_NAME" == "Kylin" ]; then
        MAIN_VERSION_ID=$(sed -rn 's/^VERSION_ID="?([A-Za-z]+)(.*)"?$/\2/p' /etc/os-release)
    else
        MAIN_VERSION_ID=$(sed -rn 's/^VERSION_ID="?([0-9]+).*"?$/\1/p' /etc/os-release)
    fi
    if [[ "$MAIN_NAME" == "Ubuntu" || "$MAIN_NAME" == "Debian" ]]; then
        FULL_NAME="$PRETTY_NAME"
    elif [ "$MAIN_NAME" == "UOS" ]; then
        FULL_NAME="$NAME"
    else
        FULL_NAME="$NAME$VERSION_ID"
    fi
}
os
DATA_DIR=/data/mariadb

# Determine MariaDB version
if [ "$MAIN_NAME" == "CentOS" && "$MAIN_VERSION_ID" == 7 ]; then
    MARIADB_VERSION=11.4.8
else
    MARIADB_VERSION=11.8.3
fi
MARIADB_URL="https://mirrors.tuna.tsinghua.edu.cn/mariadb///mariadb-${MARIADB_VERSION}/bintar-linux-systemd-x86_64/"
MARIADB_FILE="mariadb-${MARIADB_VERSION}-linux-systemd-x86_64.tar.gz"

check_file(){
    if [[ "$MAIN_NAME" == "Rocky" || "$MAIN_NAME" == "AlmaLinux" || "$MAIN_NAME" == "CentOS" || "$MAIN_NAME" == "Anolis" || "$MAIN_NAME" == "OpenCloudOS" || "$MAIN_NAME" == "Kylin" ]]; then
        rpm -q wget &>/dev/null || { $COLOR "Installing wget tool, please wait..." $END; yum install -y wget &>/dev/null; }
    fi
    if [ ! -e "$MARIADB_FILE" ]; then
        $COLOR "Missing $MARIADB_FILE. Starting download..." $END
        wget "${MARIADB_URL}${MARIADB_FILE}" || { $COLOR "Failed to download MariaDB binary package." $END; exit 1; }
    else
        $COLOR "$MARIADB_FILE is ready." $END
    fi
}

install_mariadb(){
    [ -d /usr/local/mysql ] && { $COLOR "MariaDB already exists, installation aborted!" $END; exit 1; }
    $COLOR "Starting MariaDB installation..." $END
    if [ "$MAIN_NAME" == "openSUSE" ]; then
        id mysql &>/dev/null || { groupadd -r mysql && useradd -s /sbin/nologin -d $DATA_DIR -r -g mysql mysql; $COLOR "Created mysql user!" $END; }
    else
        id mysql &>/dev/null || { useradd -r -s /sbin/nologin -d $DATA_DIR mysql; $COLOR "Created mysql user!" $END; }
    fi
    if [ "$MAIN_NAME" == "openEuler" ]; then
        if [[ "$MAIN_VERSION_ID" == 22 || "$MAIN_VERSION_ID" == 24 ]]; then
            yum install -y tar &>/dev/null
        fi
    fi
    if [ "$MAIN_NAME" == "Anolis" ]; then
        if [ "$MAIN_VERSION_ID" == 23 ]; then
            yum install -y tar &>/dev/null
        fi
    fi
    if [ "$MAIN_NAME" == "OpenCloudOS" ]; then
        if [ "$MAIN_VERSION_ID" == 9 ]; then
            yum install -y tar &>/dev/null
        fi
    fi
    tar xf $MARIADB_FILE -C /usr/local
    MARIADB_DIR=$(echo $MARIADB_FILE | sed -nr 's/^(.*[0-9]).*/\1/p')
    ln -s /usr/local/$MARIADB_DIR /usr/local/mysql
    chown -R mysql:mysql /usr/local/mysql
    echo 'PATH=/usr/local/mysql/bin/:$PATH' > /etc/profile.d/mariadb.sh
    . /etc/profile.d/mariadb.sh
    cat > /etc/my.cnf <<-EOF
[mariadb]
datadir=$DATA_DIR
socket=$DATA_DIR/mariadb.sock
log-error=$DATA_DIR/mariadb.log
pid-file=$DATA_DIR/mariadb.pid

[client]
socket=$DATA_DIR/mariadb.sock
EOF
    [ -d $DATA_DIR ] || mkdir -p $DATA_DIR
    chown -R mysql:mysql $DATA_DIR
    if [ "$MAIN_NAME" == "Rocky" ]; then
        if [ "$MAIN_VERSION_ID" == 10 ]; then
            yum install -y libxcrypt-compat &>/dev/null
        fi
    fi
    if [ "$MAIN_NAME" == "AlmaLinux" ]; then
        if [ "$MAIN_VERSION_ID" == 10 ]; then
            yum install -y libxcrypt-compat &>/dev/null
        fi
    fi
    if [ "$MAIN_NAME" == "CentOS" ]; then
        if [ "$MAIN_VERSION_ID" == 10 ]; then
            yum install -y libxcrypt-compat &>/dev/null
        fi
    fi
    cd /usr/local/mysql
    ./scripts/mysql_install_db --datadir=$DATA_DIR --user=mysql
    if [[ "$MAIN_NAME" == "Ubuntu" || "$MAIN_NAME" == "Debian" ]]; then
        cp /usr/local/mysql/support-files/systemd/mariadb.service /lib/systemd/system/
    else
        cp /usr/local/mysql/support-files/systemd/mariadb.service /usr/lib/systemd/system/
    fi
    systemctl daemon-reload && systemctl enable --now mariadb &>/dev/null
    [ $? -ne 0 ] && { $COLOR "Database start failed, exiting!" $END; exit 1; }
}

mariadb_secure(){
    ln -s $DATA_DIR/mariadb.sock /tmp/mysql.sock
    /usr/local/mysql/bin/mariadb-secure-installation <<EOF

y
n
y
y
y
y
EOF
    $COLOR "$FULL_NAME operating system, MariaDB installation completed!" $END
}

main(){
    check_file
    install_mariadb
    mariadb_secure
}

if [ "$MAIN_NAME" == "Rocky" ]; then
    if [[ "$MAIN_VERSION_ID" == 8 || "$MAIN_VERSION_ID" == 9 || "$MAIN_VERSION_ID" == 10 ]]; then
        main
    fi
elif [ "$MAIN_NAME" == "AlmaLinux" ]; then
    if [[ "$MAIN_VERSION_ID" == 8 || "$MAIN_VERSION_ID" == 9 || "$MAIN_VERSION_ID" == 10 ]]; then
        main
    fi
elif [ "$MAIN_NAME" == "CentOS" ]; then
    if [[ "$MAIN_VERSION_ID" == 7 || "$MAIN_VERSION_ID" == 8 || "$MAIN_VERSION_ID" == 9 || "$MAIN_VERSION_ID" == 10 ]]; then
        main
    fi
elif [ "$MAIN_NAME" == "openEuler" ]; then
    if [[ "$MAIN_VERSION_ID" == 22 || "$MAIN_VERSION_ID" == 24 ]]; then
        main
    fi
elif [ "$MAIN_NAME" == "Anolis" ]; then
    if [[ "$MAIN_VERSION_ID" == 8 || "$MAIN_VERSION_ID" == 23 ]]; then
        main
    fi
elif [ "$MAIN_NAME" == "OpenCloudOS" ]; then
    if [[ "$MAIN_VERSION_ID" == 8 || "$MAIN_VERSION_ID" == 9 ]]; then
        main
    fi
elif [ "$MAIN_NAME" == "Kylin" ]; then
    if [ "$MAIN_VERSION_ID" == 10 ]; then
        main
    fi
elif [ "$MAIN_NAME" == "UOS" ]; then
    if [ "$MAIN_VERSION_ID" == 20 ]; then
        main
    fi
elif [ "$MAIN_NAME" == "openSUSE" ]; then
    if [ "$MAIN_VERSION_ID" == 15 ]; then
        main
    fi
elif [ "$MAIN_NAME" == "Ubuntu" ]; then
    if [[ "$MAIN_VERSION_ID" == 18 || "$MAIN_VERSION_ID" == 20 || "$MAIN_VERSION_ID" == 22 || "$MAIN_VERSION_ID" == 24 ]]; then
        main
    fi
elif [ "$MAIN_NAME" == "Debian" ]; then
    if [[ "$MAIN_VERSION_ID" == 11 || "$MAIN_VERSION_ID" == 12 || "$MAIN_VERSION_ID" == 13 ]]; then
        main
    fi
else
    $COLOR "This script does not support $FULL_NAME operating system!" $END
fi
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

LinuxDatabase AdministrationMariaDBBinary Installation
Raymond Ops
Written by

Raymond Ops

Linux ops automation, cloud-native, Kubernetes, SRE, DevOps, Python, Golang and related tech discussions.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.