How to Install MariaDB on Ubuntu (Quick & Easy Guide)

How to Install MariaDB on Ubuntu (Quick & Easy Guide)
User
8 Min Read
2025/08/18

When MySQL changed hands years ago, some of its original developers decided to build their own version and that’s how MariaDB was born. If you’re looking to install MariaDB on Ubuntu, you’ll find that it works almost the same way as MySQL, so if you’ve used that before, you won’t feel lost here. Over time, MariaDB proved itself as a solid, fast, and trustworthy database, which is why so many developers rely on it today.

In this walkthrough, I’ll show you how to get MariaDB running on Ubuntu. It’s nothing complicated just a couple of commands in the terminal, and you’ll be up and running with a fresh database server you can actually use right away.

When I first switched from MySQL to MariaDB on Ubuntu 22.04, I was surprised how smooth the process was. At first, the service didn’t even start until I enabled it with systemctl enable mariadb. That’s a common issue beginners face when they install MariaDB on Ubuntu, so I’ll cover it here too.

Step 1 – Update Ubuntu Packages

Before installing any new software, it’s always a good idea to update your package list. First, update your packages with this command. That way, when you install MariaDB on Ubuntu, you’ll get the latest version.

sudo apt-get update -y

This ensures that you get the latest version of MariaDB from the official Ubuntu repositories.

Step 2 – Install MariaDB on Ubuntu

To get MariaDB onto your system, just type:

sudo apt-get install mariadb-server -y

Ubuntu will grab everything it needs and set it up for you, so there’s no extra hunting for missing packages to install MariaDB successfully on Ubuntu.

Step 3 – Verify the Installation

Once it’s done, check the version with:

mysql -V

Seeing the version number confirms that MariaDB is installed and ready to use. Want to log in? After you install MariaDB on Ubuntu, try:

mysql -u root -p

Enter the password you chose during setup, and you’ll drop into the MariaDB prompt where you can start playing with the database.

Step 4 – Enable and Start MariaDB Service

After installing, fire up the MariaDB service with:

sudo systemctl start mariadb

If you don’t want to manually start it every time the server reboots, enable it so it runs automatically as part of your MariaDB on Ubuntu setup:

sudo systemctl enable mariadb

Curious if it’s working? Check the status of MariaDB in your Ubuntu environment:

sudo systemctl status mariadb

You should see it marked as active (running).

Step 5 – Secure MariaDB Installation

Out of the box, MariaDB isn’t very secure. There’s a handy script to fix that:

sudo mysql_secure_installation

This will guide you through a few questions, like setting a root password, removing the test database, and blocking anonymous users. Just hit Y for the recommended options unless you know you need something different.

The mysql_secure_installation script is not just a recommendation. It removes insecure defaults like the test database, disables anonymous accounts, and forces a strong root password—all critical steps before you put the server into production after you install MariaDB on Ubuntu.

Next Steps: After installation, try creating a test database to confirm everything works. For example:

CREATE DATABASE testdb;
SHOW DATABASES;

This quick test ensures your server is ready before using it for real applications.

Conclusion

That’s pretty much it MariaDB should be up and running on your Ubuntu box now. The setup isn’t complicated at all, and that’s one of the reasons I like working with it.

Personally, after finishing the install, I always create a quick test database and run a couple of simple queries, just to double-check everything before I start building something serious. It saves a lot of headaches later if something small went wrong while installing MariaDB on Ubuntu.

And if you’re wondering why MariaDB came into the picture in the first place or how it stacks up against MySQL, I’ve got a separate guide on that which you might find useful.

 

Common Issues Section

Error: Access denied for user ‘root’@’localhost’

This happens if you try to log in without setting a root password. Run sudo mysql_secure_installation to fix it.

Error: MariaDB service not starting automatically

Sometimes MariaDB won’t run after reboot. Use:

sudo systemctl enable mariadb
sudo systemctl start mariadb

Error: Package not found when installing MariaDB

Make sure your package list is updated with:

sudo apt-get update -y

rrr

0 out of 0 votes
Frequently Asked Questions

Pretty much, yes. I’ve run the exact same commands on 20.04 and 22.04, and they behaved the same way. The only difference you might notice is the package versions newer Ubuntu gives you a slightly newer MariaDB by default.

In most cases, yeah. I’ve swapped it in on a few projects without changing a single line of code. The only time I ran into trouble was with an app that used some old MySQL-specific functions but that’s rare these days.

Leave a Reply

Full Name*
Email*
Comment *

Calculate the value of 3 + 9 :

Save my name, email, and website in this browser for the next time I comment.
Recent Replies
Show More

We are by your side every step of the way

Think about developing your online business; We will protect it compassionately

We are by your side every step of the way

+8595670151

7 days a week, 24 hours a day