---
title: How To Install MariaDB on Ubuntu 22.04
description: "MariaDB is an open-source relational database management system often used as a substitute for MySQL in the widely-used LAMP stack (Linux, Apache, MySQL, PHP/Python/Perl). It is designed to serve as a drop-in replacement for MySQL. To install **MariaDB** on **Ubuntu…"
url: "https://truehost.com/support/knowledge-base/how-to-install-mariadb-on-ubuntu-22-04/"
updated: "2024-10-24"
category: Cloud servers in Kenya
---

# How To Install MariaDB on Ubuntu 22.04

MariaDB is an open-source relational database management system often used as a substitute for MySQL in the widely-used LAMP stack (Linux, Apache, MySQL, PHP/Python/Perl). It is designed to serve as a drop-in replacement for MySQL.

To install **MariaDB** on **Ubuntu 22.04**, you can follow these steps:

## **Prerequisites**

- A server running Ubuntu 22.04
- SSH Access to the server with root or a sudo user

You could also check our tutorial on **[First Server Setup with Ubuntu](https://truehost.com/support/knowledge-base/first-server-setup-with-ubuntu/)**to get set with the initial set up.

**Step 1: Update the System**

- Before installing MariaDB, ensure that your package index is updated to the latest available versions by running:

```
sudo apt update
```

**Step 2: Install MariaDB**

- The MariaDB packages are available in the official Ubuntu repositories. You can install it using the `apt` package manager:

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

- The above command installs both the **MariaDB server** and the **MariaDB client**.

![](https://truehost.com/support/wp-content/uploads/2024/10/image-529.png)

![](https://truehost.com/support/wp-content/uploads/2024/10/image-530.png)

**Step 3: Start and Enable MariaDB**

- Once MariaDB is installed, start the service and enable it to automatically start on boot.
- Start the MariaDB service:

```
sudo systemctl start mariadb
```

- Enable MariaDB to start at boot:

```
sudo systemctl enable mariadb
```

- Verify that the service is running:
- You should see output indicating that MariaDB is active and running.

```
sudo systemctl status mariadb
```

![](https://truehost.com/support/wp-content/uploads/2024/10/image-531-1024x523.png)

**Step 4: Secure the MariaDB Installation**

MariaDB includes a security script that can remove some insecure defaults, like anonymous users and test databases. To run the script:

```
sudo mysql_secure_installation
```

The script will prompt you to perform several security-related tasks:

- **Enter current password for root**: Press **Enter**
- **Switch to unix_socket authentication**: Answer `Y` to switch
- **Set/Change the root password**: You will be asked whether to set a root password. On new installations, you may not need to, as MariaDB on Ubuntu may use the `unix_socket` plugin for root access. Press **Enter** or **Answer n**

- **Remove anonymous users**: Answer `Y` to remove anonymous users.

- **Disallow remote root login**: Answer `Y` to disallow root login remotely.

- **Remove the test database**: Answer `Y` to remove the test database.

- **Reload privilege tables**: Answer `Y` to reload the privilege tables.

![](https://truehost.com/support/wp-content/uploads/2024/10/image-532-1024x791.png)

**Step 5: Verify MariaDB Installation**

- To verify that MariaDB is installed correctly, log into the MariaDB shell:

```
sudo mysql
```

- Once inside the MariaDB shell, check the version: You should see the MariaDB version number.

```
SELECT VERSION();
```

![](https://truehost.com/support/wp-content/uploads/2024/10/image-533.png)

- Exit the shell using the exit command

```
exit
```

![](https://truehost.com/support/wp-content/uploads/2024/10/image-534.png)

**Step 6: Creating an Administrative User that Employs Password Authentication (Optional)**

On Ubuntu systems running MariaDB 10.5, the default root user is configured to authenticate via the `unix_socket` plugin, instead of using a password. This improves security and ease of use, especially for local access, but it can be inconvenient when external programs (such as phpMyAdmin) require administrative access

It is advised to create a separate administrative account specifically for password-based access. To create this new administrative account, follow these steps:

- Access the MariaDB prompt from your terminal:

```
sudo mariadb
```

- Create a new user named `admin` with root-level privileges and password authentication. Replace `admin` and `password` with your preferred username and password respectively.

```
GRANT ALL PRIVILEGES ON *.* TO 'admin'@'localhost' IDENTIFIED BY 'password' WITH GRANT OPTION;
```

![](https://truehost.com/support/wp-content/uploads/2024/10/image-535-1024x93.png)

- Save the changes by flushing the privileges:

```
FLUSH PRIVILEGES;
```

![](https://truehost.com/support/wp-content/uploads/2024/10/image-536.png)

- Exit the MariaDB shell:

```
exit
```

![](https://truehost.com/support/wp-content/uploads/2024/10/image-538.png)

**Step 7: Confirm that MariaDB Installation is running**

- To verify that MariaDB is installed correctly, log into the MariaDB shell:

```
sudo systemctl status mariadb
```

![](https://truehost.com/support/wp-content/uploads/2024/10/image-537-1024x197.png)

- If MariaDB is not running, you can start it with:

```
sudo systemctl start mariadb
```

That's it! You've successfully installed and secured MariaDB on Ubuntu 22.04.
