How to Install Mariadb

How to Install MariaDB: A Complete Step-by-Step Guide for Developers and System Administrators MariaDB is a powerful, open-source relational database management system (RDBMS) that originated as a fork of MySQL in 2009. Developed by the original creators of MySQL and maintained by the MariaDB Foundation, it was created to ensure continued openness and community-driven development after Oracle’s ac

Nov 10, 2025 - 12:21
Nov 10, 2025 - 12:21
 0

How to Install MariaDB: A Complete Step-by-Step Guide for Developers and System Administrators

MariaDB is a powerful, open-source relational database management system (RDBMS) that originated as a fork of MySQL in 2009. Developed by the original creators of MySQL and maintained by the MariaDB Foundation, it was created to ensure continued openness and community-driven development after Oracles acquisition of MySQL. Today, MariaDB is widely adopted by enterprises, startups, and developers alike due to its high performance, scalability, compatibility with MySQL, and robust feature setincluding advanced storage engines, enhanced security, and improved query optimization.

Installing MariaDB correctly is a foundational step for deploying web applications, data analytics platforms, content management systems (like WordPress and Drupal), and enterprise software. Whether youre setting up a local development environment, provisioning a production server, or migrating from MySQL, understanding how to install MariaDB securely and efficiently is critical. This guide provides a comprehensive, step-by-step walkthrough for installing MariaDB across major operating systems, followed by best practices, essential tools, real-world examples, and answers to frequently asked questions.

By the end of this tutorial, youll have the knowledge and confidence to install MariaDB on Linux, Windows, and macOS systems, configure it for optimal performance, secure it against common threats, and troubleshoot common installation issuesall while adhering to industry-standard best practices.

Step-by-Step Guide

Installing MariaDB on Ubuntu and Debian

Ubuntu and Debian are among the most popular Linux distributions for server deployments. Installing MariaDB on these systems is straightforward using the APT package manager.

Begin by updating your systems package list to ensure youre working with the latest repository metadata:

sudo apt update

Next, install MariaDB using the following command:

sudo apt install mariadb-server

The installation process will automatically create the necessary system user and service files. Once complete, start the MariaDB service and enable it to launch at boot:

sudo systemctl start mariadb

sudo systemctl enable mariadb

To verify that MariaDB is running, check its service status:

sudo systemctl status mariadb

You should see output indicating that the service is active and running. Next, run the built-in security script to harden your installation:

sudo mysql_secure_installation

This script will guide you through setting a root password, removing anonymous users, disabling remote root login, removing the test database, and reloading privilege tables. Follow the prompts and select Y for each security enhancement unless you have specific requirements.

Finally, test your installation by logging into the MariaDB shell:

sudo mysql -u root -p

Enter the root password you just set. You should see the MariaDB prompt:

Welcome to the MariaDB monitor.  Commands end with ; or \g.

Your MariaDB connection id is 12345

Server version: 11.4.2-MariaDB-1:11.4.2+maria~ubu2204 mariadb.org binary distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]>

Type EXIT; or \q to exit the shell.

Installing MariaDB on CentOS, RHEL, and Fedora

Red Hat-based distributions use the DNF (or YUM on older versions) package manager. MariaDB is available in the default repositories, but for the latest stable version, its recommended to use the official MariaDB repository.

First, add the official MariaDB repository. For CentOS 8 or RHEL 8, use:

sudo dnf install wget

sudo wget https://downloads.mariadb.com/MariaDB/mariadb_repo_setup

sudo bash mariadb_repo_setup --mariadb-server-version="mariadb-11.4"

For CentOS 7 or RHEL 7, use:

sudo yum install wget

sudo wget https://downloads.mariadb.com/MariaDB/mariadb_repo_setup

sudo bash mariadb_repo_setup --mariadb-server-version="mariadb-11.4"

For Fedora, the process is similar:

sudo dnf install wget

sudo wget https://downloads.mariadb.com/MariaDB/mariadb_repo_setup

sudo bash mariadb_repo_setup --mariadb-server-version="mariadb-11.4"

After adding the repository, install MariaDB:

sudo dnf install mariadb-server

Start and enable the service:

sudo systemctl start mariadb

sudo systemctl enable mariadb

Verify the service status:

sudo systemctl status mariadb

Run the security script to secure your installation:

sudo mysql_secure_installation

Set a strong root password and answer Y to all recommended security prompts. Then test the login:

sudo mysql -u root -p

If successful, youll be presented with the MariaDB command-line interface.

Installing MariaDB on macOS

macOS users have multiple options for installing MariaDB, including Homebrew (recommended), MacPorts, or manual installation via DMG. Homebrew is the most popular and reliable method.

