MariaDB is an opensource relational database server. Which is made by the original developers of MySQL. MariaDB intended to maintain high compatibility with the MySQL server, APIs and commands.
This tutorial will help you to install Mariadb database server on your Ubuntu 20.04 LTS system.
- Running Ubuntu 20.04 system
- Login access with root or sudo privileged account
Step 1 – Setup Repository
The Default packages repositories contains old versions of Mariadb server. So, it will be good to use official repository, which provides latest version of packages.
First, add the package signing key to your system by running commands:
sudo apt install software-properties-common sudo apt-key adv --fetch-keys 'https://mariadb.org/mariadb_release_signing_key.asc'
Then, create a apt configuration file on your Ubuntu system. To create file run command:
sudo nano /etc/apt/sources.list.d/mariadb.list
Add below content to file.
# MariaDB 10.4 Repository deb [arch=amd64] http://nyc2.mirrors.digitalocean.com/mariadb/repo/10.4/ubuntu focal main deb-src http://nyc2.mirrors.digitalocean.com/mariadb/repo/10.4/ubuntu focal main
Save file and close.
Step 2 – Install MariaDB on Ubuntu
The official MariaDB repository contains latest version of MariaDB server packages.
Once you added the package repository, run the following commands to install MariaDB server packages and required dependencies.
sudo apt update sudo apt install mariadb-server
The above command will install Mariadb server, client tools and other required packages on your system.
Step 3 – Post Installation Setup
MariaDB package provides a command line utility to complete post installation steps. Which includes to configure password for root user and removing unnecessary database from default installation.
To run the MariaDB post installation wizard, type:
A wizard will prompt for some inputs to setup MaraiDB root user password. Secure your MariaDB installation by removing anonymous users, disable root login from remote host and remove test databases.
A preferred choice is to say yes (‘y’) for all the question:
- Enter current password for root (enter for none):
[ JUST PRESS ENTER ]
- Set root password? [Y/n] y
- New password:
[ ENTER A SECURE PASSWORD ]
- Re-enter new password:
[ CONFIRM YOUR PASSWORD ]
- Remove anonymous users? [Y/n] y
- Disallow root login remotely? [Y/n] y
- Remove test database and access to it? [Y/n] y
- Reload privilege tables now? [Y/n] y
Step 4 – Connect to MariaDB
MaraiDB packages provides an command line utility to connect database server via command line. Where you can completely manage your database server.
To connect MariaDB server run below command on terminal:
mysql -u root -p
Enter the password for root account configured in above step.
Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 57 Server version: 10.4.13-MariaDB-1:10.4.13+maria~focal-log mariadb.org binary distribution Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. MariaDB [(none)]>
Step 5 – Manage Mariadb Service
The latest version of Ubuntu systems uses systemd to manage services. You can use the following commands manage Mariadb service on your system.
sudo systemctl start mariadb # To start service sudo systemctl stop mariadb # To stop service sudo systemctl status mariadb # To check status of service sudo systemctl restart mariadb # To stop and then start service
Step 6 – Create Database and User (Optional)
This is optional step for you. The below commands help you to create a database, a user and assign privilege to user on database.
To use below commands, first, you must be connected to the MariaDB server via command line.
CREATE DATABASE mydb;
CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'my_secure_password';
GRANT ALL ON mydb.* TO 'myuser'@'localhost';
In this tutorial, you have learned about to install MariaDB on Ubuntu Linux system. Next, you can install phpMyAdmin to administer MySQL server via web based interface.