Install and Configure MariaDB on Ubuntu 24.04

By Raman Kumar

Updated on Aug 07, 2024

Install and Configure MariaDB Database on Ubuntu

MariaDB is an open-source relational database management system known for its performance, reliability, and ease of use. It is a community-developed fork of MySQL, offering a robust solution for managing databases with advanced features and capabilities. Suitable for a variety of applications, MariaDB ensures seamless data management and scalability.

You will learn to secure your installation, create a new database, set up tables, and insert data into them. This guide is designed for users looking to get started with MariaDB and covers essential steps to help you set up and manage your database effectively. Whether you're a beginner or an experienced user, this tutorial provides clear, step-by-step instructions to ensure a smooth and successful installation and configuration of MariaDB.

Prerequisites:

  • A Ubuntu 24.04 installed dedicated server or KVM VPS
  • A root user access or normal user with sudo rights
  • Basic Linux commands knowledge

Install and Configure MariaDB on Ubuntu

Step 1: Installing MariaDB

Open a terminal and update your package index:

sudo apt update
sudo apt upgrade

Install the MariaDB server package:

sudo apt install mariadb-server

Secure the Installation. Run the security script to remove insecure default settings:

sudo mysql_secure_installation

You will be prompted to set a root password, remove anonymous users, disallow root login remotely, remove test databases, and reload privilege tables. Follow the prompts to secure your installation.

Start and enable the MariaDB service to start on boot:

sudo systemctl start mariadb
sudo systemctl enable mariadb

Step 2: Creating a Database

Log in to the MariaDB server using the root account:

sudo mysql -u root -p

Create a Database

Once logged in, create a new database. Here, we'll name it testdb:

CREATE DATABASE testdb;

Use the Database. Switch to the new database:

USE testdb;

Step 3: Creating a Table 

Create a new table named users with columns for ID, name, and email:

CREATE TABLE users (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(100),
    email VARCHAR(100)
);

Step 4: Inserting Values into the Table

Insert some sample data into the users table:

INSERT INTO users (name, email) VALUES ('Alice', 'alice@example.com');
INSERT INTO users (name, email) VALUES ('Bob', 'bob@example.com');
INSERT INTO users (name, email) VALUES ('Charlie', 'charlie@example.com');

Verify the inserted values by running a query:

SELECT * FROM users;

You should see an output like this:

+----+---------+-----------------------------------+
| id | name    | email                             |
+----+---------+-----------------------------------+
|  1 | Alice   | alice@example.com       |
|  2 | Bob     | bob@example.com       |
|  3 | Charlie | charlie@example.com |
+----+---------+-----------------------------------+

Step 5: Exiting MariaDB

Exit the MariaDB shell:

EXIT;

Conclusion

You have successfully seen how to install  and configure MariaDB on Ubuntu 24.04 server, created a database, created a table, and inserted values into the table. This tutorial provides the basic steps to get started with MariaDB on a Linux system. For more advanced configurations and optimizations, refer to the MariaDB documentation.