How to Install MariaDB on AlmaLinux
Categories:
4 minute read
MariaDB, an open-source relational database management system, is a widely popular alternative to MySQL. Known for its performance, scalability, and reliability, MariaDB is a favored choice for web applications, data warehousing, and analytics. AlmaLinux, a CentOS replacement, offers a stable and secure platform for hosting MariaDB databases.
In this comprehensive guide, we’ll walk you through the steps to install MariaDB on AlmaLinux, configure it for production use, and verify its operation. Whether you’re a beginner or an experienced system administrator, this tutorial has everything you need to get started.
Table of Contents
- Introduction to MariaDB and AlmaLinux
- Prerequisites for Installation
- Installing MariaDB on AlmaLinux
- Installing from Default Repositories
- Installing the Latest Version
- Configuring MariaDB
- Securing the Installation
- Editing Configuration Files
- Starting and Managing MariaDB Service
- Testing the MariaDB Installation
- Creating a Database and User
- Best Practices for MariaDB on AlmaLinux
- Troubleshooting Common Issues
- Conclusion
1. Introduction to MariaDB and AlmaLinux
MariaDB originated as a fork of MySQL and has since gained popularity for its enhanced features, community-driven development, and open-source commitment. AlmaLinux, a RHEL-based distribution, provides an excellent platform for hosting MariaDB, whether for small-scale projects or enterprise-level applications.
2. Prerequisites for Installation
Before installing MariaDB on AlmaLinux, ensure the following:
A running AlmaLinux instance with root or sudo access.
The system is up-to-date:
sudo dnf update -yA basic understanding of Linux commands and database management.
3. Installing MariaDB on AlmaLinux
There are two main approaches to installing MariaDB on AlmaLinux: using the default repositories or installing the latest version from the official MariaDB repositories.
Installing from Default Repositories
Install MariaDB: The default AlmaLinux repositories often include MariaDB. To install it, run:
sudo dnf install -y mariadb-serverVerify Installation: Check the installed version:
mariadb --versionOutput example:
mariadb 10.3.29
Installing the Latest Version
If you require the latest version, follow these steps:
Add the Official MariaDB Repository: Visit the MariaDB repository page to find the latest repository for your AlmaLinux version. Create a repository file:
sudo nano /etc/yum.repos.d/mariadb.repoAdd the following contents (replace
10.11with the desired version):[mariadb] name = MariaDB baseurl = http://yum.mariadb.org/10.11/rhel8-amd64 gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=1Save and exit the file.
Install MariaDB:
sudo dnf install -y MariaDB-server MariaDB-clientVerify Installation:
mariadb --version
4. Configuring MariaDB
After installation, some configuration steps are required to secure and optimize MariaDB.
Securing the Installation
Run the security script to improve MariaDB’s security:
sudo mysql_secure_installation
The script will prompt you to:
- Set the root password.
- Remove anonymous users.
- Disallow root login remotely.
- Remove the test database.
- Reload privilege tables.
Answer “yes” to these prompts to ensure optimal security.
Editing Configuration Files
The MariaDB configuration file is located at /etc/my.cnf. You can customize settings based on your requirements.
Edit the File:
sudo nano /etc/my.cnfOptimize Basic Settings: Add or modify the following for better performance:
[mysqld] bind-address = 0.0.0.0 max_connections = 150 query_cache_size = 16M- bind-address: Allows remote connections. Change to the server’s IP for security.
- max_connections: Adjust based on expected traffic.
- query_cache_size: Optimizes query performance.
Save and Restart MariaDB:
sudo systemctl restart mariadb
5. Starting and Managing MariaDB Service
MariaDB runs as a service, which you can manage using systemctl.
Start MariaDB:
sudo systemctl start mariadbEnable MariaDB to Start on Boot:
sudo systemctl enable mariadbCheck Service Status:
sudo systemctl status mariadb
6. Testing the MariaDB Installation
Log in to the MariaDB Shell:
sudo mysql -u root -pEnter the root password set during the
mysql_secure_installationprocess.Check Server Status: Inside the MariaDB shell, run:
SHOW VARIABLES LIKE "%version%";This displays the server’s version and environment details.
Exit the Shell:
EXIT;
7. Creating a Database and User
Log in to MariaDB:
sudo mysql -u root -pCreate a New Database:
CREATE DATABASE my_database;Create a User and Grant Permissions:
CREATE USER 'my_user'@'%' IDENTIFIED BY 'secure_password'; GRANT ALL PRIVILEGES ON my_database.* TO 'my_user'@'%'; FLUSH PRIVILEGES;Exit the Shell:
EXIT;
8. Best Practices for MariaDB on AlmaLinux
Regular Updates: Keep MariaDB and AlmaLinux updated:
sudo dnf update -yAutomate Backups: Use tools like
mysqldumpormariabackupfor regular backups:mysqldump -u root -p my_database > my_database_backup.sqlSecure Remote Connections: Use SSL/TLS for encrypted connections to the database.
Monitor Performance: Utilize monitoring tools like
MySQLTunerto optimize the database’s performance:perl mysqltuner.plSet Resource Limits: Configure resource usage to avoid overloading the system.
9. Troubleshooting Common Issues
MariaDB Fails to Start:
Check the logs for errors:
sudo tail -f /var/log/mariadb/mariadb.logVerify the configuration file syntax.
Access Denied Errors:
Ensure proper user privileges and authentication:
SHOW GRANTS FOR 'my_user'@'%';
Remote Connection Issues:
Verify
bind-addressin/etc/my.cnfis set correctly.Ensure the firewall allows MariaDB traffic:
sudo firewall-cmd --permanent --add-service=mysql sudo firewall-cmd --reload
10. Conclusion
Installing MariaDB on AlmaLinux is a straightforward process, whether you use the default repositories or opt for the latest version. Once installed, securing and configuring MariaDB is essential to ensure optimal performance and security. By following this guide, you now have a functional MariaDB setup on AlmaLinux, ready for use in development or production environments. Regular maintenance, updates, and monitoring will help you keep your database system running smoothly for years to come.
Feedback
Was this page helpful?
Glad to hear it! Please tell us how we can improve.
Sorry to hear that. Please tell us how we can improve.