How to Install and Configure MariaDB on Ubuntu

ShellShellBeginner
Practice Now

Introduction

This comprehensive tutorial provides a detailed walkthrough for installing and configuring MariaDB, an open-source relational database management system, on Ubuntu Linux. Designed for developers and system administrators, the guide covers essential steps from initial setup to basic database operations, helping users quickly deploy a robust and scalable database solution.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL shell(("`Shell`")) -.-> shell/ControlFlowGroup(["`Control Flow`"]) shell(("`Shell`")) -.-> shell/VariableHandlingGroup(["`Variable Handling`"]) shell(("`Shell`")) -.-> shell/AdvancedScriptingConceptsGroup(["`Advanced Scripting Concepts`"]) shell/ControlFlowGroup -.-> shell/if_else("`If-Else Statements`") shell/VariableHandlingGroup -.-> shell/variables_decl("`Variable Declaration`") shell/VariableHandlingGroup -.-> shell/variables_usage("`Variable Usage`") shell/ControlFlowGroup -.-> shell/for_loops("`For Loops`") shell/AdvancedScriptingConceptsGroup -.-> shell/read_input("`Reading Input`") subgraph Lab Skills shell/if_else -.-> lab-393057{{"`How to Install and Configure MariaDB on Ubuntu`"}} shell/variables_decl -.-> lab-393057{{"`How to Install and Configure MariaDB on Ubuntu`"}} shell/variables_usage -.-> lab-393057{{"`How to Install and Configure MariaDB on Ubuntu`"}} shell/for_loops -.-> lab-393057{{"`How to Install and Configure MariaDB on Ubuntu`"}} shell/read_input -.-> lab-393057{{"`How to Install and Configure MariaDB on Ubuntu`"}} end

MariaDB Basics

Introduction to MariaDB

MariaDB is an open-source relational database management system (RDBMS) that emerged as a fork of MySQL. Developed by the original MySQL developers, it provides a robust and scalable solution for storing, managing, and retrieving structured data across various applications.

graph LR A[Application] --> B[MariaDB] B --> C[Data Storage] B --> D[Data Retrieval]

Key Characteristics

Feature Description
Open Source Free and community-driven development
MySQL Compatibility Direct drop-in replacement for MySQL
Performance High-speed data processing
Scalability Supports large and complex database environments

Database Architecture

MariaDB uses a client-server model where multiple clients can connect to a central database server. The system supports multiple storage engines, allowing flexible data management strategies.

Basic Database Operations Example

Here's a simple demonstration of MariaDB operations on Ubuntu 22.04:

## Install MariaDB
sudo apt update
sudo apt install mariadb-server

## Start MariaDB service
sudo systemctl start mariadb
sudo systemctl enable mariadb

## Secure initial installation
sudo mysql_secure_installation

## Connect to MariaDB
mysql -u root -p

These commands illustrate the fundamental steps of installing and initializing MariaDB on a Linux system, providing a foundation for further database management tasks.

Installation Guide

Preparation for MariaDB Installation

Before installing MariaDB on Ubuntu 22.04, ensure your system is updated and meets the necessary prerequisites. The installation process involves adding the official MariaDB repository and configuring the server.

graph LR A[System Update] --> B[Add Repository] B --> C[Install MariaDB] C --> D[Configure Server]

Repository Configuration

Step Command Description
Update System sudo apt update Refresh package lists
Install Dependencies sudo apt install software-properties-common Prepare system for repository management
Add MariaDB GPG Key `sudo apt-key adv --fetch-keys ' Verify repository authenticity

Installation Commands

## Add MariaDB repository
sudo add-apt-repository 'deb [arch=amd64]  jammy main'

## Update package lists
sudo apt update

## Install MariaDB server
sudo apt install mariadb-server

## Start MariaDB service
sudo systemctl start mariadb

## Enable automatic startup
sudo systemctl enable mariadb

Initial Server Configuration

## Secure installation
sudo mysql_secure_installation

## Typical configuration steps:
## 1. Set root password
## 2. Remove anonymous users
## 3. Disable remote root login
## 4. Remove test database

Verification

## Check MariaDB service status
sudo systemctl status mariadb

## Connect to MariaDB
mysql -u root -p

Database Operations

Core Database Management Concepts

MariaDB provides comprehensive database operations through SQL commands, enabling efficient data management and manipulation across various applications.

graph LR A[Database Operations] --> B[Create] A --> C[Read] A --> D[Update] A --> E[Delete]

Key SQL Operations

Operation Command Purpose
Database Creation CREATE DATABASE Initialize new database
Table Creation CREATE TABLE Define data structure
Data Insertion INSERT INTO Add new records
Data Retrieval SELECT Query and fetch data
Data Modification UPDATE Modify existing records
Data Deletion DELETE Remove specific records

Practical Examples

## Create a new database
CREATE DATABASE employee_management;

## Use the database
USE employee_management;

## Create a table
CREATE TABLE staff (
    id INT PRIMARY KEY,
    name VARCHAR(100),
    department VARCHAR(50),
    salary DECIMAL(10,2)
);

## Insert data
INSERT INTO staff VALUES 
(1, 'John Doe', 'IT', 5000.00),
(2, 'Jane Smith', 'HR', 4500.00);

## Query data
SELECT * FROM staff WHERE department = 'IT';

## Update record
UPDATE staff SET salary = 5500.00 WHERE id = 1;

## Delete record
DELETE FROM staff WHERE id = 2;

Security Considerations

## Create database user
CREATE USER 'dbadmin'@'localhost' IDENTIFIED BY 'strong_password';

## Grant specific privileges
GRANT ALL PRIVILEGES ON employee_management.* TO 'dbadmin'@'localhost';

## Flush privileges
FLUSH PRIVILEGES;

Summary

By following this tutorial, users will gain practical knowledge of MariaDB installation, configuration, and fundamental database management techniques. The guide emphasizes key aspects such as system preparation, repository configuration, server setup, and initial database operations, enabling professionals to efficiently implement and maintain MariaDB database environments in production and development scenarios.

Other Shell Tutorials you may like