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

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 days ago

git cherry-pick Command: Apply Commits from Another Branch

Sometimes the change you need already exists, just on the wrong branch. A hotfix lands…

2 days ago

Best Email APIs for Secure Business Email: Why Developers Are Moving Beyond SMTP

Email is still one of the most important communication channels inside modern applications. Password resets,…

3 days ago

Nginx Commands in Linux: Start, Stop, Reload, Test, and Log

Nginx is a high-performance web server and reverse proxy trusted by some of the largest…

6 days ago

ufw Command in Linux: Manage Firewall Rules with Examples

ufw (Uncomplicated Firewall) sits on top of iptables (or nftables on newer systems) and replaces…

6 days ago

who Command in Linux: Show All Logged-In Users and Sessions

When you share a server with a team or investigate unexpected activity, the first question…

6 days ago