HomeDATABASEHow To Install MariaDB 10.6 on Ubuntu 22.04|20.04|18.04

How To Install MariaDB 10.6 on Ubuntu 22.04|20.04|18.04

This article will show How To Install MariaDB 10.6 on Ubuntu 22.04|20.04|18.04. MariaDB is an open-source database that is free to use. MariaDB was created in 2010 after Oracle purchased MySQL, and MySQL developers assumed that MySQL would now be updated as a paid service. So they wanted to create a database that was free and open source, and it used MySQL strategies.

Install MariaDB 10.6 on Ubuntu 22.04|20.04|18.04

To Install MariaDB 10.6 on Ubuntu 22.04|20.04|18.04, adhere to the instructions provided below.

Let’s get started;

1. Update the system

First and foremost, update the system packages to the most recent updates.

sudo apt update

2. Install necessary packages

To install packages required for MariaDB 10.6 installation, run the following command;

sudo apt-get install wget software-properties-common dirmngr ca-certificates apt-transport-https -y

3. Install MariaDB 10.6 on Ubuntu 22.04|20.04|18.04

Use the following command in the terminal to install MariaDB 10.6 on Ubuntu 22.04|20.04|18.04.

sudo apt install mariadb-server mariadb-client

Sample output:

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
The following packages were automatically installed and are no longer required:
  libflashrom1 libftdi1-2 linux-headers-5.15.0-25 linux-headers-5.15.0-25-generic linux-image-5.15.0-25-generic
  linux-modules-5.15.0-25-generic linux-modules-extra-5.15.0-25-generic
Use 'sudo apt autoremove' to remove them.
0 upgraded, 29 newly installed, 0 to remove and 4 not upgraded.
Need to get 18.7 MB of archives.
After this operation, 165 MB of additional disk space will be used.
Do you want to continue? [Y/n] y
Check MariaDB version
$ mariadb --version
mariadb  Ver 15.1 Distrib 10.6.11-MariaDB, for debian-linux-gnu (x86_64) using  EditLine wrapper

4. Check MariaDB 10.06 Status

Then, use the following command to see if MariaDB is active and running:

systemctl status mariadb

Output:

 mariadb.service - MariaDB 10.6.11 database server
     Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
     Active: active (running) since Wed 2022-11-30 12:51:21 EAT; 3min 32s ago
       Docs: man:mariadbd(8)
             https://mariadb.com/kb/en/library/systemd/
    Process: 9045 ExecStartPre=/usr/bin/install -m 755 -o mysql -g root -d /var/run/mysqld (code=exited, status=0/SUCCESS)
    Process: 9046 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
    Process: 9048 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= ||   VAR=`cd /usr/bin/..; /usr/bin/galera_r>
    Process: 9090 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
    Process: 9092 ExecStartPost=/etc/mysql/debian-start (code=exited, status=0/SUCCESS)
   Main PID: 9077 (mariadbd)
     Status: "Taking your SQL requests now..."
      Tasks: 8 (limit: 4625)
     Memory: 66.9M
        CPU: 760ms
     CGroup: /system.slice/mariadb.service
             └─9077 /usr/sbin/mariadbd

5. Secure MariaDB 10.06 Database

In order to safeguard our database from hackers and other intrusions, we will install the security script with the MariaDB installation in this step;

sudo mysql_secure_installation

Sample output:

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): <PRESS ENTER>
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
Enabled successfully!
Reloading privilege tables..
 ... Success!


You already have your root account protected, so you can safely answer 'n'.

Change the root password? [Y/n] y
New password:<Enter New Password>
Re-enter new password:<Re-Enter New Password>
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
 ... 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
 ... 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
 - Dropping test database...
 ... 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
 ... 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!

Now you can log in to MariaDB through the command below;

sudo mariadb

Sample output;

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 39
Server version: 10.6.11-MariaDB-0ubuntu0.22.04.1 Ubuntu 22.04

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)]>

The next step is to flush all privileges before continuing;

MariaDB [(none)]> flush privileges;
Query OK, 0 rows affected (0.001 sec)

6. Create MariaDB Database

Then, using the following command, create the Maria database:

MariaDB [(none)]> CREATE DATABASE tutordb;

Query OK, 1 row affected (0.001 sec)

MariaDB [(none)]> 

You can choose the name of your database, for this guide I created “tutordb“.

Now view your database already created using the command below:

MariaDB [(none)]> SHOW DATABASES;
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
| performance_schema |
| sys                |
| tutordb            |
+--------------------+
5 rows in set (0.062 sec)

MariaDB [(none)]> 

7. Create MariaDB User

In the following step, enter the following command to create a MariaDB user:

MariaDB [(none)]> CREATE USER 'tutornix'@'localhost' IDENTIFIED BY 'new_password';
Query OK, 0 rows affected (0.283 sec)

MariaDB [(none)]> 

Then grant all privileges to the created MariaDB “tutornix” user;


MariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* to 'tutornix'@'localhost';
Query OK, 0 rows affected (0.384 sec)

MariaDB [(none)]> 

Finally, type “quit” to exit the active MariaDB shell:

MariaDB [(none)]>  quit;
Bye

Conclusion

We have completed our tutorial on how to install MariaDB on Ubuntu 22.04|20.04. Cheers!

Read more about MariaDB.

Check out below cool articles:

- Advertisment -

Recent posts

LEAVE A REPLY

Please enter your comment!
Please enter your name here