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:
- A Rocky Linux 9 server. We recommend a Digital Ocean VPS server.
- A non-root user with sudo priveleges.
Install MariaDB
This section walks you through the installation process of MariaDB on Rocky Linux 9.
- SSH to your server.
-
Update your system packages to the latest versions.
CONSOLE$ sudo dnf update -y
-
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.
-
Start the MariaDB service if it is not already running.
CONSOLE$ sudo systemctl start mariadb
-
Enable the MariaDB service to start automatically at boot.
CONSOLE$ sudo systemctl enable mariadb
-
Stop the MariaDB service.
CONSOLE$ sudo systemctl stop mariadb
-
Restart the MariaDB service.
CONSOLE$ sudo systemctl restart mariadb
-
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.
-
Run the
mysql_secure_installation
script.CONSOLE$ sudo mysql_secure_installation
-
Respond with the following.
Understand MariaDB Configurations
This section explains the directory structure and location of configuration files for MariaDB.
-
Data Directory: MariaDB stores its data files in the
data
directory, typically located in/var/lib/mysql/
.CONSOLE$ sudo ls /var/lib/mysql/
-
Configuration File: The main configuration file for MariaDB is
my.cnf
, typically located in/etc/my.cnf
.CONSOLE$ sudo nano /etc/my.cnf
-
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.
-
Log in to the MariaDB server as the
root
user.CONSOLE$ sudo mysql -u root -p
-
Create a
company
database.SQLCREATE DATABASE company;
-
Switch to the new
company
database.SQLUSE company;
-
Create a
products
table with three columns:product_id
,product_name
, andretail_price
.SQLCREATE TABLE products ( product_id INT AUTO_INCREMENT PRIMARY KEY, product_name VARCHAR(255) NOT NULL, retail_price DECIMAL(10, 2) NOT NULL );
-
Insert sample data into the
products
table.SQLINSERT INTO products (product_name, retail_price) VALUES ('Leather Key Holder', 2.99), ('Natural Flavour Ginger Wine', 15.49), ('Wine Bottle Opener', 7.99);
-
Retrieve the records from the
products
table to confirm the data has been inserted correctly.SQLSELECT * 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.