Introduction
MariaDB is an open-source relational database management system derived from MySQL, which has gained popularity in Linux environments due to its performance, scalability, and compatibility. In this article we will show you step by step how to install, configure, and optimize MariaDB on the most used Linux distributions, ensuring that your database is ready for production environments.
Why Choose MariaDB on Linux
Choosing MariaDB on a Linux server offers several advantages. It is fully compatible with MySQL, allowing you to migrate applications without significant changes. Its InnoDB engine and improvements in complex queries provide superior performance in mixed workloads. The active community and frequent updates guarantee security and long-term support. Additionally, its GPL license eliminates licensing costs, making it ideal for startups and companies looking to reduce operational expenses.
Prerequisites
Before starting, make sure you have root or sudo access on your Linux machine, a stable internet connection, and at least 2 GB of free RAM. Verify that your distribution is up to date by running the corresponding update commands (apt update && upgrade for Debian/Ubuntu, dnf update for Fedora, yum update for CentOS/RHEL). Having a text editor like nano or vim will make editing configuration files easier.
Installation on Ubuntu and Debian
On Ubuntu and Debian, the installation process is simple thanks to the official repositories. Open a terminal and run: sudo apt update; sudo apt install mariadb-server
During installation, you will be prompted to set a password for the MariaDB root user. Once finished, the service starts automatically. You can check its status with: sudo systemctl status mariadb
If the service is not active, start it and enable it to start on each system boot: sudo systemctl start mariadb; sudo systemctl enable mariadb
Installation on CentOS and RHEL
On CentOS and RHEL, MariaDB is available in the standard repositories. First, install the package: sudo yum install mariadb-server mariadb
Then start and enable the service: sudo systemctl start mariadb; sudo systemctl enable mariadb
To improve security, run the included security script: sudo mysql_secure_installation
This script will guide you to set a root password, remove anonymous users, disable remote root access, and delete the test database.
Installation on Fedora
On Fedora, the package manager is dnf. Installation is done as follows: sudo dnf install mariadb-server
Afterwards, start and enable the service: sudo systemctl start mariadb; sudo systemctl enable mariadb
As with other distributions, it is recommended to run mysql_secure_installation to fine-tune the security configuration.
Basic Configuration
After installation, it is advisable to adjust the main configuration file, usually located at /etc/mysql/mariadb.conf.d/50-server.cnf (on Debian/Ubuntu) or /etc/my.cnf.d/mariadb-server.cnf (on RHEL/CentOS/Fedora). Some useful parameters to start with are:
- bind-address = 0.0.0.0 # allows connections from any IP (adjust according to your needs)
- port = 3306
- max_connections = 150
- innodb_buffer_pool_size = 1G # adjust according to available RAM
After modifying the file, restart the service: sudo systemctl restart mariadb
Performance Optimization
To get the most out of MariaDB on Linux, consider these optimizations:
- Increase innodb_buffer_pool_size to 60-70% of total RAM if the server is dedicated to the database.
- Enable query cache query_cache_type only if your workload is predominantly read and you have sufficient memory.
- Set innodb_log_file_size to an appropriate value (e.g., 256M) to reduce frequent checkpoints.
- Use partitioned tables for large data volumes and improve query times.
- Monitor performance with tools like mysqltuner or Percona Monitoring and Management (PMM).
Essential Security
The security of MariaDB should not be underestimated. Apply these best practices:
- Run mysql_secure_installation after installation.
- Restrict access to port 3306 via firewalld or ufw, allowing only trusted IPs.
- Use SSL/TLS encrypted connections to prevent interception.
- Regularly update the mariadb-server package to receive security patches.
- Audit user privileges and remove unnecessary accounts.
- Enable error logging and slow query logging to detect anomalies.
Backups and Restoration
Performing periodic backups is critical. The simplest method is to use mysqldump:
- Backup of a specific database:
mysqldump -u root -p nombre_base > respaldo_nombre_base.sql
- Backup of all databases:
mysqldump -u root -p --all-databases > respaldo_completo.sql
To restore, simply run:
mysql -u root -p nombre_base < respaldo_nombre_base.sql
Consider automating these tasks with cron and storing backups in a remote location or cloud storage services.
Conclusion
MariaDB has established itself as a robust and free option for managing databases in Linux environments. Its easy installation, compatibility with MySQL, and wide set of optimization and security tools make it suitable for both developers and system administrators. By following the steps described in this article, you will have a production-ready MariaDB server with good performance and the necessary security measures to protect your information.