# How to install MariaDB on AlmaLinux 9

Installing MariaDB on AlmaLinux 9 takes just a few minutes. This guide walks you through the process, step by step:

1. Update AlmaLinux 9
2. Set up the repository
3. Install and start MariaDB
4. Secure the installation
5. Create a database and user account

## Why combine MariaDB with AlmaLinux 9?

[MariaDB](https://www.ionos.co.uk/digitalguide/server/know-how/what-is-mariadb/) is a widely used, high-performance open-source database. It is based on **MySQL** but includes additional features and is trusted in many enterprise environments. [AlmaLinux 9](https://www.ionos.co.uk/digitalguide/server/configuration/almalinux-what-does-the-new-linux-distribution-offer/) is a free, binary-compatible alternative to [RHEL](https://www.ionos.co.uk/digitalguide/server/know-how/rhel-red-hat-enterprise-linux/). Together, they are an excellent option for developers, small businesses and administrators looking for a stable, secure, license-free server platform.

## What requirements does my setup need to meet?

Before you begin, make sure your setup meets the following requirements:

- A system with AlmaLinux 9 pre-installed
- Root access or a user account with [sudo](https://www.ionos.co.uk/digitalguide/server/configuration/linux-sudo-command/) privileges
- Internet connection for package downloads
- Terminal access via console or [SSH](https://www.ionos.co.uk/help/hosting/setting-up-and-managing-ssh-accounts/what-is-ssh/ "What is SSH? – IONOS Help")

## How to install MariaDB on AlmaLinux 9

Here’s **how to install MariaDB on AlmaLinux 9**step by step. If you want to run MariaDB on a different distribution, such as [RHEL](https://www.ionos.co.uk/digitalguide/hosting/technical-matters/install-mariadb-rhel-9/) or [Ubuntu 24.04](https://www.ionos.co.uk/digitalguide/hosting/technical-matters/install-mariadb-ubuntu-2404/), we recommend looking at our other tutorials.

### Step 1: Update the system

Before installing new software, always make sure your system is up to date. This helps prevent version conflicts and strengthens security.

Open a terminal and run the following:

```bash
sudo dnf update -y
```

This command updates all installed packages to the latest version. If the kernel or core components are updated, restart the system:

```bash
sudo reboot
```

### Step 2: Set up the MariaDB repository

The MariaDB version included in the default AlmaLinux repositories might be outdated. To install the current stable release, configure the official AlmaLinux 9 MariaDB repository.

Create a new file:

```bash
sudo vi /etc/yum.repos.d/mariadb.repo
```

Insert the following content:

```bash
# MariaDB 11.7 AlmaLinux 9 Repository
[mariadb]
name = MariaDB
baseurl = https://mirror.23m.com/mariadb/yum/11.7/almalinux/$releasever/$basearch
module_hotfixes = 1
gpgkey = https://mirror.23m.com/mariadb/yum/RPM-GPG-KEY-MariaDB
gpgcheck = 1
```

Save the file and close with `:wq`. Then refresh the package sources so that the new repository is taken into account:

```bash
sudo dnf clean all
sudo dnf makecache
```

This ensures the package manager uses the latest information from the MariaDB repository.

### Step 3: Install MariaDB

Now install the database server with:

```bash
sudo dnf install mariadb-server -y
```

The system will download and install all required packages. The `-y` flag automatically confirms prompts in advance.

### Step 4: Start and enable the service

After the installation is complete, start the MariaDB service:

```bash
sudo systemctl start mariadb
```

Enable it so that it starts automatically when the system boots:

```bash
sudo systemctl enable mariadb
```

Check its status:

```bash
sudo systemctl status mariadb
```

The service should now be active and running. If so, you can move on to the configuration.

&lt;box-note&gt;

If [SELinux](https://www.ionos.co.uk/digitalguide/server/security/what-is-selinux/) is enabled (default in AlmaLinux 9), it might block external database connections. Allow network access by using the command `sudo setsebool -P mysqld_can_network_connect 1`. If you use your own data directory, set the correct context with `sudo semanage fcontext -a -t mysqld_db_t “/data/mysql(/.*)?”`. Then apply the rule with `sudo restorecon -Rv /data/mysql`.

&lt;/box-note&gt;

### Step 5: Secure MariaDB

MariaDB provides a built-in **security setup script**. To run it, use:

```bash
sudo mariadb_secure_installation
```

You will then be asked whether you want to:

- Set a root password (if not already set)
- Remove anonymous users: **Yes**
- Disable root login over the network: **Yes**
- Delete the test database: **Yes**
- Reload privileges: **Yes**

These steps strengthen the security of your installation.

### Step 6: Create a user and database

Next, create a database and a user account with the required privileges. To do this, first log in to the AlmaLinux 9 MariaDB console:

```bash
sudo mariadb -u root -p
```

Enter the **root password** you set earlier. You should then see the MariaDB prompt:

```sql
MariaDB [(none)]>
```

Create a new database, for example:

```sql
CREATE DATABASE db_name;
```

Then, create a new user and set a secure password:

```sql
CREATE USER 'dbuser'@'localhost' IDENTIFIED BY 'safepassword';
```

Grant this user full privileges on the database you created earlier:

```sql
GRANT ALL PRIVILEGES ON db_name.* TO 'dbuser'@'localhost';
```

Finally, reload the privileges:

```sql
FLUSH PRIVILEGES;
```

Exit the MariaDB console:

```sql
EXIT;
```


This is a markdown version of: [https://www.ionos.co.uk/digitalguide/hosting/technical-matters/install-mariadb-almalinux-9/](https://www.ionos.co.uk/digitalguide/hosting/technical-matters/install-mariadb-almalinux-9/) for AI/LLM consumption.