MariaDB is a popular, free, and open-source database management system that offers robust features and high performance. If you’re running AlmaLinux 9 and want to harness the power of MariaDB, this step-by-step guide will walk you through the installation process. By following these instructions, you’ll have a fully functional MariaDB server up and running on your AlmaLinux system.
Prerequisites
Before you begin the installation process, make sure you have the following prerequisites in place:
- A server running AlmaLinux 9.
- Root access or a user account with sudo privileges.
- A stable internet connection.
Step 1: Creating the MariaDB Repository File
To install the MariaDB server, you need to create a MariaDB repository configuration file. Start by opening a terminal and running the following command to create the repository file:
sudo vi /etc/yum.repos.d/mariadb.repo
This command will open a new file in the vi editor. Copy and paste the following configuration into the file:
# MariaDB 10.11 AlmaLinux repository list - created [current date] # https://mariadb.org/download/ [mariadb] name = MariaDB baseurl = https://mirror.23m.com/mariadb/yum/10.11/almalinux/$releasever/$basearch module_hotfixes = 1 gpgkey = https://mirror.23m.com/mariadb/yum/RPM-GPG-KEY-MariaDB gpgcheck = 1
Save and exit the file by pressingEsc, typing:wq, and hittingEnter.
Step 2: Installing MariaDB Server
Once the repository file is created, you can proceed with the installation of the MariaDB server. Run the following command in the terminal:
sudo dnf install MariaDB-server
You will be prompted to confirm the installation. Type y and hit Enter to proceed. The installation process will begin, and the required packages will be downloaded and installed automatically.
Step 3: Verifying the Installation
After the installation is complete, you can verify the version of the MariaDB server by running the following command:
mysql -V
This command will display the version information of the installed MariaDB server.
Step 4: Starting and Enabling MariaDB
To ensure that MariaDB starts automatically upon system boot, you need to enable it. Run the following command:
sudo systemctl enable mariadb
Next, start the MariaDB service by running:
sudo systemctl start mariadb
To check the status of the MariaDB service, use the following command:
sudo systemctl status mariadb
If the service is running, the output will indicate that it is active and running.
Step 5: Securing Your MariaDB Server
Securing your MariaDB installation is crucial to protect your data and ensure the integrity of your database. Follow these steps to secure your MariaDB server:
- Start the MariaDB shell by running the command:
sudo mysql
- Once in the MariaDB shell, 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 by running the following command:
DELETE FROM mysql.user WHERE User='';
- Disallow remote root login to enhance security. Run the following command:
DELETE FROM mysql.user WHERE User='root' AND Host NOT IN ('localhost', '127.0.0.1', '::1');
- Remove the test database, which is a potential security risk, with the command:
DROP DATABASE IF EXISTS test;
- Reload the privileges to apply the changes:
FLUSH PRIVILEGES;
- Finally, exit the MariaDB shell by typing:
EXIT;
Step 6: 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:
sudo mysql -u root -p
Enter the password you set for the root user during the installation process.
- In the MariaDB shell, create a new database by running the command:
CREATE DATABASE your_database_name;
Replace 'your_database_name'
with the desired name for your database.
- Create a new user by executing the following command:
CREATE USER your_username@localhost IDENTIFIED BY 'your_password';
Replace 'your_username'
with the desired username and 'your_password'
with a strong password for the user.
- Grant all privileges on the database to the user with the command:
GRANT ALL ON your_database_name.* TO your_username@localhost;
Replace 'your_database_name'
and 'your_username'
with the actual names you chose.
- To apply the changes, run:
FLUSH PRIVILEGES;
- Exit the MariaDB shell:
EXIT;
Step 7: Accessing the Database
To access the MariaDB server with the newly created database and user, use the following command:
mysql -u your_username -p your_database_name
Replace 'your_username'
with the username you created and 'your_database_name'
with the name of your database.
Additional Information
At Shape.host, we offer reliable and scalable cloud hosting solutions, including Linux SSD VPS. Our services are designed to meet the needs of businesses looking for efficient and secure hosting solutions. Whether you’re a small startup or a large enterprise, our team of experts is here to support you in achieving your goals.
In conclusion, installing MariaDB on AlmaLinux 9 is a straightforward process that can be completed by following these steps. By securing your MariaDB server and creating databases and users, you can leverage the power of this robust database management system for your applications. Remember to regularly update and maintain your MariaDB installation for optimal performance and security.