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

groupdel Command in Linux: Remove a Group and Audit Files

The groupdel command in Linux removes a group from the system. It deletes the group's entry from /etc/group and /etc/gshadow,…

9 hours ago

wc Command in Linux: Count Lines, Words, Characters, and Bytes

The wc command in Linux counts lines, words, characters, and bytes in files or standard input. It…

9 hours ago

top Command in Linux: Monitor Processes and Resource Usage

The top command in Linux provides a real-time view of running processes and system resource usage. From…

9 hours ago

usermod Command in Linux: Modify User Accounts and Groups

The usermod command in Linux modifies existing user account attributes. You can use it to manage group…

9 hours ago

sort Command in Linux: Sort Text, Numbers, Columns, and More

The sort command in Linux reads lines from files or standard input and writes them to standard…

1 day ago

wall Command in Linux: Broadcast Messages to Logged-In Users

The wall command in Linux sends a message to the terminals of all currently logged-in users. The…

1 day ago