How to Install MariaDB on Rocky Linux 9

Introduction

MariaDB is a popular open-source relational database management system (RDBMS) that is a fork of MySQL. It is widely used for database management due to its performance, stability, and compatibility with MySQL. MariaDB offers several advanced features, such as enhanced security, improved storage engines, and better replication capabilities, making it an excellent choice for database administrators and developers. Additionally, it integrates well with various technologies, including web servers like Apache and scripting languages like PHP, providing a robust environment for developing and managing databases.

This article shows you how to install MariaDB on Rocky Linux 9.

Prerequisites

To get started, ensure you have the following:

Install MariaDB

This section walks you through the installation process of MariaDB on Rocky Linux 9.

  1. SSH to your server.
  2. Update your system packages to the latest versions.

    CONSOLE
    $ sudo dnf update -y
    
  3. Use the dnf package manager to install MariaDB.

    CONSOLE
    $ sudo dnf install mariadb-server -y
    

Manage MariaDB with systemctl

This section explains how to manage the MariaDB service using systemctl.

  1. Start the MariaDB service if it is not already running.

    CONSOLE
    $ sudo systemctl start mariadb
    
  2. Enable the MariaDB service to start automatically at boot.

    CONSOLE
    $ sudo systemctl enable mariadb
    
  3. Stop the MariaDB service.

    CONSOLE
    $ sudo systemctl stop mariadb
    
  4. Restart the MariaDB service.

    CONSOLE
    $ sudo systemctl restart mariadb
    
  5. Check the MariaDB service status.

    CONSOLE
    $ sudo systemctl status mariadb
    

Secure MariaDB Installation

Securing MariaDB installation involvles setting a root password, removing anonymous users, disallowing root login remotely, and removing test databases.

  1. Run the mysql_secure_installation script.

    CONSOLE
    $ sudo mysql_secure_installation
    
  2. Respond with the following.

Understand MariaDB Configurations

This section explains the directory structure and location of configuration files for MariaDB.

  1. Data Directory: MariaDB stores its data files in the data directory, typically located in /var/lib/mysql/.

    CONSOLE
    $ sudo ls /var/lib/mysql/
    
  2. Configuration File: The main configuration file for MariaDB is my.cnf, typically located in /etc/my.cnf.

    CONSOLE
    $ sudo nano /etc/my.cnf
    
  3. Log Directory: MariaDB stores its log files in the log directory, typically located in /var/log/mariadb/.

    CONSOLE
    $ sudo ls /var/log/mariadb/
    

Set Up a Sample Database (Optional)

This section shows you how to set up a sample database named company, create a table, and populate it with data.

  1. Log in to the MariaDB server as the root user.

    CONSOLE
    $ sudo mysql -u root -p
    
  2. Create a company database.

    SQL
    CREATE DATABASE company;
    
  3. Switch to the new company database.

    SQL
    USE company;
    
  4. Create a products table with three columns: product_id, product_name, and retail_price.

    SQL
    CREATE TABLE products (
        product_id INT AUTO_INCREMENT PRIMARY KEY,
        product_name VARCHAR(255) NOT NULL,
        retail_price DECIMAL(10, 2) NOT NULL
    );
    
  5. Insert sample data into the products table.

    SQL
    INSERT INTO products (product_name, retail_price) VALUES
    ('Leather Key Holder', 2.99),
    ('Natural Flavour Ginger Wine', 15.49),
    ('Wine Bottle Opener', 7.99);
    
  6. Retrieve the records from the products table to confirm the data has been inserted correctly.

    SQL
    SELECT * FROM products;
    

Conclusion

This guide shows you how to install and configure MariaDB on Rocky Linux 9. You updated your system, installed MariaDB, and secured the installation. Additionally, you started and enabled the MariaDB service to ensure it runs smoothly. You also learned about the directory structure and configuration files for MariaDB. Furthermore, you set up a sample database, created a table, and populated it with data. For further optimization, consider configuring advanced settings and tuning performance parameters. Enjoy managing your databases with MariaDB on Rocky Linux 9.

  • Databases
  • Webservers
  • PHP
  • API
  • Python
  • VPS Guides
  • Network
  • AI
  • Node.js