First, ensure Homebrew is installed. If not, open Terminal and run:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Once Homebrew is ready, install MariaDB:

brew install mariadb

After installation, start the service:

brew services start mariadb

Alternatively, you can start MariaDB manually using:

mysql.server start

Run the security script to configure your installation:

mysql_secure_installation

Set a root password and follow the prompts to remove insecure defaults. Test your installation:

mysql -u root -p

On macOS, MariaDB is typically configured to use the socket file located at /tmp/mysql.sock. If you encounter connection errors, ensure the socket path is correctly referenced in your client configuration or use --socket=/tmp/mysql.sock when connecting.

Installing MariaDB on Windows

Windows users can install MariaDB using the official Windows installer, which provides a graphical interface for setup.

Visit the official MariaDB download page and select the latest stable version under Windows (x86_64). Download the MSI installer.

Double-click the downloaded file to launch the installer. Follow the wizard:

  • Select Developer Default for a standard setup, or Server Only for a minimal installation.
  • Choose the installation directory (default is recommended).
  • Configure the server: Set a root password (ensure its strong), and enable the Windows service to start automatically.
  • Complete the installation.

Once installed, MariaDB will automatically start as a Windows service. To verify, open the Services app (services.msc) and look for MariaDB. Its status should be Running.

To access MariaDB via command line, open Command Prompt or PowerShell and type:

mysql -u root -p

Enter your root password when prompted. You can also use MySQL Workbench or DBeaver for a graphical interface.

For advanced users, you can manually configure MariaDB by editing the my.ini file located in the installation directory (typically C:\Program Files\MariaDB 11.4\data\).

Verifying Your Installation

Regardless of your operating system, verifying your MariaDB installation is essential. Use the following methods to confirm everything is working correctly:

  • Check version: In the MariaDB shell, run SELECT VERSION();
  • Check running processes: On Linux/macOS, use ps aux | grep mysqld or pgrep mariadb. On Windows, use Task Manager or tasklist | findstr mariadb.
  • Test connectivity: From another machine on the same network, attempt to connect using the servers IP address: mysql -h [IP] -u [user] -p (ensure remote access is enabled in configuration).
  • Check ports: MariaDB uses port 3306 by default. Use netstat -tlnp | grep 3306 (Linux) or netstat -an | findstr 3306 (Windows) to confirm the port is listening.

Successful verification confirms that MariaDB is installed, running, and ready for database creation and application integration.

Best Practices

Use Strong Passwords and Limit Root Access

The root account in MariaDB has full administrative privileges. Never use it for application connections or expose it to the internet. Always create dedicated database users with minimal required permissions using the CREATE USER and GRANT commands. For example:

CREATE USER 'appuser'@'localhost' IDENTIFIED BY 'StrongP@ssw0rd!2024';

GRANT SELECT, INSERT, UPDATE, DELETE ON myapp_db.* TO 'appuser'@'localhost';

FLUSH PRIVILEGES;

Use password managers or secret vaults to store credentials securely. Avoid hardcoding passwords in application source code.

Enable SSL/TLS for Encrypted Connections

By default, MariaDB connections are unencrypted. In production environments, always enable SSL to protect data in transit. MariaDB includes built-in SSL support. Generate certificates using OpenSSL or use Lets Encrypt for free certificates.

To enable SSL, edit your MariaDB configuration file (/etc/mysql/mariadb.conf.d/50-server.cnf on Linux or my.ini on Windows) and 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 the service after making changes. Verify SSL is active by connecting and running:

SHOW VARIABLES LIKE '%ssl%';

Ensure have_ssl is set to YES.

Configure Resource Limits and Performance Tuning

Optimize MariaDB for your workload by adjusting key parameters in the configuration file. Common settings include:

  • innodb_buffer_pool_size: Set to 7080% of available RAM on dedicated database servers.
  • max_connections: Increase from default 151 to 200500 based on application needs.
  • query_cache_type and query_cache_size: Disable query cache in MariaDB 10.5+; its deprecated.
  • tmp_table_size and max_heap_table_size: Set to 64M256M to prevent disk-based temporary tables.

Use the SHOW VARIABLES; command to review current settings and SHOW STATUS; to monitor performance metrics like threads_connected, questions, and slow_queries.

Regular Backups and Point-in-Time Recovery

Implement automated backups using mysqldump or mariabackup (for physical backups). For example, to create a daily backup:

mysqldump -u root -p --all-databases > /backup/mariadb-full-$(date +%F).sql

Schedule backups using cron (Linux/macOS) or Task Scheduler (Windows). For point-in-time recovery, enable binary logging:

[mysqld]

log_bin = /var/log/mysql/mariadb-bin

expire_logs_days = 7

