MariaDB is a powerful, open-source relational database system widely used as a drop-in replacement for MySQL. It offers enhanced performance, security features, and enterprise-ready capabilities.
However, running MariaDB on a Linux server without proper hardening can expose sensitive data to cyber threats. To protect your database, it is essential to monitor and secure MariaDB on Linux using best practices, configurations, and continuous monitoring strategies.
Why Securing MariaDB on Linux is Critical?

Databases store critical application and business data, making them prime targets for attackers. Without proper security, unauthorized users can steal or manipulate data, disrupt services, or compromise entire systems.
Securing MariaDB ensures data integrity, prevents breaches, and maintains compliance with industry standards. Implementing structured security measures and monitoring systems is the foundation of a reliable MariaDB environment.
Step 1: Keep MariaDB and Linux System Updated
Keeping your database and operating system updated is the first step in minimizing vulnerabilities. Updates fix bugs and patch security flaws that attackers often exploit.
- On Ubuntu/Debian:
sudo apt update && sudo apt upgrade mariadb-server
- On CentOS/RHEL:
sudo yum update mariadb-server
Automate updates with cron jobs or system utilities to ensure you always have the latest security patches applied.
Step 2: Run the MariaDB Secure Installation Script
MariaDB includes a script to improve security and eliminate weak defaults. Running it immediately after installation is highly recommended.
sudo mysql_secure_installation
This script allows you to:
- Set a strong root password.
- Remove anonymous users.
- Disable remote root logins.
- Remove test databases.
- Reload privilege tables.
Executing this tool provides a secure baseline and prevents common exploits on newly installed servers.
Also, Read | How to Install MariaDB on a Linux Server
Step 3: Implement Strong Authentication and User Management
Proper user management prevents unauthorized access and limits the impact of potential breaches.
- Create dedicated users for each application instead of using root:
CREATE USER 'appuser'@'localhost' IDENTIFIED BY 'StrongPass@123';
GRANT SELECT, INSERT, UPDATE, DELETE ON appdb.* TO 'appuser'@'localhost';
FLUSH PRIVILEGES;
Key practices include:
- Using complex passwords or authentication plugins like
mysql_native_password
orcaching_sha2_password
. - Granting only necessary privileges (principle of least privilege).
- Regularly auditing accounts and removing unused users.
Step 4: Secure MariaDB Configuration
The my.cnf
configuration file controls MariaDB behavior. Adjusting its settings prevents unauthorized access and strengthens security.
Recommended settings:
[mysqld]
bind-address = 127.0.0.1
skip-symbolic-links
local-infile = 0
- bind-address restricts MariaDB to local connections unless remote access is explicitly required.
- skip-symbolic-links prevents exploitation of filesystem links.
- local-infile = 0 disables the
LOAD DATA LOCAL
feature, which can be misused for SQL injection attacks.
Also, Read | Step-by-Step: Configure MariaDB on Linux Server
Step 5: Enable SSL/TLS Encryption
Unencrypted traffic can be intercepted, leading to data leaks. Enabling SSL/TLS ensures all client-server communication is encrypted.
- Generate SSL certificates and update
my.cnf
:
[mysqld]
ssl-ca=/etc/mysql/ssl/ca.pem
ssl-cert=/etc/mysql/ssl/server-cert.pem
ssl-key=/etc/mysql/ssl/server-key.pem
- Require SSL for users connecting remotely:
ALTER USER 'appuser'@'%' REQUIRE SSL;
This ensures that sensitive information, including credentials and queries, cannot be intercepted during transmission.
Step 6: Firewall and Network Restrictions
Limiting access to MariaDB reduces exposure to external threats.
- UFW (Ubuntu/Debian):
sudo ufw allow from 192.168.1.50 to any port 3306
- Firewalld (CentOS/RHEL):
sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="192.168.1.50" port protocol="tcp" port="3306" accept'
sudo firewall-cmd --reload
Never expose MariaDB’s default port (3306) directly to the internet. Use VPNs or SSH tunnels for remote connections whenever possible.
Step 7: Monitor MariaDB Logs and Performance
Monitoring MariaDB logs is crucial for identifying suspicious activity and maintaining database health.
- Key log files:
- Error log:
/var/log/mysql/error.log
- General query log: Tracks all executed queries.
- Slow query log: Highlights inefficient or long-running queries.
- Error log:
- Recommended monitoring tools:
- Percona Monitoring and Management (PMM) for performance analytics.
- Grafana + Prometheus dashboards for resource and query monitoring.
- Nagios/Zabbix for uptime and alert notifications.
Consistent monitoring enables proactive detection of intrusions, query issues, and unusual patterns.
Step 8: Backup and Disaster Recovery
Even a secured database is vulnerable to human error, software failures, or ransomware attacks. Regular backups ensure quick recovery.
- Using
mysqldump
:
mysqldump -u root -p appdb > appdb_backup.sql
- Using
mysqlpump
: Faster, parallelized backups. - Percona XtraBackup: Enables hot backups without downtime.
Backups should be encrypted, stored securely, and tested periodically to ensure recovery reliability.
Step 9: Automate Security and Auditing
Manual security management is prone to mistakes. Automation ensures continuous protection and consistent monitoring.
- Cron jobs: Automate backups, log rotation, and updates.
- Audit plugins: Use MariaDB audit plugins to track user actions.
- Configuration management tools: Ansible or Puppet can enforce security policies across multiple servers.
Automated auditing also helps meet compliance requirements and provides detailed activity records for review.
Best Practices to Secure MariaDB on Linux
Securing MariaDB is an ongoing process. Following best practices helps maintain a robust database environment and reduces the risk of breaches:
- Apply the principle of least privilege to all users.
- Regularly perform vulnerability scans and penetration testing.
- Use IDS/IPS tools such as OSSEC or Snort to detect intrusions.
- Rotate passwords and update SSL/TLS certificates periodically.
- Maintain an incident response plan to recover quickly from security events.
Consistent adherence to these practices ensures your MariaDB server remains resilient and secure.
Conclusion
MariaDB is a reliable, high-performance database, but without proper hardening, it is vulnerable to cyberattacks. By applying updates, running the secure installation script, enforcing strong authentication, enabling SSL, configuring firewalls, monitoring logs, and automating backups, administrators can protect critical data effectively.
The best way to secure MariaDB on Linux is through a layered approach combining configuration hardening, network security, encryption, monitoring, and automation. This ensures your database remains safe, performant, and ready to support applications reliably.