MariaDB is an open-source 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 the MariaDB on Ubuntu 20.04 LTS system.
Prerequisites
- Running Ubuntu 20.04 system
- Login access with root or sudo privileged account
Step 1 – Setup Repository
The Default packages repositories contain old versions of the MariaDB server. So, it will be good to use the official repository, which provides the 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 the below snippet
# 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 the 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 the 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. This includes configuring a password for the root user and removing unnecessary databases from the default installation.
To run the MariaDB post installation wizard, type:
sudo mysql_secure_installation
A wizard will prompt for some inputs to set up the MariaDB root user password. Secure your MariaDB installation by removing anonymous users, disabling root login from a remote host, and removing 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
MariaDB packages provide a command-line utility to connect database servers via the 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 the root account configured in the 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 to manage the 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 an optional step for you. The below commands help you to create a database, a user, and assign privilege to the user on the database.
To use the below commands, first, you must be connected to the MariaDB server via the command line.
1 2 3 4 | CREATE DATABASE mydb; CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'my_secure_password'; GRANT ALL ON mydb.* TO 'myuser'@'localhost'; FLUSH PRIVILEGES; |
Conclusion
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.
1 Comment
There are broken dependencies which are preventing installation. Here is what I get when I do sudo apt install mariadb-server:
Reading package lists… Done
Building dependency tree
Reading state information… Done
Some packages could not be installed. This may mean that you have
requested an impossible situation or if you are using the unstable
distribution that some required packages have not yet been created
or been moved out of Incoming.
The following information may help to resolve the situation:
The following packages have unmet dependencies:
mariadb-server : Depends: mariadb-server-10.4 (>= 1:10.4.34+maria~ubu2004) but it is not installable
E: Unable to correct problems, you have held broken packages.