How to Install Mariadb
How to Install MariaDB: A Complete Step-by-Step Guide for Developers and 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 Michael Widenius, one of the original developers of MySQL, MariaDB was introduced in 2009 to ensure continued open-source development after Oracle’s a
How to Install MariaDB: A Complete Step-by-Step Guide for Developers and 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 Michael Widenius, one of the original developers of MySQL, MariaDB was introduced in 2009 to ensure continued open-source development after Oracles acquisition of MySQL. Today, MariaDB is widely adopted by enterprises, web hosting providers, and developers due to its superior performance, enhanced security features, and active community support.
Installing MariaDB correctly is a foundational skill for anyone managing web applications, data-driven services, or backend infrastructure. Whether youre deploying a WordPress site, building a custom enterprise application, or managing a data warehouse, having a properly configured MariaDB server ensures reliability, scalability, and optimal performance. Unlike proprietary alternatives, MariaDB offers full transparency, frequent updates, and compatibility with MySQL tools and connectors making it an ideal choice for modern tech stacks.
This comprehensive guide walks you through every aspect of installing MariaDB on major operating systems, including Linux distributions like Ubuntu, CentOS, and Debian, as well as macOS and Windows. Youll learn not only how to install it, but also how to secure it, optimize it, and troubleshoot common issues. By the end of this tutorial, youll have the confidence to deploy MariaDB in production environments with best practices in mind.
Step-by-Step Guide
Installing MariaDB on Ubuntu 22.04/20.04
Ubuntu is one of the most popular Linux distributions for servers and development environments. Installing MariaDB on Ubuntu is straightforward and can be completed using the systems package manager, APT.
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 installer will automatically download and configure the latest stable version of MariaDB from Ubuntus official repositories. During installation, you may be prompted to confirm the installation press Y and hit Enter.
Once the installation completes, 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 (running). If its not, review the logs using sudo journalctl -u mariadb for troubleshooting.
For enhanced security, run the built-in security script:
sudo mysql_secure_installation
This interactive 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 carefully accepting the default recommendations is generally safe for most use cases.
Installing MariaDB on CentOS 8/9 and RHEL
CentOS and Red Hat Enterprise Linux (RHEL) use the DNF (Dandified YUM) package manager. MariaDB is available in the default repositories, but for the latest version, its recommended to add the official MariaDB repository.
First, update your system:
sudo dnf update -y
Then, add the MariaDB repository by creating a new repository file:
sudo nano /etc/yum.repos.d/mariadb.repo
Paste the following content into the file (adjust the version number if needed check mariadb.org/download/ for the latest stable release):
[mariadb]
name = MariaDB
baseurl = https://yum.mariadb.org/11.11/centos9-amd64
module_hotfixes=1
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1
Save and exit the file (Ctrl+O, then Ctrl+X in nano).
Install MariaDB server:
sudo dnf install MariaDB-server MariaDB-client -y
Start and enable the service:
sudo systemctl start mariadb
sudo systemctl enable mariadb
Verify the installation:
sudo systemctl status mariadb
Run the security script to harden your installation:
sudo mysql_secure_installation
Follow the prompts to set a strong root password and remove insecure defaults.
Installing MariaDB on Debian 12/11
Debian, known for its stability, is widely used in production environments. Installing MariaDB on Debian follows a similar pattern to Ubuntu.
Begin by updating 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
Confirm the service status:
sudo systemctl status mariadb
Secure your installation:
sudo mysql_secure_installation
Debian users may encounter a prompt asking whether to use the unix_socket authentication plugin. This plugin allows local users to authenticate using their system credentials. For development environments, this is convenient. For production, its recommended to disable it and use password authentication instead. Choose No if you plan to connect remotely or use application-level authentication.
Installing MariaDB on macOS
macOS users can install MariaDB using Homebrew, the most popular package manager for macOS.
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 and enable it to launch at login:
brew services start mariadb
To verify the installation, connect to the MariaDB server:
mysql -u root
By default, the root account has no password on macOS installations. For security, immediately set a password:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'YourStrongPassword123!';
FLUSH PRIVILEGES;
Then run the secure installation script manually:
mysql_secure_installation
Follow the prompts to remove anonymous users, disable remote root access, and delete the test database.
Installing MariaDB on Windows
While Linux is preferred for server deployments, developers on Windows may need MariaDB for local testing or development environments.
Visit the official MariaDB downloads page: https://mariadb.org/download/
Under Windows, select the latest stable version (e.g., MariaDB 11.11). Download the MSI installer (recommended for most users).
Run the installer as Administrator. Follow the setup wizard:
- Select Server only if youre installing for backend use.
- Choose Typical configuration unless you have specific performance needs.
- Set a strong root password when prompted.
- Enable Add MySQL to Windows PATH for easier command-line access.
- Complete the installation.
After installation, open the Windows Services app (services.msc) and locate MariaDB. Ensure the service is set to Automatic and is running.
To verify the installation, open Command Prompt or PowerShell and type:
mysql -u root -p
Enter your root password when prompted. If youre connected successfully, youll see the MariaDB prompt:
mysql>
Run SELECT VERSION(); to confirm the version and ensure the installation is functional.
Best Practices
Use Strong Passwords and Limit Root Access
One of the most common security oversights is leaving the root account with a weak or empty password. Always assign a complex password using a combination of uppercase, lowercase, numbers, and symbols. Avoid reusing passwords from other systems.
Never allow remote root login. The mysql_secure_installation script disables this by default, but verify it manually by querying the user table:
SELECT User, Host FROM mysql.user WHERE User = 'root';
If any row shows root@%, remove it immediately:
DROP USER 'root'@'%';
FLUSH PRIVILEGES;
Enable SSL/TLS for Encrypted Connections
By default, MariaDB does not enforce SSL connections. For applications connecting over public networks, this is a security risk. To enable SSL, generate certificates or use the built-in auto-generation feature.
Run the following command to generate SSL certificates automatically:
sudo mysql_ssl_rsa_setup --uid=mysql
Then edit the MariaDB configuration file typically located at /etc/mysql/mariadb.conf.d/50-server.cnf on Ubuntu or /etc/my.cnf on CentOS:
[mysqld]
ssl-ca=/var/lib/mysql/ca.pem
ssl-cert=/var/lib/mysql/server-cert.pem
ssl-key=/var/lib/mysql/server-key.pem
Restart the service:
sudo systemctl restart mariadb
To verify SSL is active, connect to MariaDB and run:
SHOW VARIABLES LIKE '%ssl%';
Look for have_ssl set to YES.
Configure Resource Limits and Performance Tuning
MariaDBs default configuration is optimized for minimal memory usage. For production servers, adjust key parameters in the configuration file to match your hardware.
Key settings to review:
- innodb_buffer_pool_size: Set to 7080% of available RAM on dedicated database servers.
- max_connections: Increase from the default 151 to 200500 based on expected concurrent users.
- query_cache_type and query_cache_size: Deprecated in newer versions; use the Performance Schema instead.
- tmp_table_size and max_heap_table_size: Set to 64M256M to prevent disk-based temporary tables.
After making changes, restart MariaDB and monitor performance using:
SHOW GLOBAL STATUS LIKE 'Threads_connected';
SHOW GLOBAL STATUS LIKE 'Created_tmp%';
SHOW ENGINE INNODB STATUS;
Regular Backups and Point-in-Time Recovery
Never rely on a single backup strategy. Implement a layered approach:
- Daily full backups using
mysqldumpormariabackup(for InnoDB). - Binary logs enabled for point-in-time recovery.
- Offsite storage upload backups to encrypted cloud storage or a separate server.
To enable binary logging, add to your configuration file:
[mysqld]
log-bin=mysql-bin
server-id=1
Take a full backup:
mysqldump -u root -p --all-databases > full-backup.sql
For larger databases, use mariabackup (part of MariaDB Enterprise):
mariabackup --backup --target-dir=/backup/mariadb
Store backups with timestamps and test restores quarterly.
Use Non-Root Database Users for Applications
Never connect your application using the root database account. Create dedicated users with minimal privileges:
CREATE USER 'appuser'@'localhost' IDENTIFIED BY 'StrongAppPassword123!';
GRANT SELECT, INSERT, UPDATE, DELETE ON myapp_db.* TO 'appuser'@'localhost';
FLUSH PRIVILEGES;
This principle of least privilege limits damage if credentials are compromised. Always use SSL for application-to-database connections and store credentials in environment variables or secure vaults, not in plain-text configuration files.
Tools and Resources
Command-Line Tools
MariaDB comes with a suite of powerful command-line utilities:
- mysql The primary client for connecting to the server and running SQL queries.
- mysqldump Exports databases into SQL scripts for backup and migration.
- mariabackup Hot backup tool for InnoDB tables without locking the database.
- mysqladmin Administrative tool for server status, shutdown, and user management.
- mysqlcheck Checks, repairs, and optimizes tables.
Use mysql --help or man mysql to explore all available options.
Graphical User Interfaces (GUIs)
While CLI tools are powerful, GUIs simplify database management for non-experts:
- phpMyAdmin Web-based interface; ideal for shared hosting and quick edits.
- Adminer Lightweight, single-file alternative to phpMyAdmin.
- MySQL Workbench Official GUI from Oracle; fully compatible with MariaDB.
- DBeaver Free, open-source universal database tool supporting MariaDB, PostgreSQL, and more.
- HeidiSQL Windows-native tool with intuitive interface and SSH tunneling support.
Install phpMyAdmin on Ubuntu:
sudo apt install phpmyadmin
sudo ln -s /usr/share/phpmyadmin /var/www/html/phpmyadmin
Access via http://your-server-ip/phpmyadmin. Always secure it with HTTPS and IP whitelisting.
Monitoring and Performance Tools
Monitor MariaDB health using:
- pt-query-digest (Percona Toolkit) Analyzes slow query logs to identify bottlenecks.
- mysqldumpslow Summarizes slow query logs.
- Prometheus + Grafana Export metrics using the
mysqld_exporterand visualize performance trends. - Performance Schema Built-in MariaDB feature that tracks server internals without external tools.
To enable Performance Schema, ensure its not disabled in your config file. Query it directly:
SELECT * FROM performance_schema.events_statements_summary_by_digest ORDER BY SUM_TIMER_WAIT DESC LIMIT 10;
Official Documentation and Community
Always refer to the official MariaDB documentation for version-specific guidance:
- https://mariadb.com/kb/en/ Comprehensive knowledge base
- https://mariadb.org/ Community hub and downloads
- https://github.com/MariaDB/server Source code and issue tracking
Join the MariaDB Forum or Stack Overflows
mariadb tag for troubleshooting and advice from experienced users.
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 on Ubuntu:
- Install MariaDB as shown earlier.
- Secure the installation with
mysql_secure_installation. - Create a database and user for WordPress:
CREATE DATABASE wordpress_db;
CREATE USER 'wp_user'@'localhost' IDENTIFIED BY 'WpSecurePass!2024';
GRANT ALL PRIVILEGES ON wordpress_db.* TO 'wp_user'@'localhost';
FLUSH PRIVILEGES;
- Download and configure WordPress:
cd /var/www/html
wget https://wordpress.org/latest.tar.gz
tar -xzf latest.tar.gz
mv wordpress/* .
rm -rf wordpress latest.tar.gz
cp wp-config-sample.php wp-config.php
- Edit
wp-config.phpand update the database credentials:
define('DB_NAME', 'wordpress_db');
define('DB_USER', 'wp_user');
define('DB_PASSWORD', 'WpSecurePass!2024');
define('DB_HOST', 'localhost');
- Set correct file permissions:
chown -R www-data:www-data /var/www/html
chmod -R 755 /var/www/html
Complete the WordPress installation via browser at http://your-server-ip. The database connection will succeed, and your site will be live.
Example 2: High-Availability Setup with Galera Cluster
For mission-critical applications, MariaDB Galera Cluster provides synchronous multi-master replication. Heres a simplified three-node setup:
Install MariaDB on all three servers (Ubuntu 22.04). Then, on each node, edit /etc/mysql/mariadb.conf.d/50-server.cnf:
[mysqld]
wsrep_on=ON
wsrep_provider=/usr/lib/galera/libgalera_smm.so
wsrep_cluster_name="my_galera_cluster"
wsrep_cluster_address="gcomm://192.168.1.10,192.168.1.11,192.168.1.12"
wsrep_node_name="node1"
wsrep_node_address="192.168.1.10"
wsrep_sst_method=rsync
Adjust wsrep_node_name and wsrep_node_address for each server.
On the first node, start the cluster:
sudo systemctl stop mariadb
sudo galera_new_cluster
On the other two nodes, start MariaDB 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 and allows writes on any node.
Example 3: Migrating from MySQL to MariaDB
Many legacy systems run MySQL. Migrating to MariaDB is seamless since MariaDB maintains binary compatibility.
Backup your MySQL database:
mysqldump -u root -p --all-databases > mysql-backup.sql
Stop MySQL:
sudo systemctl stop mysql
Remove MySQL packages:
sudo apt remove mysql-server mysql-client
Install MariaDB:
sudo apt install mariadb-server
Restore the backup:
mysql -u root -p
Start MariaDB and verify:
sudo systemctl start mariadb
mysql -u root -p -e "SHOW DATABASES;"
All databases and users will appear unchanged. Performance may improve immediately due to MariaDBs optimized storage engines and query planner.
FAQs
Is MariaDB compatible with MySQL?
Yes. MariaDB was designed as a drop-in replacement for MySQL. Most MySQL clients, applications, and tools (including WordPress, Drupal, and Laravel) work without modification. The SQL syntax, APIs, and connectors are nearly identical. However, some MySQL-specific features (like the Enterprise Audit Plugin) are not available in MariaDB, and vice versa MariaDB has unique features like the Aria storage engine and dynamic columns.
Whats the difference between MariaDB and MySQL?
While both are RDBMSs, MariaDB is community-driven and open-source, while MySQL is owned by Oracle. MariaDB includes performance improvements, additional storage engines (e.g., Aria, ColumnStore), and faster development cycles. It also avoids proprietary features and remains fully GPL-licensed. Many organizations prefer MariaDB for its transparency and commitment to open-source principles.
Can I run MariaDB and MySQL on the same machine?
Technically yes, but its not recommended. Both services use the same default port (3306) and configuration paths. Running them simultaneously requires complex port changes and separate data directories. For development, use Docker containers instead each service runs in isolation.
How do I reset the MariaDB root password?
Stop the MariaDB service:
sudo systemctl stop mariadb
Start MariaDB in safe mode without grant tables:
sudo mysqld_safe --skip-grant-tables --skip-networking &
Connect to MariaDB:
mysql -u root
Update the root password:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewStrongPassword123!';
FLUSH PRIVILEGES;
Exit and restart the service normally:
sudo systemctl restart mariadb
Why is my MariaDB installation slow?
Common causes include insufficient memory allocation, missing indexes on large tables, unoptimized queries, or disk I/O bottlenecks. Check the slow query log, enable Performance Schema, and use EXPLAIN before complex SELECT statements. Also ensure youre using InnoDB (not MyISAM) for transactional workloads.
How do I enable remote access to MariaDB?
By default, MariaDB only accepts local connections. To allow remote access:
- Edit the config file:
sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf - Change
bind-address = 127.0.0.1tobind-address = 0.0.0.0 - Restart MariaDB:
sudo systemctl restart mariadb - Create a user with remote access:
CREATE USER 'remote_user'@'%' IDENTIFIED BY 'password'; GRANT ALL ON db.* TO 'remote_user'@'%'; - Open port 3306 in your firewall:
sudo ufw allow 3306
Always use SSL and restrict IPs where possible.
What port does MariaDB use?
MariaDB uses port 3306 by default, the same as MySQL. This can be changed in the configuration file under the [mysqld] section with port = 3307 (or any unused port).
How often should I update MariaDB?
Update regularly at least quarterly. MariaDB releases security patches and performance fixes frequently. Use your systems package manager to update:
sudo apt update && sudo apt upgrade
or
sudo dnf update
Always test updates in a staging environment first.
Conclusion
Installing MariaDB is a critical step in building robust, scalable, and secure applications. Whether youre deploying on Ubuntu, CentOS, macOS, or Windows, the process is straightforward when following best practices. From securing root access and enabling SSL to configuring performance settings and implementing backups, each step contributes to a resilient database infrastructure.
MariaDBs compatibility with MySQL, active community, and continuous innovation make it the preferred choice for modern applications. By leveraging the tools and techniques outlined in this guide from command-line utilities to GUIs and monitoring systems you gain full control over your data layer.
Remember: installation is just the beginning. Regular maintenance, performance tuning, and proactive security are what transform a working database into a mission-critical asset. Use this guide as your foundation, refer to official documentation for updates, and always test changes in non-production environments before rolling them out.
With MariaDB properly installed and configured, youre not just running a database youre empowering your applications to perform at their best, reliably and securely, today and into the future.