How to Install Mariadb on Ubuntu 20.04 step by step tutorial. MariaDB is an open-source relational database management system and drop-in replacement for the MySQL database. It is used with LAMP or LEMP stack to store data. MariaDB is continuously gaining popularity due to its performance and faster query response. It supports SQL and allows you to use SQL queries to insert, manipulate, and retrieve data from MariaDB. It comes with a variety of plugins and tools to exaggerate its features. It is used by many big companies including, Alibaba Travels, Walmart, Accenture, UpstageAI, BirdView, Bagelcode, Google, Wikipedia, WordPress and many more.
Table of Contents
In this post, we will show you how to install and use MariaDB on Ubuntu 20.04 server.
By default, the latest version of MariaDB is not included in the Ubuntu 2.04 default repository. So it is recommended to add the MariaDB official repository to get the latest MariaDB version.
First, install the required dependencies by running the following command:
Now, you can install the MariaDB server and client package by running the following command:
apt-get install mariadb-server mariadb-client -y
After the installation, start the MariaDB service and enable it to start at system reboot:
systemctl start mariadb
systemctl enable mariadb
Next, you can verify the MariaDB installed version with the following command:
mysqladmin version
You should get the MariaDB version in the following output:
mysqladmin Ver 9.1 Distrib 10.5.12-MariaDB, for debian-linux-gnu on x86_64
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Server version 10.5.12-MariaDB-1:10.5.12+maria~focal
Protocol version 10
Connection Localhost via UNIX socket
UNIX socket /run/mysqld/mysqld.sock
Uptime: 19 sec
Threads: 1 Questions: 466 Slow queries: 0 Opens: 171 Open tables: 28 Queries per second avg: 24.526
By default, MariaDB listens on port 3306. You can check it by running the following command:
ss -antpl | grep mariadb
You should see the MariaDB listening port in the following output:
After installing the MariaDB server, it is a good idea to secure the MariaDB installation and set a MariaDB root password. You can perform this by executing the mysql_secure_installation script:
mysql_secure_installation
You will be asked to provide your current MariaDB root password if you have set:
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MariaDB
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MariaDB to secure it, we'll need the current
password for the root user. If you've just installed MariaDB, and
haven't set the root password yet, you should just press enter here.
Enter current password for root (enter for none):
If you have not set any password then just press Enter to continue. You will be asked to switch to the unix socket authentication method:
OK, successfully used password, moving on...
Setting the root password or using the unix_socket ensures that nobody
can log into the MariaDB root user without the proper authorisation.
You already have your root account protected, so you can safely answer 'n'.
Switch to unix_socket authentication [Y/n] n
Type n and hit Enter to skip it. You will be asked to change the MariaDB root password:
... skipping.
You already have your root account protected, so you can safely answer 'n'.
Change the root password? [Y/n] Y
New password:
Re-enter new password:
Set your MariaDB root password and press Enter. You will be asked to remove anonymous users.
Password updated successfully!
Reloading privilege tables..
... Success!
By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] Y
Type Y and press Enter. You will be asked to disallow root login remotely:
... Success!
Normally, root should only be allowed to connect from 'localhost'. This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] Y
Type Y and press Enter. You will be asked to remove the test database:
... Success!
By default, MariaDB comes with a database named 'test' that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] Y
Type Y and press Enter. You will be asked reload the privilege tables:
... Success!
- Removing privileges on test database...
... Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] Y
Type Y and press Enter. Once the MariaDB is secured, you should get the following output:
... Success!
Cleaning up...
All done! If you've completed all of the above steps, your MariaDB
installation should now be secure.
Thanks for using MariaDB!
In this section, we will show you how to connect to the MariaDB console, create a Mariadb database, create a table and insert the data in a table.
First, you can log in to the MariaDB console using the following command:
mysql -u root -p
You will be asked to provide your MariaDB root password:
Enter password:
Provide your MariaDB root password and press Enter. Once you are connected, you should get into the MariaDB shell as shown below:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 54
Server version: 10.5.12-MariaDB-1:10.5.12+maria~focal 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)]>
To create a database called persons, run the following command:
MariaDB [(none)]> CREATE DATABASE persons;
To list all databases, run the following command:
MariaDB [(none)]> SHOW DATABASES;
You should see all databases in the following output:
To restore a backup from the persons_back.dump backup file, run the following command:
mysql -u root -p persons < persons_back.dump
To restore all databases, run the following command:
mysql -u root -p < alldb_back.dump
Uninstall MariaDB Database
If you want to remove the MariaDB database from your server, run the following command:
apt-get remove mariadb-server --purge
After removing the MariaDB database, some other unwanted dependencies are still persist in your system. You can remove them by running the following command:
apt-get autoremove
Next, remove all package cache with the following command:
That’s it for now! You have successfully installed the MariaDB database on Ubuntu 20.04 server. You can now use MariaDB as a database backend with LAMP/LEMP stack or other applications.
I am a fan of open source technology and have more than 10 years of experience working with Linux and Open Source technologies. I am one of the Linux technical writers for Cloud Infrastructure Services.
00votes
Article Rating
Subscribe
Login and comment with
I allow to create an account
When you login first time using a Social Login button, we collect your account public profile information shared by Social Login provider, based on your privacy settings. We also get your email address to automatically create an account for you in our website. Once your account is created, you'll be logged-in to this account.
DisagreeAgree
Login and comment with
I allow to create an account
When you login first time using a Social Login button, we collect your account public profile information shared by Social Login provider, based on your privacy settings. We also get your email address to automatically create an account for you in our website. Once your account is created, you'll be logged-in to this account.