# Install MariaDB on Linux

{% hint style="info" %}
This documentation has been extracted from mariadb oficial page
{% endhint %}

{% tabs %}
{% tab title="Debian / Ubuntu" %}
{% hint style="info" %}
This guide will walk you through the steps to install **MariaDB 11.4.3** on a Linux system based on Debian (such as Ubuntu, Debian itself, or other derivatives). MariaDB is an open-source relational database system that is a popular choice for many web applications.
{% endhint %}

***

#### Prerequisites

* A running Debian-based system (e.g., Ubuntu 22.04, Debian 11).
* Root or sudo access.
* A stable internet connection for package downloads.

#### Step-by-Step Installation Guide

**1. Update Your System**

First, make sure your package lists are up to date.

```bash
sudo apt update
sudo apt upgrade -y
```

**2. Install Prerequisites**

MariaDB requires some dependencies to be installed on your system, like `software-properties-common` to manage repositories.

```bash
sudo apt install software-properties-common dirmngr -y
```

**3. Add the MariaDB 11.4 Repository**

To install the latest version of MariaDB (11.4.3), you need to add the official MariaDB repository to your system.

1. Import the MariaDB GPG key:

   ```bash
   sudo apt-key adv --fetch-keys 'https://mariadb.org/mariadb_release_signing_key.asc'
   ```
2. Add the MariaDB repository:

   ```bash
   sudo add-apt-repository 'deb [arch=amd64] https://mirror.mariadb.org/repo/11.4/debian bullseye main'
   ```

   If you're using a different Debian-based distribution, replace `bullseye` with your version codename (e.g., `focal` for Ubuntu 20.04).

**4. Update Package Lists Again**

After adding the MariaDB repository, update your package list to include the new packages from MariaDB:

```bash
sudo apt update
```

**5. Install MariaDB 11.4.3**

Now you can install MariaDB 11.4.3 using the following command:

```bash
sudo apt install mariadb-server mariadb-client -y
```

**6. Start and Enable MariaDB Service**

After installation, start the MariaDB service and enable it to automatically start on system boot:

```bash
sudo systemctl start mariadb
sudo systemctl enable mariadb
```

**7. Secure the MariaDB Installation**

MariaDB includes a security script to remove default settings that are insecure. Run this script:

```bash
sudo mysql_secure_installation
```

You will be prompted to:

* Set a root password (if not set during installation).
* Remove anonymous users.
* Disallow remote root login.
* Remove the test database.
* Reload privilege tables.

Answer "Y" to all prompts for a secure installation.

**8. Verify Installation**

To verify that MariaDB is correctly installed and running, use:

```bash
sudo systemctl status mariadb
```

You should see the service status as "active" (running).

Additionally, log into the MariaDB shell:

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

Enter the root password you created earlier, and you'll be logged into the MariaDB shell. To confirm the version, run:

```sql
SELECT VERSION();
```

You should see something like:

```
+----------------+
| VERSION()      |
+----------------+
| 11.4.3-MariaDB |
+----------------+
```

**9. Basic Configuration (Optional)**

You can configure MariaDB by editing the `my.cnf` configuration file:

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

Make any changes you need, then restart the service:

```bash
sudo systemctl restart mariadb
```

***

#### Common Commands

* **Start MariaDB:**

  ```bash
  sudo systemctl start mariadb
  ```
* **Stop MariaDB:**

  ```bash
  sudo systemctl stop mariadb
  ```
* **Restart MariaDB:**

  ```bash
  sudo systemctl restart mariadb
  ```
* **Check MariaDB Status:**

  ```bash
  sudo systemctl status mariadb
  ```

***

{% endtab %}

{% tab title="CentOS" %}
{% hint style="info" %}
This guide will help you install **MariaDB 11.4.3** on a **CentOS** system, including CentOS 7, CentOS 8, or CentOS Stream. MariaDB is a widely-used relational database system, known for its speed and reliability.
{% endhint %}

***

#### Prerequisites

* A running CentOS system (CentOS 7, CentOS 8, or CentOS Stream).
* Root or sudo access.
* Internet connection for package downloads.

***

#### Step-by-Step Installation Guide

**1. Update Your System**

Before beginning, update your system packages to ensure everything is up-to-date:

```bash
sudo yum update -y
```

**2. Add the MariaDB 11.4 Repository**

MariaDB 11.4 is not available by default in the CentOS repositories, so we need to add the MariaDB official repository.

1. **Create a repository file**:

   ```bash
   sudo nano /etc/yum.repos.d/MariaDB.repo
   ```
2. **Add the following content** based on your CentOS version:

For **CentOS 7**:

```
[mariadb]
name = MariaDB
baseurl = https://mirror.mariadb.org/repo/11.4/centos7-amd64
gpgkey=https://mariadb.org/mariadb_release_signing_key.asc
gpgcheck=1
```

For **CentOS 8** / **Stream**:

```
[mariadb]
name = MariaDB
baseurl = https://mirror.mariadb.org/repo/11.4/centos8-amd64
gpgkey=https://mariadb.org/mariadb_release_signing_key.asc
gpgcheck=1
```

1. **Save and exit** the file by pressing `CTRL + X`, then `Y`, and `Enter`.

**3. Install MariaDB 11.4.3**

Now that the MariaDB repository is added, you can install MariaDB 11.4.3.

```bash
sudo yum install MariaDB-server MariaDB-client -y
```

**4. Start and Enable MariaDB Service**

Once the installation is complete, start MariaDB and enable it to start on boot:

```bash
sudo systemctl start mariadb
sudo systemctl enable mariadb
```

You can check if the service is running correctly:

```bash
sudo systemctl status mariadb
```

The status should be "active (running)".

**5. Secure MariaDB Installation**

MariaDB includes a script to secure the installation by removing insecure default settings. Run the script to improve security:

```bash
sudo mysql_secure_installation
```

You'll be prompted to:

* Set a root password (if not already set).
* Remove anonymous users.
* Disallow root remote login.
* Remove the test database.
* Reload privilege tables.

Answer "Y" to all prompts for better security.

**6. Verify Installation**

To verify the installation of MariaDB 11.4.3, log into the MariaDB shell:

```bash
sudo mysql -u root -p
```

Enter the root password, and you'll be logged in. To check the installed version, run:

```sql
SELECT VERSION();
```

This should output something like:

```
+----------------+
| VERSION()      |
+----------------+
| 11.4.3-MariaDB |
+----------------+
```

**7. Firewall Configuration (Optional)**

If your server uses **firewalld**, you'll need to allow MariaDB service through the firewall to allow external connections.

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

**8. Basic Configuration (Optional)**

You can configure MariaDB by editing its main configuration file, typically located at `/etc/my.cnf` or `/etc/my.cnf.d/`. For example:

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

Make any necessary changes and save. After making changes, restart MariaDB:

```bash
sudo systemctl restart mariadb
```

***

#### Common Commands

* **Start MariaDB:**

  ```bash
  sudo systemctl start mariadb
  ```
* **Stop MariaDB:**

  ```bash
  sudo systemctl stop mariadb
  ```
* **Restart MariaDB:**

  ```bash
  sudo systemctl restart mariadb
  ```
* **Enable MariaDB at Boot:**

  ```bash
  sudo systemctl enable mariadb
  ```
* **Check MariaDB Status:**

  ```bash
  sudo systemctl status mariadb
  ```

***

{% endtab %}
{% endtabs %}
