LinuxUbuntu

How to Install MariaDB on Ubuntu

MariaDB is a popular open-source relational database management system that is a fork of MySQL. It is widely used for its reliability, performance, and open-source nature. This guide will walk you through the steps to install MariaDB on an Ubuntu system.


Prerequisites

Before proceeding with the installation, ensure the following:

  1. You have access to an Ubuntu server or desktop with sudo privileges.
  2. Your system is updated. Run the following command to update all packages:
   sudo apt update && sudo apt upgrade -y

Step 1: Install MariaDB

MariaDB is included in the default Ubuntu repositories, making installation straightforward. Follow these steps:

  1. Install the MariaDB Server and Client:
    Run the following command to install MariaDB:
   sudo apt install mariadb-server mariadb-client -y
  1. Verify the Installation:
    After the installation is complete, you can verify it by checking the MariaDB version:
   mariadb --version

This will output the installed version number of MariaDB.


Step 2: Secure the MariaDB Installation

MariaDB includes a security script to help you secure your installation by setting a root password, removing test databases, and disabling anonymous users.

  1. Run the following command:
   sudo mysql_secure_installation
  1. You will be prompted to configure several options:
  • Set the root password (if not already set).
  • Remove anonymous users.
  • Disallow remote root login.
  • Remove the test database.
  • Reload privilege tables. Respond to each prompt as needed to secure your installation.

Step 3: Start and Enable MariaDB Service

Ensure that the MariaDB service is running and set to start on boot.

  1. Start the MariaDB service:
   sudo systemctl start mariadb
  1. Enable the service to start on boot:
   sudo systemctl enable mariadb
  1. Check the service status:
   sudo systemctl status mariadb

The output should show that the service is active and running.


Step 4: Test MariaDB

To confirm that MariaDB is working as expected, log in to the MariaDB shell.

  1. Log in using the following command:
   sudo mysql
  1. If successful, you’ll see the MariaDB prompt. Run basic SQL commands to verify functionality, such as:
   SHOW DATABASES;
  1. Exit the MariaDB shell by typing:
   EXIT;

Optional: Configure Remote Access

If you need to allow remote access to the MariaDB server, follow these steps:

  1. Open the MariaDB configuration file:
   sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf
  1. Locate the line that starts with bind-address and change it from 127.0.0.1 to 0.0.0.0:
   bind-address = 0.0.0.0
  1. Save and close the file, then restart MariaDB:
   sudo systemctl restart mariadb
  1. Update the firewall rules to allow traffic on the MariaDB port (3306 by default):
   sudo ufw allow 3306

Conclusion

You have successfully installed and configured MariaDB on your Ubuntu system. Whether you’re using it for personal projects or production environments, MariaDB provides a robust and efficient solution for managing your databases. If you plan on using it in production, consider additional hardening steps to enhance security.

Leave a Reply

Your email address will not be published. Required fields are marked *


Back to top button