# How to install MariaDB on RHEL 9

MariaDB can be installed on RHEL 9 in just a few steps:

1. Update RHEL 9 to the latest version
2. Set up the MariaDB repository and configure the database server
3. Install and start MariaDB
4. Secure the database and configure the firewall
5. Create a user account and enable remote access

## What are the advantages of MariaDB on RHEL 9?

[MariaDB](https://www.ionos.ca/digitalguide/server/know-how/what-is-mariadb/) delivers high performance and reliability. **RHEL 9** provides a stable, secure operating system with long-term support. Combined, the two create a robust database environment that is both maintainable and easy to manage over time.

## What are the requirements for installing MariaDB on RHEL 9?

Before starting the installation, make sure your system meets these requirements:

- [RHEL 9 installed](https://www.ionos.ca/digitalguide/server/configuration/install-red-hat-9/)
- Root privileges or access via [sudo](https://www.ionos.ca/digitalguide/server/configuration/linux-sudo-command/)
- At least 1 GB RAM (2 GB is recommended)
- At least 2 GB of free disk space

## How to install MariaDB on RHEL 9

If you need a [relational database](https://www.ionos.ca/digitalguide/hosting/technical-matters/relational-databases/) on RHEL 9, MariaDB can be set up quickly and reliably. On a standard RHEL 9 system, the installation process itself is pretty straightforward.

### Step 1: Update the system

Before installing any packages, update your system to the latest version. This prevents conflicts with outdated **dependencies**.

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

### Step 2: Add the MariaDB repository

RHEL 9 typically provides an older version of MariaDB. To install the latest release, add the **official repository**. Create a new configuration file:

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

Then insert the following content:

```bash
[mariadb]
name = MariaDB
baseurl = https://downloads.mariadb.com/MariaDB/mariadb-11.7/yum/rhel9-amd64
gpgkey=https://downloads.mariadb.com/MariaDB/MariaDB-Server-GPG-KEY
gpgcheck=1
```

Clear the package cache and rebuild it:

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

### Step 3: Install MariaDB

Install the **MariaDB Server**. The command will pull the necessary packages from the repository and install them automatically:

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

### Step 4: Start and enable MariaDB

After installation, start the **MariaDB service**:

```bash
sudo systemctl start mariadb
```

Then, enable it to ensure MariaDB runs automatically after reboot:

```bash
sudo systemctl enable mariadb
```

Check the current status of the service:

```bash
sudo systemctl status mariadb
```

### Step 5: Secure MariaDB

MariaDB includes a security setup script. Run **mariadb\_secure\_installation** to secure the installation:

```bash
sudo mariadb_secure_installation
```

The script will prompt you to set a root password, remove anonymous users, disable remote root logins and delete the test database. Confirm each step with `y` to apply the recommended defaults.

### Step 6: Test the database connection

Open the MariaDB console to verify access:

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

Enter the root password you just set. If you see the database shell, the installation was successful and MariaDB is ready to use:

```sql
Welcome to the MariaDB monitor...
MariaDB [(none)]>
```

### Step 7: Configure the firewall

To allow external connections, open **port 3306** on the [firewall](https://www.ionos.ca/digitalguide/server/security/what-is-a-firewall/):

```bash
sudo firewall-cmd --permanent --add-service=mysql
sudo firewall-cmd --reload
```

This enables incoming connections on the MariaDB/MySQL port.

### Step 8: Create a database and user

Log back in to MariaDB again to create a new database and user:

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

Then run the following commands:

```sql
CREATE DATABASE example_db;
CREATE USER 'user'@'localhost' IDENTIFIED BY 'safepassword';
GRANT ALL PRIVILEGES ON example_db.* TO 'user'@'localhost';
FLUSH PRIVILEGES;
```

You now have a database and a new user with full privileges.

### Step 9: Enable remote access

If you need to allow other systems to connect over the network, edit the configuration file:

```bash
sudo vi /etc/my.cnf.d/mariadb-server.cnf
```

Find the `bind-address` line and change it to:

```bash
bind-address = 0.0.0.0
```

This enables connections from all [IP addresses](https://www.ionos.ca/digitalguide/server/know-how/what-is-an-ip-address/). Restart the service for the change to take effect:

```bash
sudo systemctl restart mariadb
```


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