Use mysqlbinlog to replay transactions from the binary log for recovery.

Keep MariaDB Updated

Security vulnerabilities are patched regularly. Subscribe to the MariaDB Foundations security advisories and apply updates promptly. On Ubuntu/Debian:

sudo apt update && sudo apt upgrade

On RHEL/CentOS/Fedora:

sudo dnf update

Always test updates in a staging environment before deploying to production.

Secure File Permissions and Directory Ownership

Ensure MariaDB data directories are owned by the mariadb user and have restrictive permissions:

sudo chown -R mariadb:mariadb /var/lib/mysql

sudo chmod -R 750 /var/lib/mysql

Avoid running MariaDB as root. The service should run under a dedicated, low-privilege system account.

Disable Unnecessary Features

Remove unused plugins, storage engines, and protocols. For example, disable the archive or blackhole engines if not used:

[mysqld]

disabled_storage_engines="Archive,Blackhole"

Also, disable local infile if not needed to prevent potential data exfiltration attacks:

local-infile=0

Tools and Resources

Official Documentation

The MariaDB Knowledge Base is the most authoritative resource for configuration, SQL syntax, storage engines, and troubleshooting. It is continuously updated and includes examples, diagrams, and performance tips.

Monitoring Tools

  • MariaDB Enterprise Monitor: A commercial tool offering real-time performance dashboards, query analysis, and alerting.
  • Prometheus + Grafana: Open-source combination for monitoring metrics like queries per second, connection counts, and buffer usage. Use the mariadb_exporter to expose metrics.
  • phpMyAdmin: Web-based GUI for managing databases, users, and tables. Install on a secure subdomain with HTTPS and IP whitelisting.
  • MySQL Workbench: Official GUI tool from Oracle that supports MariaDB connections. Ideal for schema design and query development.
  • DBeaver: Free, universal database tool supporting MariaDB, PostgreSQL, MySQL, and more. Excellent for developers and analysts.

Backup and Recovery Tools

  • mysqldump: Logical backup tool included with MariaDB. Best for small to medium databases.
  • mariabackup: Physical backup tool based on Percona XtraBackup. Supports hot backups and compression. Required for large databases (>100GB).
  • AutoMySQLBackup: Script-based solution for automated daily, weekly, and monthly backups.

Security Auditing Tools

  • MariaDB Audit Plugin: Logs all queries, connections, and privilege changes. Essential for compliance.
  • OpenSCAP: Security compliance scanner that can audit MariaDB configurations against CIS benchmarks.
  • lynis: Linux security auditing tool that checks for insecure MariaDB settings.

Community and Support

Engage with the MariaDB community through:

These resources provide peer support, code examples, and real-world solutions to common problems.

Real Examples

Example 1: Deploying MariaDB for a WordPress Site

WordPress requires a MySQL/MariaDB database to store posts, users, and settings. Heres how to set it up:

  1. Install MariaDB on Ubuntu as described earlier.
  2. Log into MariaDB: sudo mysql -u root -p
  3. Create a database for WordPress:
CREATE DATABASE wordpress_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
  1. Create a dedicated user:
CREATE USER 'wp_user'@'localhost' IDENTIFIED BY 'WpStr0ngP@ss!2024';

GRANT ALL PRIVILEGES ON wordpress_db.* TO 'wp_user'@'localhost';

FLUSH PRIVILEGES;

  1. Exit the shell and proceed with WordPress installation. During setup, enter:
  • Database Name: wordpress_db
  • Username: wp_user
  • Password: WpStr0ngP@ss!2024
  • Database Host: localhost

WordPress will now connect securely to MariaDB. Enable SSL in wp-config.php if your server uses HTTPS.

Example 2: Migrating from MySQL to MariaDB

Many organizations migrate from MySQL to MariaDB for performance gains and open-source assurance. The process is straightforward:

  1. Stop the MySQL service: sudo systemctl stop mysql
  2. Backup your databases: mysqldump -u root -p --all-databases > mysql_backup.sql
  3. Uninstall MySQL: sudo apt remove mysql-server mysql-client
  4. Install MariaDB: sudo apt install mariadb-server
  5. Restore the backup: mysql -u root -p
  6. Verify data integrity: Check tables, users, and application connectivity.

Most applications work without modification since MariaDB maintains near-perfect MySQL compatibility. Test thoroughly before decommissioning the old MySQL server.

Example 3: High Availability Setup with Galera Cluster

For mission-critical applications requiring high availability, deploy MariaDB with Galera Clustera synchronous multi-master replication solution.

Install MariaDB on three servers (node1, node2, node3). Configure each with:

[mysqld]

wsrep_on=ON

wsrep_provider=/usr/lib/galera/libgalera_smm.so

