Step-by-Step Guide to Installing MariaDB on Ubuntu 24.04 LTS


Introduction

MariaDB is a free and open-source database server that works on a relational database management system (RDBMS). It is widely used for projects, and it is also the most popular database server for LAMP servers. 

Prerequisites

  • 1 Core CPU and 1 GB Memory 
  • 500 MB disk space (This will be a minimal requirement, Click here for offical website.)

In this post, We are going to show you how to install MariaDB on Ubuntu 24.04 LTS.

Step 1: Run System Update & Upgrade 

We need to execute the given command that updates and upgrades the Ubuntu repository and upgrades the packages.

sudo apt-get update && sudo apt-get upgrade -y


Step 2: Installing MariaDB  

We need to execute the given command that installs MariaDB along with the client package. This auto-resolves the dependencies for MariaDB.

sudo apt-get install mariadb-server mariadb-client -y


Step 3: Enabling and Start MariaDB Service 

After installation of MariaDB packages, we need to enable the MariaDB service on server reboot along with starting the service by using the given command.

sudo systemctl enable mariadb && sudo systemctl start mariadb


Step 4: Secure MariaDB

By default, MariaDB comes with some sample data and some unwanted access. We need to secure the MariaDB with the root user password and by removing the unwanted user, etc. Use the following command for the same.

sudo mysql_secure_installation


Secure the MariaDB by Following the prompts to:

  • Setup a root's user  password
  • Removing anonymous users
  • Disabling remote root login
  • Removing test database


Step 5: Log in MariaDB  

To log in to the MariaDB server, We need to use the given command, and with this command, We need to use the username and password.

sudo mysql -u root -p


Step 6: Creating a Sample Database  

To create a database in the MariaDB server, we can use the given command to check functionality, Execute the given command for the same.

CREATE DATABASE sample_db;


Step 7: Veriying Database

To verify the database is created or not, We need to simply execute the given query.

SHOW DATABASES;


Step 8: Use Database

To use the created database, we need to use the given command; after that, we can create a table.

USE sample_db;


Step 9: Creating a Table

To create a table with the database, We need to execute the following query that has fields.

CREATE TABLE employees (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(100) NOT NULL,
    age INT,
    department VARCHAR(50),
    salary DECIMAL(10,2)
);


Step 10: Showing Table

To verify the created table, we need to execute the following query that shows the tables.

SHOW TABLES;



Step 11: Inserting Sample Data

Inserting the sample data in the table, we need to execute the following query.

INSERT INTO employees (name, age, department, salary) VALUES
('John Doe', 30, 'IT', 50000.00),
('Jane Smith', 28, 'HR', 45000.00),
('Alice Johnson', 35, 'Finance', 60000.00);


Step 12: Retrieving Data

Verifying the inserted data in the table by executing the given MySQL query.

SELECT * FROM employees;


Step 13: Exit from MariaDB

All the verification is done. Now we are good to log out from the MariaDB shell, Use the given command for the same.

exit;



Conclusion 

We have successfully installed and set up the MariaDB server on the Ubuntu 24.04 LTS Linux machine. Still, if you are having any issues, please leave a comment below.

Aftab Ali

My expertise is in ethical hacking, penetration testing, network security, monitoring and more.

Post a Comment

Previous Post Next Post