How to Install Mariadb

How to Install MariaDB: A Comprehensive Tutorial Introduction MariaDB is a popular open-source relational database management system (RDBMS) that is widely used as a replacement for MySQL. It offers enhanced performance, scalability, and a rich set of features that make it suitable for a variety of applications, from small websites to large enterprise systems. Installing MariaDB correctly is criti

Nov 17, 2025 - 11:15
Nov 17, 2025 - 11:15
 3

How to Install MariaDB: A Comprehensive Tutorial

Introduction

MariaDB is a popular open-source relational database management system (RDBMS) that is widely used as a replacement for MySQL. It offers enhanced performance, scalability, and a rich set of features that make it suitable for a variety of applications, from small websites to large enterprise systems.

Installing MariaDB correctly is critical for database reliability, security, and performance. This tutorial provides a detailed, step-by-step guide to installing MariaDB on multiple operating systems, along with best practices, tools, real-world examples, and answers to frequently asked questions.

Step-by-Step Guide

1. Preparing Your System

Before installing MariaDB, ensure your operating system is up to date. This step helps avoid compatibility issues and ensures you have the latest security patches.

  • For Debian/Ubuntu: sudo apt update && sudo apt upgrade -y
  • For CentOS/RHEL: sudo yum update -y
  • For Windows, ensure your system has the latest updates installed via Windows Update.

2. Installing MariaDB on Linux

On Ubuntu/Debian

MariaDB is included in the default repositories of many Linux distributions. To install it on Ubuntu or Debian:

  1. Update package database: sudo apt update
  2. Install MariaDB server and client: sudo apt install mariadb-server mariadb-client -y
  3. Start the MariaDB service: sudo systemctl start mariadb
  4. Enable MariaDB to start on boot: sudo systemctl enable mariadb
  5. Secure the installation by running: sudo mysql_secure_installation

On CentOS/RHEL

CentOS and RHEL typically require enabling the MariaDB repository before installation.

  1. Add the MariaDB repository by creating a repo file in /etc/yum.repos.d/MariaDB.repo with content specific to your MariaDB version and OS version. You can find official repo configurations on the MariaDB official site.
  2. Install MariaDB server and client: sudo yum install mariadb-server mariadb -y
  3. Start the service: sudo systemctl start mariadb
  4. Enable MariaDB to auto-start at boot: sudo systemctl enable mariadb
  5. Run the security script: sudo mysql_secure_installation

3. Installing MariaDB on Windows

Follow these steps to install MariaDB on Windows:

  1. Download the latest MariaDB MSI installer from the official MariaDB download page.
  2. Run the installer and follow the setup wizard.
  3. Choose the setup type (Typical or Custom) based on your needs.
  4. Set a root password during installation.
  5. Complete the installation and verify by opening a command prompt and typing: mysql -u root -p

4. Verifying the Installation

After installation, verify that MariaDB is running properly:

  • Check status on Linux: sudo systemctl status mariadb
  • Log in to MariaDB shell: mysql -u root -p
  • Run a test query: SELECT VERSION(); to confirm the version installed.

5. Basic Configuration

Secure your MariaDB installation and tune basic settings:

  1. Run mysql_secure_installation to disable remote root login, remove anonymous users, and set root password.
  2. Edit the configuration file (usually /etc/mysql/mariadb.conf.d/50-server.cnf or /etc/my.cnf) to adjust buffer sizes, character sets, and connection limits.
  3. Restart MariaDB after changes: sudo systemctl restart mariadb

Best Practices

1. Always Secure the Installation

Running mysql_secure_installation is essential. It helps prevent unauthorized access by disabling remote root login, removing test databases, and setting strong root passwords.

2. Use the Latest Stable Version

MariaDB frequently updates with security patches and performance improvements. Always install or upgrade to the latest stable release to benefit from these enhancements.

3. Regularly Backup Your Databases

Implement automated backup strategies using tools like mysqldump or MariaDBs integrated backup utilities to avoid data loss.

4. Monitor Performance and Logs

Keep an eye on slow query logs, error logs, and resource usage to proactively identify and fix potential issues.

5. Configure Appropriate User Privileges

Grant least privilege access to database users to enhance security. Avoid using the root account for application connections.

6. Optimize Configuration for Your Workload

Tune MariaDB parameters such as innodb_buffer_pool_size and max_connections depending on your servers hardware and application demands.

Tools and Resources

1. MariaDB Official Documentation

The official MariaDB Knowledge Base is the best resource for in-depth guides, tutorials, and reference materials.

2. Command-Line Tools

  • mysql: The interactive MariaDB command-line client.
  • mysqldump: Utility for backing up databases.
  • mysqladmin: Administrative commands for monitoring the server.

3. Graphical Clients

Tools like phpMyAdmin, HeidiSQL, and DBeaver provide user-friendly interfaces for managing MariaDB databases.

4. Configuration and Management Tools

Use my.cnf or 50-server.cnf for configuration. Monitoring tools like Percona Monitoring and Management or Grafana can help track performance metrics.

Real Examples

Example 1: Installing MariaDB on Ubuntu 22.04

Run the following commands sequentially:

sudo apt update

sudo apt install mariadb-server -y

sudo systemctl start mariadb

sudo systemctl enable mariadb

sudo mysql_secure_installation

Verify the installation:

mysql -u root -p

SELECT VERSION();

Example 2: Adding a New MariaDB User with Limited Privileges

Log into MariaDB shell and execute:

CREATE USER 'appuser'@'localhost' IDENTIFIED BY 'StrongPassword123';

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

FLUSH PRIVILEGES;

This creates a user with limited privileges on a specific database, enhancing security.

Example 3: Backing Up a Database

Use mysqldump to backup 'mydatabase' to a SQL file:

mysqldump -u root -p mydatabase > mydatabase_backup.sql

FAQs

Q1: What is the difference between MariaDB and MySQL?

MariaDB is a fork of MySQL and is fully compatible in many respects but offers additional features, improved performance, and is community-driven. MariaDB tends to integrate cutting-edge features faster than MySQL.

Q2: Can I install MariaDB alongside MySQL?

It is possible but generally not recommended as they may conflict due to shared port usage and files. If necessary, configure them to use different ports and data directories.

Q3: How do I update MariaDB to the latest version?

Updating involves backing up your databases, updating your package repositories, and reinstalling the latest MariaDB packages. Always test upgrades in a staging environment first.

Q4: What default port does MariaDB listen on?

MariaDB listens on port 3306 by default, the same as MySQL.

Q5: How can I improve MariaDB performance?

Performance can be improved by tuning configuration parameters, using appropriate storage engines like InnoDB, indexing tables properly, and optimizing queries.

Conclusion

Installing MariaDB is straightforward but requires attention to detail to ensure security, stability, and performance. This tutorial covered installation on major operating systems, best practices for configuration and security, useful tools, and practical examples to help you get started confidently.

By following these guidelines and leveraging available resources, you can set up a robust MariaDB environment tailored to your specific needs, whether for development, testing, or production deployment.