MariaDB has quickly become one of the most popular open source database solutions, with over 60 million downloads to date. As a database analyst and Linux enthusiast, I‘m excited to provide an in-depth guide on installing, configuring, optimizing, and securing MariaDB on Ubuntu and CentOS.
Why MariaDB?
Before we get into the technical details, let‘s discuss why MariaDB is worth your time in the first place:
-
100% open source and community developed – this ensures transparency and collaboration.
-
Strong compatibility with MySQL – makes migration easy. MariaDB enhancements are designed to be non-disruptive.
-
Improved performance – benchmarks show MariaDB outperforming MySQL by an average of 5-10% on the SysBench test suite.
-
Feature enhancements – MariaDB introduces engine-independent columnar storage, temporary tables, advanced GTIDs, and more.
-
Commercial support available – MariaDB Corporation provides enterprise support subscriptions like MySQL. You get the best of both worlds!
According to DB-Engines rankings, MariaDB now holds 11.4% market share, while MySQL has 33.8%. MariaDB adoption is clearly growing strong. As a FOSS advocate, I‘m delighted to see its success!
Step-by-Step Installation Guide
Let‘s get started with installing MariaDB on our Ubuntu 20.04 and CentOS 7/8 systems. I‘ll be demonstrating the steps on freshly provisioned VMs.
Installing on Ubuntu 20.04
First, we refresh our package index to ensure we download the latest package versions:
sudo apt update
Now, we install the MariaDB server package:
sudo apt install mariadb-server
The apt manager will take care of installing MariaDB along with any required dependencies. Easy as pie!
Once the installation completes, MariaDB service will start automatically. We can verify using:
sudo systemctl status mariadb
Installing on CentOS 7
On CentOS, I prefer installing MariaDB‘s latest release. The version in default CentOS 7 repos is too old.
Adding MariaDB‘s repo is simple. Just download and run their repo setup script:
sudo yum install wget
wget https://downloads.mariadb.com/MariaDB/mariadb_repo_setup
chmod +x mariadb_repo_setup
sudo ./mariadb_repo_setup
Alternatively, you can manually create the repo file at /etc/yum.repos.d/MariaDB.repo. The script is just more convenient.
With the repo added, installing MariaDB is a breeze:
sudo yum install MariaDB-server
Unlike Ubuntu, the service doesn‘t start automatically. We‘ll have to start it manually:
sudo systemctl start mariadb
sudo systemctl enable mariadb
Installing on CentOS 8
On CentOS 8, MariaDB versions 10.3+ are available in the default AppStream repo. We can just install it using dnf:
sudo dnf install mariadb-server
Then start and enable the service:
sudo systemctl enable --now mariadb
That‘s all we need to get MariaDB running on CentOS 8!
The installation steps are pretty straightforward on all three distros. In just a few minutes, we have MariaDB ready for action.
Post-Installation Security Hardening
An important step after installing MariaDB is securing it properly. The mysql_secure_installation script helps automate this:
sudo mysql_secure_installation
It allows us to:
- Set root password
- Remove anonymous user accounts
- Disable remote root login
- Remove test database
- Reload privileges
I also strongly recommend creating a separate user account for your apps to interact with MariaDB. Don‘t use the root account directly.
Optimizing for Performance
Now let‘s discuss tuning MariaDB for optimal efficiency and performance. This can get complex, so I‘ll stick to the key areas.
Operating System Optimization
There are several OS parameters we can tweak:
-
Use noop/deadline IO scheduler – improves MariaDB I/O performance.
-
Increase open files limit – allows MariaDB to open more files. Set to 65535 in /etc/security/limits.conf.
-
Allow core dumps – helps debugging by allowing core dump files. Set core file size to unlimited in /etc/security/limits.conf.
-
Lower swappiness – reduces memory swapping for MariaDB processes. Set vm.swappiness to 1 in sysctl.conf.
-
Mount MariaDB disks noatime – prevents unnecessary writes by not logging access times.
MariaDB Configuration Tuning
The main config file is my.cnf. Important tuning parameters include:
-
innodb_buffer_pool_size – Set to 70-80% of total RAM for best efficiency.
-
innodb_log_file_size – Increase for higher write throughput.
-
innodb_io_capacity – Higher values improve IOPS on SSD storage.
There are many more options for tuning based on your specific workload and hardware. I suggest reviewing the official MariaDB knowledgebase.
Query Optimization
-
Add indexes on frequently filtered columns.
-
Analyze slow queries and optimize them to improve performance.
-
Benchmark with tools like SysBench to identify bottlenecks.
Backups and Replication
Since data is a crucial asset, we must plan for disaster recovery:
-
Take regular backups using mysqldump. Store them external to server.
-
Setup replication to create hot standby secondaries.
-
Consider MariaDB Galera cluster for multi-master clustering.
Automated backups and replication are vital for high availability. Test restores regularly!
Closing Thoughts
I hope this guide provided you a comprehensive overview of installing, configuring, optimizing and securing MariaDB on Linux servers. While I‘ve only scratched the surface, these best practices will give you a solid foundation.
If you‘re currently running MySQL, consider migrating to MariaDB. The process is generally smooth, and you can achieve significant performance gains. As an open source advocate, I encourage you to give MariaDB a try. And as always, feel free to ping me with any database-related topics you‘d like me to cover!