Install MariaDB on Ubuntu

How To Install MariaDB on Ubuntu 22.04: A Quick Step-by-Step Guide

MariaDB Introduction

MariaDB is a popular open-source relational database management system. It’s a great choice for Ubuntu users who need a reliable and powerful database solution. If you’re looking to set up MariaDB on your Ubuntu 22.04 system, you’re in the right place.

Installing MariaDB on Ubuntu 22.04 is a straightforward process that can be completed in just a few steps using the command line. The process involves updating your system, installing the necessary packages, and securing your MariaDB installation. By following this guide, you’ll have a fully functional MariaDB server up and running in no time.

Setting up MariaDB on Ubuntu 22.04 opens up a world of possibilities for managing and organizing your data. Whether you’re a developer, system administrator, or just someone who needs a robust database for personal projects, MariaDB provides the tools and features you need to succeed.

Key Takeaways

Preparing for MariaDB Installation

Before installing MariaDB, you need to update your system and set up the correct repository. These steps ensure you get the latest version and avoid potential issues.

Updating System Packages

First, update your Ubuntu package index and upgrade existing packages. Open a terminal and run:

sudo apt update
sudo apt upgrade

This refreshes the list of available packages and installs any updates. It’s a good practice to do this regularly.

Next, install some required packages:

sudo apt install software-properties-common dirmngr apt-transport-https

These tools help manage software repositories and secure connections.

Configuring the MariaDB Repository

To get the latest MariaDB version, add the official MariaDB repository. This ensures you have access to the most up-to-date builds.

First, import the MariaDB GPG key:

sudo apt-key adv --fetch-keys 'https://mariadb.org/mariadb_release_signing_key.asc'

Then, add the MariaDB repository to your system:

sudo add-apt-repository 'deb [arch=amd64,arm64,ppc64el] https://mirror.rackspace.com/mariadb/repo/10.6/ubuntu focal main'

Replace ‘10.6’ with your desired MariaDB version if needed. After adding the repository, update the package index again:

sudo apt update

Your system is now ready for MariaDB installation.

Installing and Securing MariaDB

Installing MariaDB on Ubuntu 22.04 is straightforward. The process involves installing the software, setting up initial security, and managing the service.

Executing the Installation

To install MariaDB on Ubuntu, use the following command:

sudo apt update
sudo apt install mariadb-server

This installs the MariaDB server and related tools. The installation process is quick and doesn’t require user input.

After installation, check the MariaDB version:

mariadb --version

Initial Security Configuration

Run the security script to set up initial security measures:

sudo mysql_secure_installation

This script prompts you to:

  • Set a root password
  • Remove anonymous users
  • Disallow root login remotely
  • Remove test database
  • Reload privilege tables

Answer “Y” to all prompts for maximum security. These steps enhance MariaDB’s security by limiting access and removing potential vulnerabilities.

Managing MariaDB Service

Control the MariaDB service using systemctl:

  • Start MariaDB: sudo systemctl start mariadb
  • Enable MariaDB to start on boot: sudo systemctl enable mariadb
  • Check status: sudo systemctl status mariadb
  • Restart MariaDB: sudo systemctl restart mariadb
  • Stop MariaDB: sudo systemctl stop mariadb

These commands allow easy management of the MariaDB service. Regular status checks ensure the database is running smoothly.

To further secure MariaDB, consider setting up a firewall and creating separate user accounts with limited privileges for different applications or users.

Frequently Asked Questions

Installing MariaDB on Ubuntu 22.04 involves several key steps. These include preparing the system, adding the MariaDB repository, installing the software, and securing the setup. Let’s address some common questions about this process.

What are the initial steps to prepare Ubuntu 22.04 for MariaDB installation?

Before installing MariaDB, update your system packages. Run these commands:

sudo apt update
sudo apt upgrade

This ensures your system has the latest updates and security patches.

How can I add the MariaDB repository to an Ubuntu 22.04 system?

To add the official MariaDB repository, use these commands:

sudo apt install software-properties-common
sudo apt-key adv --fetch-keys 'https://mariadb.org/mariadb_release_signing_key.asc'
sudo add-apt-repository 'deb [arch=amd64] http://mariadb.mirror.globo.tech/repo/10.5/ubuntu focal main'

These steps add the MariaDB repository to your system’s sources.

What is the command to install MariaDB on Ubuntu 22.04 using the terminal?

After adding the repository, install MariaDB with this command:

sudo apt install mariadb-server

This installs the MariaDB server and client packages.

How do you secure the MariaDB installation after setup on Ubuntu 22.04?

Run the security script with this command:

sudo mysql_secure_installation

This script helps you set a root password, remove anonymous users, and disable remote root login.

What process should be followed to configure MariaDB for initial use on Ubuntu 22.04?

Log in to MariaDB as root:

sudo mysql -u root -p

Create a new database and user:

CREATE DATABASE your_database_name;
CREATE USER 'your_username'@'localhost' IDENTIFIED BY 'your_password';
GRANT ALL PRIVILEGES ON your_database_name.* TO 'your_username'@'localhost';
FLUSH PRIVILEGES;

These commands set up a new database and user with full privileges.

Where can you check the status of the MariaDB service on Ubuntu 22.04 after installation?

Check the MariaDB service status with this command:

sudo systemctl status mariadb

This shows if MariaDB is running, stopped, or encountering issues.

Share this article: