
How to Install MariaDB on Ubuntu 24
MariaDB is a powerful, open-source relational database management system that serves as a drop-in replacement for MySQL, offering enhanced performance, advanced features, and better security. With Ubuntu 24 (Noble Numbat) bringing improved system performance and stability, installing MariaDB on this platform creates an excellent foundation for web applications, data analytics, and enterprise solutions. In this guide, you’ll learn how to install MariaDB on Ubuntu 24, configure it properly, handle common installation issues, and implement best practices for production environments.
Why Choose MariaDB Over Other Database Systems
MariaDB has gained significant traction among developers and system administrators due to its performance improvements over MySQL and its commitment to open-source principles. Here’s how it compares to other popular database systems:
Feature | MariaDB | MySQL | PostgreSQL |
---|---|---|---|
License | GPL v2 | GPL/Commercial | PostgreSQL License |
Performance (Complex Queries) | Excellent | Good | Excellent |
Storage Engines | 12+ (including Aria, TokuDB) | 9 (InnoDB, MyISAM) | Built-in only |
JSON Support | Yes (Enhanced) | Yes | Yes (Advanced) |
Replication Features | Advanced | Standard | Advanced |
Installation Methods Overview
Ubuntu 24 offers several ways to install MariaDB, each with its own advantages:
- APT Package Manager: Quick installation using Ubuntu’s default repositories
- MariaDB Official Repository: Latest stable versions with faster updates
- Source Compilation: Maximum customization but requires more time and expertise
- Docker Container: Isolated environment, perfect for development and testing
Method 1: Installing from Ubuntu Default Repository
This is the quickest method and works well for most development and production scenarios. Ubuntu 24 ships with MariaDB 10.11, which is a long-term support release.
# Update package index
sudo apt update
# Install MariaDB server and client
sudo apt install mariadb-server mariadb-client -y
# Check installation status
systemctl status mariadb
# Enable MariaDB to start on boot
sudo systemctl enable mariadb
After installation, verify the version:
mariadb --version
Method 2: Installing from MariaDB Official Repository
For access to the latest features and faster security updates, using the official MariaDB repository is recommended. This method gives you access to MariaDB 11.x series.
# Install software-properties-common for repository management
sudo apt install software-properties-common -y
# Import MariaDB signing key
wget -O- https://mariadb.org/mariadb_release_signing_key.asc | sudo gpg --dearmor -o /usr/share/keyrings/mariadb-keyring.gpg
# Add MariaDB repository
echo "deb [signed-by=/usr/share/keyrings/mariadb-keyring.gpg] https://mirror.mariadb.org/repo/11.4/ubuntu noble main" | sudo tee /etc/apt/sources.list.d/mariadb.list
# Update package index
sudo apt update
# Install MariaDB
sudo apt install mariadb-server mariadb-client -y
Initial Security Configuration
Immediately after installation, run the security script to remove default accounts and set up proper authentication:
sudo mariadb-secure-installation
The script will prompt you for several security settings:
- Root password: Set a strong password for the root user
- Remove anonymous users: Always choose ‘Y’ for production systems
- Disallow root login remotely: Choose ‘Y’ unless you specifically need remote root access
- Remove test database: Choose ‘Y’ to clean up the test database
- Reload privilege tables: Choose ‘Y’ to apply changes immediately
Essential Configuration
MariaDB’s main configuration file is located at /etc/mysql/mariadb.conf.d/50-server.cnf
. Here are some important settings to consider:
# Edit the configuration file
sudo nano /etc/mysql/mariadb.conf.d/50-server.cnf
# Key settings to modify:
[mysqld]
# Bind to specific IP (change from 127.0.0.1 for remote access)
bind-address = 127.0.0.1
# InnoDB buffer pool size (set to 70-80% of available RAM)
innodb_buffer_pool_size = 1G
# Query cache (useful for read-heavy applications)
query_cache_type = 1
query_cache_size = 256M
# Maximum connections
max_connections = 500
# Enable slow query log for performance monitoring
slow_query_log = 1
slow_query_log_file = /var/log/mysql/slow-query.log
long_query_time = 2
After making configuration changes, restart MariaDB:
sudo systemctl restart mariadb
Creating Databases and Users
Here’s how to create a database and user for your applications:
# Connect to MariaDB as root
sudo mariadb -u root -p
# Create a new database
CREATE DATABASE myapp_production;
# Create a new user with proper privileges
CREATE USER 'myapp_user'@'localhost' IDENTIFIED BY 'secure_password_here';
# Grant privileges to the user
GRANT ALL PRIVILEGES ON myapp_production.* TO 'myapp_user'@'localhost';
# Apply changes
FLUSH PRIVILEGES;
# Exit MariaDB
EXIT;
Common Installation Issues and Troubleshooting
Here are the most frequent problems you might encounter and their solutions:
Issue 1: MariaDB Service Won’t Start
# Check detailed error logs
sudo journalctl -u mariadb.service
# Check MariaDB error log
sudo tail -f /var/log/mysql/error.log
# Common fix: Reset file permissions
sudo chown -R mysql:mysql /var/lib/mysql
sudo chmod -R 755 /var/lib/mysql
Issue 2: Can’t Connect After Installation
Ubuntu 24’s MariaDB uses unix_socket authentication by default for the root user. This means you need to use sudo:
# This works
sudo mariadb -u root
# This might not work without additional configuration
mariadb -u root -p
To enable password authentication for root:
sudo mariadb -u root
ALTER USER 'root'@'localhost' IDENTIFIED BY 'your_password';
FLUSH PRIVILEGES;
EXIT;
Issue 3: Repository Key Errors
If you encounter GPG key errors when using the official repository:
# Remove old keys and re-add
sudo apt-key del 0xF1656F24C74CD1D8
wget -O- https://mariadb.org/mariadb_release_signing_key.asc | sudo gpg --dearmor -o /usr/share/keyrings/mariadb-keyring.gpg
Performance Optimization for Production
For production environments, consider these performance tuning parameters:
# Add to [mysqld] section in configuration file
[mysqld]
# InnoDB settings
innodb_buffer_pool_size = 4G # Adjust based on available RAM
innodb_log_file_size = 512M
innodb_flush_log_at_trx_commit = 2
innodb_file_per_table = 1
# MyISAM settings (if using MyISAM tables)
key_buffer_size = 256M
myisam_sort_buffer_size = 64M
# Connection settings
max_connections = 200
connect_timeout = 60
wait_timeout = 120
# Query cache settings
query_cache_size = 256M
query_cache_limit = 2M
Real-World Use Cases and Applications
MariaDB on Ubuntu 24 excels in various scenarios:
- Web Applications: Perfect backend for WordPress, Drupal, or custom PHP/Python applications
- E-commerce Platforms: Handles high transaction volumes with excellent ACID compliance
- Data Analytics: Columnstore engine provides excellent performance for analytical queries
- Content Management: Fast full-text search capabilities for content-heavy applications
- API Backend: Reliable data storage for REST APIs and microservices
Security Best Practices
Implement these security measures for production deployments:
# Create a dedicated user for applications (never use root)
CREATE USER 'webapp'@'localhost' IDENTIFIED BY 'complex_password';
GRANT SELECT, INSERT, UPDATE, DELETE ON webapp_db.* TO 'webapp'@'localhost';
# Enable SSL connections
[mysqld]
ssl-ca = /etc/mysql/ssl/ca-cert.pem
ssl-cert = /etc/mysql/ssl/server-cert.pem
ssl-key = /etc/mysql/ssl/server-key.pem
# Restrict network access
bind-address = 127.0.0.1
# Regular security updates
sudo apt update && sudo apt upgrade mariadb-server
Backup and Maintenance
Set up automated backups to prevent data loss:
# Create backup script
#!/bin/bash
BACKUP_DIR="/var/backups/mariadb"
DATE=$(date +%Y%m%d_%H%M%S)
mkdir -p $BACKUP_DIR
mariadb-dump --all-databases --single-transaction --routines --triggers > $BACKUP_DIR/full_backup_$DATE.sql
# Keep only last 7 days of backups
find $BACKUP_DIR -name "*.sql" -mtime +7 -delete
Add this script to your crontab for daily execution:
# Edit crontab
sudo crontab -e
# Add this line for daily backup at 2 AM
0 2 * * * /path/to/backup_script.sh
Integration with Popular Frameworks
MariaDB integrates seamlessly with modern development frameworks:
# Django settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'myapp_production',
'USER': 'myapp_user',
'PASSWORD': 'secure_password_here',
'HOST': 'localhost',
'PORT': '3306',
'OPTIONS': {
'charset': 'utf8mb4',
},
}
}
# Laravel .env file
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=myapp_production
DB_USERNAME=myapp_user
DB_PASSWORD=secure_password_here
For additional configuration options and advanced features, refer to the official MariaDB documentation. The Ubuntu Server Guide also provides distribution-specific information that can be helpful for system administrators managing Ubuntu-based infrastructure.
Monitoring and Performance Tuning
Use these commands to monitor your MariaDB installation:
# Check current connections
SHOW PROCESSLIST;
# Monitor query performance
SHOW STATUS LIKE 'Slow_queries';
# Check buffer pool efficiency
SHOW STATUS LIKE 'Innodb_buffer_pool%';
# View current configuration
SHOW VARIABLES LIKE 'innodb%';
Installing MariaDB on Ubuntu 24 provides a robust foundation for modern applications. Whether you’re running a simple blog or a complex enterprise system, following these installation and configuration steps will ensure optimal performance and security. Remember to regularly update your installation, monitor performance metrics, and maintain proper backups to keep your database environment running smoothly.

This article incorporates information and material from various online sources. We acknowledge and appreciate the work of all original authors, publishers, and websites. While every effort has been made to appropriately credit the source material, any unintentional oversight or omission does not constitute a copyright infringement. All trademarks, logos, and images mentioned are the property of their respective owners. If you believe that any content used in this article infringes upon your copyright, please contact us immediately for review and prompt action.
This article is intended for informational and educational purposes only and does not infringe on the rights of the copyright owners. If any copyrighted material has been used without proper credit or in violation of copyright laws, it is unintentional and we will rectify it promptly upon notification. Please note that the republishing, redistribution, or reproduction of part or all of the contents in any form is prohibited without express written permission from the author and website owner. For permissions or further inquiries, please contact us.