# How to install MariaDB on Proxmox

Running MariaDB on [Proxmox](https://www.ionos.co.uk/digitalguide/server/know-how/proxmox/) offers many benefits for users of Home Assistant and anyone running other data-heavy applications on their own network. In this guide, you’ll learn how to install, configure and manage a MariaDB database inside a Proxmox LXC container.

## When is it a good idea to run MariaDB on Proxmox?

MariaDB on Proxmox is a good choice if you want to run database services flexibly in isolated environments. Proxmox supports [MariaDB](https://www.ionos.co.uk/digitalguide/server/know-how/what-is-mariadb/) in **containers (LXC) or virtual machines (KVM)**, letting you address different requirements separately.

## What are the prerequisites for setup?

Before starting, make sure you have:

- A running Proxmox host (VE 7 or 8)
- Access to the Proxmox web interface and shell
- At least 4 GB of storage and 1 GB of [RAM](https://www.ionos.co.uk/digitalguide/server/know-how/what-is-ram/) for the LXC
- Network access for the container (via DHCP or static [IP address](https://www.ionos.co.uk/digitalguide/server/know-how/what-is-an-ip-address/))

## How to install MariaDB in an LXC container on Proxmox

With Proxmox, you can run MariaDB efficiently inside an **LXC container**. The following steps show you how to set up an LXC container and install MariaDB inside it:

### Step 1: Run the script

The simplest way to install MariaDB inside an LXC container on Proxmox is to use a **community script**. Log in to the Proxmox web interface and select your node. Click on **Shell** and run the following command:

```bash
bash -c "$(wget -qLO - https://github.com/community-scripts/ProxmoxVE/raw/main/ct/mariadb.sh)"
```

A security prompt will appear. Press Enter to confirm, then choose either standard or advanced installation.

### Step 2: Configure the installation

The standard installation uses these default settings:

- **RAM**: 1 GB
- **Storage**: 4 GB
- **CPU**: 1 vCore
- **Container Type**: unprivileged
- **Network**: [DHCP](https://www.ionos.co.uk/digitalguide/server/configuration/dhcp-an-overview-of-the-clientserver-protocol/)

This setup is enough for most cases. In advanced mode, you can configure additional options such as the Debian version, a root password or a static IP address.

During installation, you’ll also be asked whether you want to install **Adminer**. Adminer is a lightweight web front-end for databases. Press `Y` if you’d like to access MariaDB through your browser later.

When the setup finishes, you’ll see `Completed Successfully!`. You can then continue with configuration.

### Step 3: Edit the configuration file

To let applications like Home Assistant connect to the database, you need to enable **remote access**.

Open the LXC console in Proxmox and edit the main config file:

```bash
nano /etc/mysql/my.cnf
```

Find the line `#port = 3306` and remove the (`#`) at the beginning to activate it. Save with \[CTRL\] + \[O\], press Enter to confirm, and close with \[CTRL\] + \[X\].

### Step 4: Update the server configuration

Next, edit the server config file inside the container:

```bash
nano /etc/mysql/mariadb.conf.d/50-server.cnf
```

Find this line:

```bash
bind-address = 127.0.0.1
```

Comment it out by adding a `#` at the beginning:

```bash
#bind-address = 127.0.0.1
```

Save and close the file. Then restart MariaDB:

```bash
systemctl restart mariadb
```

This enables access from the local network.

### Step 5: Secure MariaDB

MariaDB includes a built-in **security setup script** for basic protection. Run it in the container’s console:

```bash
mariadb-secure-installation
```

You’ll be prompted to:

- Enter current root password (Press Enter for none):
- Change the root password? \[Y/n\] n
- Remove anonymous users? \[Y/n\] y
- Disallow root login remotely? \[Y/n\] y
- Remove test database and access to it? \[Y/n\] y
- Reload privilege tables now? \[Y/n\] y

Your MariaDB installation inside the container is now secured. The database is ready for you to create users and connect services.

### Step 6: Create a user and database

Now log in to the MariaDB shell:

```bash
/usr/bin/mariadb
```

Create a new user:

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

Grant this user full privileges on all databases:

```sql
GRANT ALL ON *.* TO 'homeuser'@'localhost' WITH GRANT OPTION;
```

To allow access over the local network, run:

```sql
GRANT ALL ON *.* TO 'homeuser'@'192.168.0.%' IDENTIFIED BY 'safepassword' WITH GRANT OPTION;
```

Create a database of your own, for example, for Home Assistant:

```sql
CREATE DATABASE homeassistant;
```

Apply the changes:

```sql
FLUSH PRIVILEGES;
```

Exit the shell with:

```sql
exit
```

The user account has now been created and can be accessed with the password you set. The database is also ready to accept connections from external services.

### Step 7: Configure the network and start-up order

To ensure **MariaDB** works reliably with applications like **Home Assistant**, secure the network configuration and make sure the database container starts before other containers.

If you selected **DHCP** during setup, the **MariaDB LXC** will be assigned a dynamic IP address, which may change after a restart. To prevent connection issues, either set a static IP in the LXC network settings or assign a fixed IP through a DHCP reservation in your router.

Here’s how to check the current IP address of the container:

```bash
ip a
```

Or view it in the **Proxmox** interface under **Summary** -&gt; **Network**.

### Step 8: Define the container’s start-up behaviour

To ensure Home Assistant can access the database at start-up, configure the **MariaDB** container to start first. You can set the start-up order in **Proxmox**:

1. Select the **MariaDB** container.
2. Click **Options**.
3. Double-click **Start/Shutdown order**.
4. Enable it and set: ‘Start order: 1’ and ‘Startup delay: 60 seconds’.

Repeat the process for the Home Assistant container. For example, by setting ‘Start order 2’ and ‘Startup delay 10 seconds’.

### Step 9: Connect Home Assistant to MariaDB

Once the database is ready and has a fixed IP address, configure Home Assistant to use **MariaDB** instead of [SQLite](https://www.ionos.co.uk/digitalguide/websites/web-development/sqlite/).

Open `configuration.yaml` in Home Assistant, for example using the File Editor add-on or Visual Studio Code:

```yaml
recorder:
    db_url: mysql://homeuser:safepassword@192.168.0.45:3306/homeassistant?charset=utf8mb4
```

Replace the username, password, IP address and database name with your own values. Make sure **MariaDB** starts before Home Assistant.

Restart Home Assistant. If everything is set up correctly, new data will be stored in the **MariaDB** database.

### Step 10: Back up MariaDB in Proxmox

**Proxmox** supports snapshots and container backups, so you can back up the **MariaDB LXC container** at any time – either manually or on a scheduled basis:

1. Select your **MariaDB** container from the list on the left.
2. Click **Backup** at the top.
3. Choose a storage location (for example, ‘local’), select a mode (snapshot recommended), and start the backup.

For automatic backups, you can set up schedules under **Datacenter** &gt; **Backup**.


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