How to Install Mariadb
How to Install MariaDB: A Complete Step-by-Step Guide for Developers and System Administrators MariaDB is a community-developed, open-source relational database management system (RDBMS) that serves as a drop-in replacement for MySQL. Originally created by the original developers of MySQL, MariaDB was designed to remain free and open under the GNU General Public License, ensuring long-term stabili
How to Install MariaDB: A Complete Step-by-Step Guide for Developers and System Administrators
MariaDB is a community-developed, open-source relational database management system (RDBMS) that serves as a drop-in replacement for MySQL. Originally created by the original developers of MySQL, MariaDB was designed to remain free and open under the GNU General Public License, ensuring long-term stability, performance improvements, and enhanced security features. As organizations increasingly prioritize data integrity, scalability, and cost-efficiency, MariaDB has emerged as one of the most trusted database solutions for web applications, enterprise systems, and cloud-native environments.
Installing MariaDB correctly is a foundational skill for developers, DevOps engineers, and system administrators. Whether you're setting up a local development environment, deploying a production server, or migrating from MySQL, understanding the installation process ensures optimal configuration, security, and performance from day one. This guide provides a comprehensive, step-by-step walkthrough of how to install MariaDB across major operating systems, including Ubuntu, CentOS, Debian, and Windows. We’ll also cover best practices, essential tools, real-world deployment examples, and frequently asked questions to help you avoid common pitfalls and maximize the potential of your database infrastructure.
Step-by-Step Guide
Installing MariaDB on Ubuntu 22.04 / 20.04
Ubuntu is one of the most popular Linux distributions for both development and production environments. Installing MariaDB on Ubuntu is straightforward thanks to its robust package management system.
Begin by updating your system’s package list to ensure you’re working with the latest repository metadata:
sudo apt update
Next, install MariaDB using the APT package manager:
sudo apt install mariadb-server
During installation, the system will automatically create the necessary database files and start the MariaDB service. To verify that the service is running, use:
sudo systemctl status mariadb
You should see output indicating that the service is active (running). If it’s not, start it manually:
sudo systemctl start mariadb
Enable MariaDB to start automatically on boot:
sudo systemctl enable mariadb
After installation, run the built-in security script to harden your database installation:
sudo mysql_secure_installation
This script will prompt you to set a root password, remove anonymous users, disable remote root login, remove the test database, and reload privilege tables. Follow the on-screen instructions carefully — selecting “Y” (yes) for all security recommendations is advised for production environments.
To access the MariaDB shell as the root user, type:
sudo mysql
You’ll be logged in without a password because Ubuntu uses socket authentication by default for the root user. To verify your version and connection status, run:
SELECT VERSION();
Installing MariaDB on CentOS 8 / 9 Stream
CentOS is widely used in enterprise environments due to its stability and long-term support. MariaDB is included in the default repositories for CentOS 8 and 9 Stream, making installation simple.
First, update your system:
sudo dnf update -y
Install MariaDB server:
sudo dnf install mariadb-server -y
Start and enable the service:
sudo systemctl start mariadb
sudo systemctl enable mariadb
Verify the service status:
sudo systemctl status mariadb
Secure your installation using the same security script as on Ubuntu:
sudo mysql_secure_installation
Set a strong root password and apply all recommended security settings. Once complete, log in to the MariaDB shell:
mysql -u root -p
Enter your root password when prompted. You can now execute SQL commands and manage databases.
Installing MariaDB on Debian 12 / 11
Debian is known for its strict adherence to free software principles and stability, making it ideal for mission-critical deployments. MariaDB is available in Debian’s main repositories.
Update your package index:
sudo apt update
Install MariaDB:
sudo apt install mariadb-server
Start and enable the service:
sudo systemctl start mariadb
sudo systemctl enable mariadb
Check the status to confirm successful startup:
sudo systemctl status mariadb
Run the security script:
sudo mysql_secure_installation
Follow the prompts to secure your installation. Then access the MariaDB prompt:
sudo mysql
Debian, like Ubuntu, uses socket authentication for root. If you need to authenticate via password, you’ll need to modify the authentication plugin (covered in the Best Practices section).
Installing MariaDB on Windows
While Linux is the preferred platform for server deployments, MariaDB is also fully supported on Windows for development and testing purposes.
Visit the official MariaDB download page: https://mariadb.org/download/
Select the Windows (64-bit) installer under the “Stable MariaDB Server” section. Choose the MSI installer for a guided installation process.
Launch the installer and follow the wizard:
- Select “Server only” if you’re installing for backend use.
- Choose the installation directory (default is recommended).
- Configure the root password when prompted — make sure it’s strong and securely stored.
- Enable “Install as Windows Service” to ensure MariaDB starts automatically on boot.
- Complete the installation.
After installation, open the Windows Services manager (services.msc) and verify that “MariaDB” is listed and running. If not, right-click and select “Start.”
To access MariaDB via command line, open Command Prompt or PowerShell and navigate to the MariaDB bin directory:
cd "C:\Program Files\MariaDB 11.4\bin"
Then connect:
mysql -u root -p
Enter your root password to begin managing databases.
Installing MariaDB on macOS
macOS users can install MariaDB via Homebrew, the most popular package manager for macOS.
First, ensure Homebrew is installed. If not, run:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Then install MariaDB:
brew install mariadb
Start the service:
brew services start mariadb
Verify the installation:
brew services list
Secure the installation:
mysql_secure_installation
Log in to the MariaDB shell:
mysql -u root -p
On macOS, you may need to add MariaDB to your PATH if the mysql command isn’t recognized. Add this line to your shell profile (~/.zshrc or ~/.bash_profile):
export PATH="/opt/homebrew/bin:$PATH"
Then reload your shell:
source ~/.zshrc
Best Practices
Use Strong Passwords and Limit Root Access
One of the most critical steps in securing MariaDB is enforcing strong authentication. Avoid using default or weak passwords. The mysql_secure_installation script helps, but you should also manually verify the root user’s password policy.
To enforce password strength, enable the password validation plugin:
INSTALL PLUGIN validate_password SONAME 'validate_password.so';
Then configure minimum requirements:
SET GLOBAL validate_password.policy = MEDIUM;
SET GLOBAL validate_password.length = 12;
Never use the root account for application connections. Create dedicated users with minimal privileges:
CREATE USER 'appuser'@'localhost' IDENTIFIED BY 'StrongP@ssw0rd123!';
GRANT SELECT, INSERT, UPDATE, DELETE ON myapp_db.* TO 'appuser'@'localhost';
FLUSH PRIVILEGES;
Configure Firewall Rules
By default, MariaDB listens on port 3306. If your server is exposed to the internet, restrict access using a firewall.
On Ubuntu or Debian with UFW:
sudo ufw allow from 192.168.1.0/24 to any port 3306
sudo ufw deny 3306
This allows only internal network traffic. Never expose MariaDB directly to the public internet without a reverse proxy or VPN.
Enable Logging and Monitoring
Enable general query logging and slow query logging for performance tuning and auditing:
Edit the MariaDB configuration file:
sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf
Add or modify these lines under the [mysqld] section:
[mysqld]
slow_query_log = 1
slow_query_log_file = /var/log/mysql/slow-query.log
long_query_time = 2
log_error = /var/log/mysql/error.log
Create the log directory and set permissions:
sudo mkdir -p /var/log/mysql
sudo chown mysql:mysql /var/log/mysql
sudo systemctl restart mariadb
Regularly review logs using tools like grep, awk, or log analysis platforms such as ELK Stack or Grafana Loki.
Optimize Configuration Settings
Default MariaDB settings are conservative and may not be optimal for your workload. Use the MariaDB Tuner script to analyze your configuration and suggest improvements:
wget https://raw.githubusercontent.com/major/MySQLTuner-perl/master/mysqltuner.pl
perl mysqltuner.pl
Common optimizations include:
- Increasing
innodb_buffer_pool_sizeto 70-80% of available RAM on dedicated servers - Setting
max_connectionsbased on expected concurrent users - Enabling query cache (deprecated in newer versions; use InnoDB buffer pool instead)
- Using
thread_cache_sizeto reduce thread creation overhead
Regular Backups
Always implement a backup strategy. Use mysqldump for logical backups:
mysqldump -u root -p myapp_db > myapp_db_backup.sql
For larger databases or production environments, use MariaDB Backup (based on Percona XtraBackup):
sudo apt install mariadb-backup
mariabackup --backup --target-dir=/backup/mariadb --user=root --password=YourPassword
Schedule automated backups using cron:
0 2 * * * /usr/bin/mysqldump -u root -pYourPassword myapp_db > /backups/myapp_db_$(date +\%F).sql
Use SSL/TLS for Remote Connections
If your application connects to MariaDB remotely, enable SSL to encrypt traffic. Generate certificates using OpenSSL or use Let’s Encrypt.
In 50-server.cnf, add:
[mysqld]
ssl-ca=/etc/mysql/certs/ca-cert.pem
ssl-cert=/etc/mysql/certs/server-cert.pem
ssl-key=/etc/mysql/certs/server-key.pem
Restart MariaDB and verify SSL is active:
SHOW VARIABLES LIKE '%ssl%';
Tools and Resources
Command-Line Tools
- mysql – The primary client for connecting to and managing MariaDB instances.
- mysqldump – Used to export database schemas and data in SQL format.
- mysqladmin – Administrative utility for server operations like restarting, status checks, and user management.
- mariabackup – High-performance backup tool for InnoDB and XtraDB tables.
- mysqlcheck – Checks, repairs, and optimizes tables for performance and integrity.
Graphical User Interfaces (GUIs)
- phpMyAdmin – Web-based interface widely used for managing MySQL and MariaDB databases. Easy to install and configure on Apache or Nginx.
- Adminer – Lightweight, single-file alternative to phpMyAdmin with full feature support.
- DBeaver – Cross-platform database tool supporting MariaDB, PostgreSQL, MySQL, and more. Ideal for developers working across multiple database systems.
- HeidiSQL – Windows-only GUI with excellent performance and intuitive UI for managing MariaDB.
Monitoring and Performance Tools
- MariaDB Tuner – Perl script that analyzes your server configuration and suggests optimizations.
- Prometheus + Grafana – Use the
mariadb_exporterto expose metrics and visualize performance in real time. - pt-query-digest – Part of Percona Toolkit, this tool analyzes slow query logs and identifies problematic queries.
- Netdata – Real-time performance monitoring with built-in MariaDB dashboard.
Documentation and Community Resources
- MariaDB Knowledge Base – Official documentation with in-depth guides, configuration examples, and troubleshooting tips.
- MariaDB Foundation – Home of the open-source project, with release notes and governance information.
- Stack Overflow – Search for “MariaDB installation issues” to find community solutions.
- Reddit r/MariaDB – Active community for discussions, tips, and real-world use cases.
Containerized Deployments
For modern DevOps workflows, MariaDB is available as a Docker image:
docker pull mariadb:11.4
docker run --name mariadb-server -e MYSQL_ROOT_PASSWORD=YourStrongPassword -p 3306:3306 -d mariadb:11.4
Use Docker Compose for multi-service applications:
version: '3.8'
services:
db:
image: mariadb:11.4
container_name: mariadb-server
environment:
MYSQL_ROOT_PASSWORD: YourStrongPassword
MYSQL_DATABASE: myapp_db
MYSQL_USER: appuser
MYSQL_PASSWORD: AppUserPassword123!
ports:
- "3306:3306"
volumes:
- ./data:/var/lib/mysql
- ./config/my.cnf:/etc/mysql/conf.d/custom.cnf
restart: unless-stopped
Always use persistent volumes to retain data across container restarts.
Real Examples
Example 1: WordPress Installation with MariaDB on Ubuntu
WordPress, the world’s most popular content management system, requires a database. Here’s how to set up WordPress with MariaDB on Ubuntu 22.04.
- Install MariaDB as shown in the Ubuntu section above.
- Secure the installation with
mysql_secure_installation. - Log into MariaDB:
sudo mysql
- Create a database and user for WordPress:
CREATE DATABASE wordpress_db CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci;
CREATE USER 'wordpress_user'@'localhost' IDENTIFIED BY 'WpStrongP@ss123!';
GRANT ALL PRIVILEGES ON wordpress_db.* TO 'wordpress_user'@'localhost';
FLUSH PRIVILEGES;
EXIT;
- Install Apache and PHP:
sudo apt install apache2 php libapache2-mod-php php-mysql -y
- Download and extract WordPress:
cd /tmp
wget https://wordpress.org/latest.tar.gz
tar -xzf latest.tar.gz
sudo rsync -av wordpress/ /var/www/html/
- Set correct permissions:
sudo chown -R www-data:www-data /var/www/html/
sudo chmod -R 755 /var/www/html/
- Complete the WordPress installation via browser at
http://your-server-ipand enter the database details created earlier.
WordPress will now connect to MariaDB, and your site will be live.
Example 2: E-commerce Backend with Laravel and MariaDB on CentOS
Laravel, a PHP framework, uses MariaDB as its default database. Here’s how to deploy a Laravel application with MariaDB on CentOS 9 Stream.
- Install MariaDB and secure it.
- Create a database for the Laravel app:
CREATE DATABASE laravel_app CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'laravel_user'@'localhost' IDENTIFIED BY 'LaravelP@ss2024!';
GRANT ALL ON laravel_app.* TO 'laravel_user'@'localhost';
FLUSH PRIVILEGES;
- Install PHP 8.2 and Composer:
sudo dnf install php php-mysqlnd php-gd php-mbstring php-xml php-zip -y
curl -sS https://getcomposer.org/installer | php
sudo mv composer.phar /usr/local/bin/composer
- Create a new Laravel project:
composer create-project laravel/laravel /var/www/html/laravel-app
- Configure the database in
/var/www/html/laravel-app/.env:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravel_app
DB_USERNAME=laravel_user
DB_PASSWORD=LaravelP@ss2024!
- Run migrations:
cd /var/www/html/laravel-app
php artisan migrate
Your Laravel application is now connected to MariaDB and ready to handle user data, orders, and product catalogs.
Example 3: High-Availability Setup with Galera Cluster
For mission-critical applications requiring 99.99% uptime, MariaDB Galera Cluster provides synchronous multi-master replication.
Deploy three nodes (Node1, Node2, Node3) with MariaDB 11.4 and Galera. Install on each node:
sudo apt install mariadb-server mariadb-client galera-4
Configure /etc/mysql/mariadb.conf.d/50-server.cnf with:
[mysqld]
wsrep_on=ON
wsrep_provider=/usr/lib/galera/libgalera_smm.so
wsrep_cluster_address=gcomm://NODE1_IP,NODE2_IP,NODE3_IP
wsrep_node_address=THIS_NODE_IP
wsrep_node_name=Node1
wsrep_sst_method=mariabackup
wsrep_sst_auth="sstuser:StrongSSTPassword"
Create a SST user:
CREATE USER 'sstuser'@'%' IDENTIFIED BY 'StrongSSTPassword';
GRANT RELOAD, LOCK TABLES, REPLICATION CLIENT ON *.* TO 'sstuser'@'%';
FLUSH PRIVILEGES;
Start the first node with bootstrap:
sudo galera_new_cluster
Then start MariaDB on the other nodes normally:
sudo systemctl start mariadb
Verify cluster status:
SHOW STATUS LIKE 'wsrep_cluster_size';
Output should show “3” — all nodes are synchronized. This setup ensures zero data loss during node failures.
FAQs
Is MariaDB compatible with MySQL?
Yes, MariaDB is designed as a drop-in replacement for MySQL. It uses the same ports, client libraries, and APIs. Most applications that work with MySQL will work with MariaDB without code changes. However, some advanced MySQL features (like Oracle-specific plugins) may not be available.
Can I upgrade from MySQL to MariaDB without data loss?
Absolutely. You can stop MySQL, install MariaDB, and start it — it will automatically use the existing data directory. Always back up your databases before upgrading. MariaDB includes migration scripts to handle schema compatibility.
Why should I choose MariaDB over MySQL?
MariaDB offers faster performance, more storage engines (like Aria and MyRocks), better thread pooling, and an open governance model. Oracle’s control over MySQL has raised concerns about future licensing and feature development. MariaDB remains fully open-source and community-driven.
How do I reset the root password if I forget it?
Stop the MariaDB service:
sudo systemctl stop mariadb
Start it in safe mode:
sudo mysqld_safe --skip-grant-tables &
Connect without a password:
mysql -u root
Update the password:
FLUSH PRIVILEGES;
ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewStrongPassword!';
EXIT;
Restart the service normally:
sudo systemctl restart mariadb
Does MariaDB support JSON data types?
Yes, MariaDB 10.2+ includes full JSON support, including JSON functions like JSON_EXTRACT, JSON_SET, and indexing on JSON paths. It’s fully compliant with the SQL/JSON standard.
What’s the difference between MariaDB and PostgreSQL?
MariaDB is a MySQL-compatible RDBMS optimized for transactional workloads and web applications. PostgreSQL is a more advanced object-relational database with superior support for complex queries, geospatial data, and custom data types. Choose MariaDB for simplicity and compatibility; choose PostgreSQL for advanced analytics and extensibility.
How do I check if MariaDB is running on my system?
On Linux, use:
sudo systemctl status mariadb
On Windows, open Services and look for “MariaDB.” On macOS:
brew services list
Can I run MariaDB on a Raspberry Pi?
Yes. MariaDB runs efficiently on ARM-based devices like the Raspberry Pi. Install it using the same apt commands as on Ubuntu. It’s ideal for home automation, IoT data logging, and local web servers.
How often should I update MariaDB?
Apply security patches and minor updates monthly. Major version upgrades (e.g., 10.6 → 11.4) should be planned during maintenance windows after thorough testing in a staging environment.
Conclusion
Installing MariaDB is more than just running a single command — it’s the foundation of a secure, scalable, and high-performing data infrastructure. Whether you’re setting up a local development environment, deploying a production web application, or architecting a distributed cluster, following the steps outlined in this guide ensures your database is configured correctly from the start.
By prioritizing security best practices, implementing monitoring tools, and leveraging real-world examples, you’re not just installing software — you’re building resilience into your data layer. MariaDB’s compatibility with MySQL, active community, and continuous innovation make it the ideal choice for modern applications.
As you move forward, remember to back up regularly, monitor performance, and stay updated with the latest releases. The tools and knowledge provided here will serve you whether you’re managing a single server or thousands of database instances across global cloud environments. With MariaDB, you’re not just choosing a database — you’re choosing a future-proof, open, and community-backed platform that empowers developers and organizations worldwide.