wsrep_cluster_address="gcomm://node1,node2,node3"

wsrep_node_address="node1"

wsrep_node_name="node1"

wsrep_sst_method=mariabackup

wsrep_sst_auth="sstuser:StrongSSTPass"

Start the first node with:

sudo systemctl start mariadb@bootstrap

Then start the other nodes normally:

sudo systemctl start mariadb

Verify cluster status:

SHOW STATUS LIKE 'wsrep_cluster_size';

Output should show 3 for a healthy three-node cluster. This setup ensures zero data loss during node failures.

FAQs

Is MariaDB compatible with MySQL?

Yes, MariaDB is designed to be a drop-in replacement for MySQL. It maintains binary compatibility with MySQL 5.5, 5.6, and 5.7. Most MySQL clients, connectors, and applications (including WordPress, Joomla, and Drupal) work without modification. However, some MySQL-specific features or plugins may not be available, and MariaDB introduces its own enhancements like Aria, ColumnStore, and Spider storage engines.

Can I run MariaDB and MySQL on the same server?

Technically yes, but its not recommended. Both services use the same default port (3306) and similar configuration files. Running them simultaneously requires manual port changes, separate data directories, and complex service management. For development, use Docker containers instead to isolate instances.

How do I reset the MariaDB root password?

If you forget the root password, restart MariaDB in safe mode:

  1. Stop the service: sudo systemctl stop mariadb
  2. Start in safe mode: sudo mysqld_safe --skip-grant-tables &
  3. Connect without a password: mysql -u root
  4. Update the password:
UPDATE mysql.user SET authentication_string=PASSWORD('NewStrongPass123!') WHERE User='root';

FLUSH PRIVILEGES;

  1. Exit and restart MariaDB normally: sudo systemctl restart mariadb

Why is MariaDB faster than MySQL?

MariaDB includes performance optimizations such as improved query execution plans, faster InnoDB performance, parallel replication threads, and optimized storage engines like Aria and MyRocks. It also has better thread pooling, more efficient memory management, and faster DDL operations. Benchmarks show MariaDB outperforms MySQL in read-heavy workloads, complex joins, and replication scenarios.

How do I enable remote access to MariaDB?

By default, MariaDB only accepts local connections. To allow remote access:

  1. Edit the configuration file: sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf
  2. Change bind-address = 127.0.0.1 to bind-address = 0.0.0.0 (or your servers IP).
  3. Restart MariaDB: sudo systemctl restart mariadb
  4. Create a user with remote access: CREATE USER 'remote_user'@'%' IDENTIFIED BY 'pass'; GRANT ALL ON db.* TO 'remote_user'@'%';
  5. Open port 3306 in your firewall: sudo ufw allow 3306

Always use SSL and restrict access by IP address for security.

What is the difference between MariaDB and MySQL 8.0?

While both are RDBMS platforms, MariaDB 10.6+ and MySQL 8.0 differ in several key areas:

  • Authentication: MySQL 8.0 uses caching_sha2_password by default; MariaDB uses mysql_native_password for better compatibility.
  • Storage Engines: MariaDB includes Aria, ColumnStore, and Spider; MySQL has InnoDB and NDB.
  • Features: MariaDB has window functions, CTAS, and enhanced JSON support earlier than MySQL.
  • Licensing: MariaDB is fully GPL; MySQL has a dual GPL/Commercial license.
  • Development: MariaDB is community-driven; MySQL is Oracle-controlled.

Choose MariaDB for open-source purity and performance; choose MySQL for enterprise support and Oracle ecosystem integration.

Conclusion

Installing MariaDB is a fundamental skill for developers, DevOps engineers, and system administrators working with modern web applications and data-driven systems. This guide has walked you through installing MariaDB on Linux, Windows, and macOS, configured it securely, optimized it for performance, and demonstrated real-world use casesfrom WordPress deployments to high-availability clusters.

MariaDBs compatibility with MySQL, combined with its superior performance, active community, and commitment to open-source principles, makes it the preferred choice for new projects and migrations alike. By following the best practices outlined herestrong passwords, SSL encryption, regular backups, and timely updatesyou ensure your database infrastructure is secure, scalable, and reliable.

As you continue to work with MariaDB, explore its advanced features such as replication, partitioning, and columnar storage. Leverage the tools and resources mentioned to monitor, audit, and automate your database operations. Remember: a well-installed and well-maintained MariaDB server is the backbone of any robust application stack.

Now that youve mastered the installation process, the next step is to design efficient schemas, write optimized queries, and integrate MariaDB seamlessly into your application architecture. The possibilities are limitlessand with MariaDB, youre building on a foundation thats open, fast, and future-proof.