MariaDB is a popular, free, and open-source database management system that offers robust performance and scalability. In this article, we will guide you through the process of installing MariaDB on RockyLinux 9, a secure and stable Linux distribution.
Prerequisites
Before proceeding with the installation, ensure that you have the following:
- A server or virtual machine running RockyLinux 9.
- SSH access to the server with administrative privileges.
Step 1: Creating a MariaDB Repository File
To begin, we need to create a MariaDB repository configuration file. Connect to your RockyLinux 9 server via SSH and follow the steps below:
- Open the terminal and run the following command to create the repository file:
vi /etc/yum.repos.d/mariadb.repo
- Enter the following configuration in the file:
# MariaDB 10.11 RockyLinux repository list - created 2023-10-30 14:19 UTC # https://mariadb.org/download/ [mariadb] name = MariaDB baseurl = https://mirror.23m.com/mariadb/yum/10.11/rhel/$releasever/$basearch module_hotfixes = 1 gpgkey = https://mirror.23m.com/mariadb/yum/RPM-GPG-KEY-MariaDB gpgcheck = 1
- Save and exit the file.
Step 2: Installing MariaDB Server
Once the repository file is created, we can proceed with the installation of the MariaDB server. Run the following command in the terminal:
dnf install MariaDB-server MariaDB-client
During the installation process, you will be presented with a series of prompts. Here’s how you should respond:
Isthis ok [y/N]: y
After the installation is complete, you can verify the version of the MariaDB server by running the following command:
mysql -V
The output should display the installed version of MariaDB.
Step 3: Enabling and Starting MariaDB
To ensure that MariaDB starts automatically upon system boot, enable and start the service using the following commands:
systemctl enable mariadb systemctl start mariadb
To verify the status of the MariaDB service, run the following command:
systemctl status mariadb
The output should indicate that the service is active and running.
Step 4: Securing MariaDB
To enhance the security of your MariaDB installation, we recommend following these steps:
- Start the MariaDB shell by running the following command:
mysql
- Change the root user’s password by executing the following command:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'your_new_password';
Replace 'your_new_password'
with a strong password of your choice.
- Remove anonymous users from the system using the following command:
DELETE FROM mysql.user WHERE User = '';
This step ensures that there are no anonymous users with access to your MariaDB server.
- Disallow remote root login for improved security. Execute the following command:
DELETE FROM mysql.user WHERE User = 'root' AND Host NOT IN ('localhost','127.0.0.1','::1');
This command restricts the root user’s login privileges to the localhost only.
- Remove the test database, which is not required in a production environment:
DROP DATABASE IF EXISTS test;
- Finally, reload the privileges to apply the changes:
FLUSH PRIVILEGES;
Exit the MariaDB shell by typing EXIT;
.
Step 5: Creating a New Database and User
To create a new database and user in MariaDB, follow these steps:
- Log in to the MariaDB server as the root user:
mysql -u root -p
- Enter the root user’s password when prompted.
- Create a new database using the following command:
CREATE DATABASE shapehost;
Replace 'shapehost'
with the desired name for your database.
- Create a new user and grant them full access to the database:
CREATE USER 'shapehost'@'localhost' IDENTIFIED BY 'secretePasswordHere'; GRANT ALL ON shapehost.* TO 'shapehost'@'localhost';
Replace 'secretePasswordHere'
with a strong password for the user.
Step 6: Accessing the Database
To access the MariaDB database with the newly created database and user, use the following command:
mysql -u shapehost -p 'secretePasswordHere' shapehost
Replace 'secretePasswordHere'
with the password you set for the user.
To verify that the database is accessible, you can run the show databases;
command. It should display the list of databases, including the one you created.
Congratulations! You have successfully installed and secured MariaDB on RockyLinux 9. You can now start building and managing your databases using the power of MariaDB.
If you require any assistance or have any questions, feel free to reach out to Shape.host. Shape.host offers reliable and scalable cloud hosting solutions, including Cloud VPS options tailored to meet your specific needs.