How To

Install MariaDB on Ubuntu 20.04: Setup and Admin Access

MariaDB is an open-source relational database management system. It was created by the original MySQL developers as a community-driven fork, and it works as a drop-in replacement for MySQL. Most apps that support MySQL run on MariaDB without any code changes.

MariaDB is commonly used for:

  • Web applications and CMS platforms like WordPress
  • LAMP and LEMP stack setups on Linux servers
  • Any project that previously ran on MySQL

This guide shows you how to install MariaDB on Ubuntu 20.04, log in as root, and set up admin access for external tools like phpMyAdmin.

<strong>Prerequisite:</strong>&nbsp;You need a user account with sudo or root access to follow these steps.

Install MariaDB on Ubuntu 20.04

The latest version of MariaDB available in Ubuntu’s default repositories is version 10.3. Install it with:

bashsudo apt updatesudo apt install mariadb-server

The service starts on its own after install. Check that it is running:

bashsudo systemctl status mariadb

You should see active (running) in the output. The database server is ready to use.

<strong>Tip:</strong>&nbsp;Run&nbsp;<code>sudo mysql_secure_installation</code>&nbsp;to harden your setup. It walks you through removing test databases, disabling anonymous logins, and setting a root password.

Check the installed version at any time with:

bashmariadb --version

To start, stop, or restart MariaDB, use these commands:

bashsudo systemctl start mariadbsudo systemctl stop mariadbsudo systemctl restart mariadb

Log In to MariaDB as Root

By default, MariaDB uses the auth_socket plugin for the root user. This means root does not log in with a password. Instead, MariaDB checks that the Linux system user running the command matches the database user name.

In simple terms, if you have sudo access on the server, just run:

bashsudo mysql

You will see the MariaDB prompt:

MariaDB [(none)]>

Type exit or press CTRL+D to close the session.

This way of logging in works well when you manage MariaDB from the server terminal directly. No password is sent over the network, which makes it secure by default.

The problem comes when you use an external tool like phpMyAdmin. Those tools connect with a username and password, which auth_socket does not support.

Set Up an Admin User for External Access

If you need to connect from an external program, you have two options.

Option 1: Change the root login method.

This lets the root user log in with a password. Run these commands from inside the MariaDB shell:

sqlALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'your_strong_password';FLUSH PRIVILEGES;

Option 2 (recommended): Create a new admin user.

This keeps root on auth_socket and gives you a separate account for external tools. It is the safer approach:

sqlGRANT ALL PRIVILEGES ON *.* TO 'admin'@'localhost' IDENTIFIED BY 'your_strong_password';

You can name this user anything you like. Just make sure to use a long, strong password.

After making any changes, restart MariaDB:

bashsudo systemctl restart mariadb
<strong>Tip:</strong>&nbsp;Never reuse passwords for database admin accounts. Use a random, unique password and store it in a password manager.

MariaDB is now installed and running on your Ubuntu server. The default setup is secure for most use cases. If you plan to connect a web application, create a dedicated database user with access to only that application’s database, not the full server. Got questions? Leave a comment below.

Cyber Defence

Recent Posts

What Is a Data Protection Platform and Why Your Organization Needs One

A data protection platform is a unified system that helps organizations discover, classify, monitor, and…

1 day ago

How Swiss Privacy Rules Affect AI Companies Under GDPR

AI companies operating in or around Switzerland face a compliance challenge that most legal teams…

3 days ago

Swiss FADP vs EU GDPR: Key Differences for AI and Data Privacy

Two major data privacy laws now govern how organizations handle personal data across Europe; the…

4 days ago

Kali Linux Commands Cheat Sheet: Complete Quick Reference

This cheat sheet covers the essential Kali Linux commands every pentester and ethical hacker uses…

1 month ago

What I Wish I Knew Before Learning Malware Analysis and Reverse Engineering

When I first started learning malware analysis and reverse engineering, I thought the hardest part…

1 month ago

git fetch vs git pull: How They Work and When to Use Each

Both git fetch and git pull talk to a remote repository, but they do very different things to your…

2 months ago