Thursday, July 4, 2024
HomeDatabasesHow To Install MariaDB Server on Ubuntu 22.04|20.04

How To Install MariaDB Server on Ubuntu 22.04|20.04

MariaDB is the most powerful and widely used relational database management system developed by the MariaDB Foundation. We have many articles on the installation of MariaDB on various Linux distributions. This guide will focus on the installation of MariaDB on Ubuntu 22.04|20.04 Linux system.

For those new to MariaDB, it is a community-developed fork of MySQL database system. It was primarily designed to be free and open source, without any compromise in speed, stability and scalability. Most Linux distributions will have MariaDB in their upstream repositories available for quick installation with the default OS package manager.

Install MariaDB Server and Client packages

We always start our installations by ensuring the system is updated. This can be achieved by running the commands:

sudo apt update
sudo apt -y upgrade

Once the system is updated, use the following commands to install MariaDB Server on Ubuntu22.04|20.04.

sudo apt install software-properties-common mariadb-server mariadb-client

Confirm that the service is started.

$ systemctl status mariadb
 mariadb.service - MariaDB 10.6.12 database server
     Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
     Active: active (running) since Mon 2023-08-21 14:14:41 UTC; 11s ago
       Docs: man:mariadbd(8)
             https://mariadb.com/kb/en/library/systemd/
    Process: 120995 ExecStartPre=/usr/bin/install -m 755 -o mysql -g root -d /var/run/mysqld (code=exited, status=0/SUCCESS)
    Process: 120996 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
    Process: 120998 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= ||   VAR=`cd /usr/bin/..; /usr/bin/galera_recovery`; [ $? -eq 0 ]   && systemctl set-environment _WSREP_START_P>
    Process: 121043 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
    Process: 121045 ExecStartPost=/etc/mysql/debian-start (code=exited, status=0/SUCCESS)
   Main PID: 121027 (mariadbd)
     Status: "Taking your SQL requests now..."
      Tasks: 17 (limit: 18678)
     Memory: 61.1M
        CPU: 732ms
     CGroup: /system.slice/mariadb.service
             └─121027 /usr/sbin/mariadbd

Aug 21 14:14:41 jammy mariadbd[121027]: 2023-08-21 14:14:41 0 [Note] InnoDB: Buffer pool(s) load completed at 230821 14:14:41
Aug 21 14:14:41 jammy mariadbd[121027]: 2023-08-21 14:14:41 0 [Note] /usr/sbin/mariadbd: ready for connections.
Aug 21 14:14:41 jammy mariadbd[121027]: Version: '10.6.12-MariaDB-0ubuntu0.22.04.1'  socket: '/run/mysqld/mysqld.sock'  port: 3306  Ubuntu 22.04
Aug 21 14:14:41 jammy systemd[1]: Started MariaDB 10.6.12 database server.
Aug 21 14:14:42 jammy /etc/mysql/debian-start[121050]: Looking for 'mariadb' as: /usr/bin/mariadb
Aug 21 14:14:42 jammy /etc/mysql/debian-start[121050]: Looking for 'mariadb-check' as: /usr/bin/mariadb-check
Aug 21 14:14:42 jammy /etc/mysql/debian-start[121050]: This installation of MariaDB is already upgraded to 10.6.12-MariaDB.
Aug 21 14:14:42 jammy /etc/mysql/debian-start[121050]: There is no need to run mysql_upgrade again for 10.6.12-MariaDB.
Aug 21 14:14:42 jammy /etc/mysql/debian-start[121050]: You can use --force if you still want to run mysql_upgrade
Aug 21 14:14:42 jammy /etc/mysql/debian-start[121058]: Checking for insecure root accounts.

By default, you should be able to access the mysql command line as root user without being prompted to provide a password. Let’s ensure we harden our MariaDB server and set the root password.

$ sudo mysql_secure_installation 

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
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] y
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!

Confirm MariaDB Server Installation

Let’s confirm our installation of MariaDB server on Ubuntu22.04/20.04:

$ mysql -V
mysql  Ver 15.1 Distrib 10.6.12-MariaDB, for debian-linux-gnu (x86_64) using  EditLine wrapper

Create a test database.

$ sudo mysql -u root -p
MariaDB [(none)]> CREATE DATABASE testdb;
Query OK, 1 row affected (0.000 sec)

MariaDB [(none)]> DROP  DATABASE testdb;
Query OK, 0 rows affected (0.001 sec)

MariaDB [(none)]> QUIT
Bye

Enjoy using MariaDB database server on Ubuntu22.04|20.04 Linux system. For other systems, check:

Thapelo Manthata
I’m a desktop support specialist transitioning into a SharePoint developer role by day and Software Engineering student by night. My superpowers include customer service, coding, the Microsoft office 365 suite including SharePoint and power platform.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments