You need a reliable database for your Ubuntu server, but you're not sure where to start with MariaDB. Whether you're setting up a web application, migrating from MySQL, or just need a solid relational database management system, getting MariaDB installed correctly is crucial. The good news? It takes just a few minutes and a handful of commands.
After reading this guide, you'll understand what MariaDB is, why it's a great choice for Ubuntu, and you'll have a fully functional MariaDB installation ready for your applications. We'll walk through each step together, explain what's happening, and show you how to verify everything is working properly.
Table of Contents
- What is MariaDB and Why Choose It?
- System Requirements
- Step-by-Step Installation
- Verifying Your Installation
- Initial Security Setup
- Common Installation Mistakes
- Next Steps After Installation
What is MariaDB and Why Choose It?
MariaDB is a free, open-source relational database management system that's compatible with MySQL. It was created as a drop-in replacement when MySQL's ownership changed hands, and it's now the default database server in many Linux distributions, including Ubuntu.
Many developers and system administrators prefer MariaDB because it offers better performance, more features, and stronger community support than MySQL. It's used by major companies like Google, WordPress.com, and Wikipedia. If you're already familiar with MySQL, you'll find MariaDB feels like home—the commands and syntax are nearly identical.
For Ubuntu systems, MariaDB is the recommended choice because it's fully integrated into the package repositories and receives regular security updates.
System Requirements
Before installing MariaDB, make sure your Ubuntu system meets these basic requirements:
- Ubuntu 20.04 LTS, 22.04 LTS, or newer (this guide works for all current versions)
- At least 512 MB of RAM (1 GB or more recommended for production)
- About 500 MB of disk space for the base installation
- Sudo access or root privileges
- An active internet connection
This guide assumes you're running Ubuntu on a local machine, virtual machine, or cloud server. The steps are identical across all deployment types.
Step-by-Step Installation
Step 1: Update Your Package Manager
Before installing anything new, refresh your package manager's cache to ensure you're getting the latest versions.
sudo apt update
This command reaches out to Ubuntu's repositories and fetches the latest package information. It does not install or upgrade anything. It only updates the list of available packages. You should see a series of "Hit", "Get", or "Ign" lines as it refreshes from different repositories.
What to expect: This usually takes 10 to 30 seconds depending on your internet speed.
Step 2: Install MariaDB Server
Now install MariaDB from the official Ubuntu repositories.
sudo apt install mariadb-server -y
The -y flag automatically answers "yes" to any prompts, speeding up the installation. Without it, you would need to press y and hit Enter when asked to confirm.
This command installs several packages:
mariadb-server: The main database servermariadb-client: Command-line tools to interact with the database- Supporting libraries and dependencies
What to expect: Download and installation typically takes 1 to 3 minutes depending on your internet speed and server performance.
Step 3: Start the MariaDB Service
After installation, start the MariaDB service to make sure it is running.
sudo systemctl start mariadb
The systemctl command manages system services. The start action boots up MariaDB immediately.
What to expect: If the command completes without errors and produces no output, MariaDB is now running.
Step 4: Enable MariaDB to Start on Boot
To ensure MariaDB automatically starts whenever your server reboots, enable it.
sudo systemctl enable mariadb
This creates a symbolic link that tells Ubuntu to start MariaDB during the boot process. Without this step, MariaDB would stop running after a system restart.
What to expect: You will see output confirming the service is now enabled, typically indicating a symbolic link was created.
Step 5: Run the Security Setup Script
MariaDB comes with a security script that removes default accounts and restricts access. Run it now.
sudo mysql_secure_installation
This interactive script will ask you several questions:
- Enter current password for root: Press Enter because there is no password by default
- Switch to unix_socket authentication: Type
nand press Enter unless you have specific requirements - Change the root password: Type
yand press Enter, then enter a strong password twice - Remove anonymous users: Type
yand press Enter - Disable root login remotely: Type
yand press Enter - Remove test database: Type
yand press Enter - Reload privilege tables: Type
yand press Enter
What to expect: The script takes 1 to 2 minutes and walks you through each security step. After completion, your MariaDB installation is secured and ready for production use.
Verifying Your Installation
Confirm that MariaDB is installed and running properly.
Check the Service Status
sudo systemctl status mariadb
You should see output indicating the service is active (running). If the status shows inactive or stopped, start the service again.
Connect to MariaDB
Test the connection using the command-line client.
sudo mysql -u root -p
You will be prompted for the password you set during the security setup. If successful, you will see the MariaDB prompt.
MariaDB [(none)]>
Type EXIT; to leave the MariaDB shell.
What to expect: A successful connection confirms MariaDB is operational.
Check the Version
From the MariaDB prompt, check the installed version.
SELECT VERSION();
This command displays the installed MariaDB version. Recent Ubuntu releases typically install MariaDB version 10.6 or newer.
Initial Security Setup
In addition to the automated security script, apply the following best practices.
Create a dedicated database user instead of using the root account.
CREATE USER 'appuser'@'localhost' IDENTIFIED BY 'strong_password_here';
GRANT ALL PRIVILEGES ON your_database.* TO 'appuser'@'localhost';
FLUSH PRIVILEGES;
This creates a user with limited access, following the principle of least privilege.
Restrict remote access by verifying the bind address configuration.
Edit /etc/mysql/mariadb.conf.d/50-server.cnf and confirm the following line exists:
bind-address = 127.0.0.1
This prevents remote connections unless explicitly configured.
Enable firewall rules if using Ubuntu Firewall.
sudo ufw allow from 192.168.1.0/24 to any port 3306
This allows MariaDB access only from a trusted network range.
Common Installation Mistakes
Mistake 1: Forgetting to run sudo apt update first
Without updating your package cache, you might install an outdated version of MariaDB. Always refresh first.
Mistake 2: Not setting a strong root password
During mysql_secure_installation, do not skip the password change step. A weak password makes your database vulnerable.
Mistake 3: Skipping the security setup script
Running mysql_secure_installation removes default test accounts and tightens permissions. Skipping it leaves your database exposed.
Mistake 4: Using the root account for application connections
Always create separate database users with limited permissions for your applications. If one application is compromised, it will not have access to your entire database.
Performance Impact and Considerations
MariaDB's lightweight footprint makes it ideal for Ubuntu servers with limited resources. On a basic server with 1 gigabyte of memory, MariaDB typically consumes 50 to 100 megabytes at startup, with memory usage scaling based on queries and connections.
For production environments, consider these optimizations:
- Increase the
max_connectionsparameter for high-traffic applications - Adjust the
innodb_buffer_pool_sizeto allocate more memory to the query cache - Enable slow query logging to identify performance bottlenecks
For detailed performance tuning, consult the official MariaDB documentation on system variables.
When NOT to Use This Approach
This guide assumes a standard local or single-server installation. The following scenarios require a different approach.
Clustered or replicated databases require additional configuration beyond a basic installation. High-availability setups with multiple database servers require replication or clustering configuration.
Applications requiring specific MariaDB versions may require installation from alternative repositories. Ubuntu repositories provide recent versions, but application requirements should always be verified.
Remote database servers accessed over the network require firewall configuration and binding to a non-localhost address. Security considerations change significantly in multi-machine environments.
Next Steps After Installation
After installing and securing MariaDB, complete the following tasks.
Create your first database and user using the commands from the Initial Security Setup section. Test your application connection to confirm MariaDB access.
Set up automated backups to protect your data. A basic daily backup can be implemented using a scheduled task that runs mysqldump. Refer to the Ubuntu community guide on database backups for details.
Learn basic MariaDB administration by practicing common tasks such as creating tables, inserting data, and running queries. The MariaDB Knowledge Base is a comprehensive free resource.
Monitor your database using management tools such as MySQL Workbench or phpMyAdmin. These tools simplify administration as usage grows.
Conclusion
You have successfully installed MariaDB on Ubuntu and hardened its security using a structured, step-by-step process. The database is now ready to support development projects, web applications, or production workloads.
The key practices to remember are updating the package manager, running the security setup script, and creating dedicated users for each application. These steps ensure a secure and reliable MariaDB installation.
If issues occur during installation, review the MariaDB server log located at /var/log/mysql/error.log for detailed error information. Many common problems are addressed in the official MariaDB troubleshooting guide.
Need professional help with your database installation, migration or infrastructure? Our team at Technoroots Limited specializes in enterprise database solutions.
Contact us at Technorootsfor expert guidance on MySQL migrations, PostgreSQL optimization, Oracle Database setup, or any database infrastructure challenges.