We are committed to provide service 24 X 7

Deals, Shopping, Training, Tools

Learn how to – How To Install MariaDB 10.6 on Debian 11/10/9

Learn how to – How To Install MariaDB 10.6 on Debian 11/10/9.

MariaDB is a popular open source relational databases, developed by MySQL developers. Unlike MySQL, MariaDB was meant to be totally free for use. Its development puts a lot of considerations on performance and stability. MariaDB is also mostly preferred for being robust and scalable with new storage engines. MariaDB 10.6 also comes with a number of improvements from version 10.5 and some additional features. mariaDB has different tools and plugins that make it widely applicable. It is the default database in most Linux distributions.

This guide presents a step-by-step installation of MariaDB 10.6 on Debian 11/10/9 from MariaDB APT repository.

MariaDB 10.6 is the current stable version of MariaDB and comes with a number of improvements and new features as discussed below:

New Features of MariaDB 10.6

  • Ignored Indexes – These are indexes that are visible and maintained but not used by the optimizer
  • sys schema supported– This is a “system” database containing views and procedures for investigating performance problems.
  • SKIP LOCKED – Locked tables are skipped from being updated or selected.
  • JSON_TABLE() – can create a JSON table that can be used as a subquery from a JSON document.
  • OFFSET…FETCH…[WITH TIES] – WITH TIES is an optional clause that adds extra functionality. Example as used
  • Oracle compatibility – There are ongoing works in making MariaDB compatible with OracleDB with some Oracle Syntaxes and functions already added.

Improvements in MariaDB 10.6

Some of the improvements on MariaDB 10.6 from its predecessors include:

  • Atomic DDL – CREATE, ALTER, DROP and RENAME are atomic and crash safe. If MariaDB server crashes while processing any of these operations, the change will either e done completely or not done at all.
  • InnoDB improvements – First insert to an empty table is faster. Also writes to temporary tables are avoided.Faster implicit and explicit temporary tables.
  • Improvements in Galera. Ability to enable encrypted connections between two nodes without downtime. Also added flags to specify if galera controversial compatible features should be enabled.
  • Clean up to remove unsupported features such as TukoDB Engine, Cassandra Engine, some InnoDB variables and some innodb_checksum_algorithm.

Installing MariaDB 10.6 on Debian 11/10/9

Follow the next steps to install MariaDB 10.6 on your latest Debian Servers

Step 1: System Upgrade

It is always recommend to have the latest system packages before installation to avoid dependency issues. Run the below commands:

sudo apt update && sudo apt upgrade -y

Check if a reboot is required after update.

[ -f /var/run/reboot-required ] && sudo reboot -f

Step 2: Install required Packages

Next, install necessary packages as below:

sudo apt install curl software-properties-common dirmngr -y

Step 3: Add MariaDB APT Repository

Run the below commands respectively to import MariaDB signing key and add MariaDB APT repository

curl -LsS -O https://downloads.mariadb.com/MariaDB/mariadb_repo_setup
sudo bash mariadb_repo_setup --mariadb-server-version=10.6

If successful the output should be similar to below.

# [info] Checking for script prerequisites.
# [info] MariaDB Server version 10.6 is valid
# [info] Repository file successfully written to /etc/apt/sources.list.d/mariadb.list
# [info] Adding trusted package signing keys...
# [info] Running apt-get update...
# [info] Done adding trusted package signing keys

Step 4: Install MariaDB on Debian 11/10/9

Next, update packages and install MariaDB server

sudo apt update
sudo apt install mariadb-server mariadb-client

Proceed to install MariaDB packages and all its dependencies:

....
The following NEW packages will be installed:
  galera-4 gawk libcgi-fast-perl libcgi-pm-perl libclone-perl libdaxctl1 libdbd-mariadb-perl libdbi-perl libencode-locale-perl libfcgi-bin libfcgi-perl
  libfcgi0ldbl libgdbm-compat4 libhtml-parser-perl libhtml-tagset-perl libhtml-template-perl libhttp-date-perl libhttp-message-perl libio-html-perl
  liblwp-mediatypes-perl libmariadb3 libmpfr6 libndctl6 libperl5.32 libpmem1 libsigsegv2 libterm-readkey-perl libtimedate-perl liburi-perl lsof mariadb-client
  mariadb-client-10.6 mariadb-client-core-10.6 mariadb-common mariadb-server mariadb-server-10.6 mariadb-server-core-10.6 mysql-common perl perl-modules-5.32
  rsync
0 upgraded, 41 newly installed, 0 to remove and 0 not upgraded.
Need to get 37.5 MB of archives.
After this operation, 265 MB of additional disk space will be used.
Do you want to continue? [Y/n] y

Step 5: Start and Enable MariaDB

Now run the following commands to start MariaDB and enable it to automatically start on system reboot

sudo systemctl start mariadb
sudo systemctl enable mariadb

Confirm that MariaDB is running

$ sudo systemctl status mariadb
● mariadb.service - MariaDB 10.6.12 database server
     Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor pres>
    Drop-In: /etc/systemd/system/mariadb.service.d
             └─migrated-from-my.cnf-settings.conf
     Active: active (running)  since Tue 2023-04-04 13:36:39 UTC; 21min ago
       Docs: man:mariadbd(8)
             https://mariadb.com/kb/en/library/systemd/
 

Step 6: Secure MariaDB Installation

Once MariaDB is successfully installed, proceed to secure it as below:

$ sudo mariadb-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
haven't set the root password yet, you should just press enter here.

Enter current password for root (enter for none): 
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] Y
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: 
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!

Step 7: Check MariaDB Version

To check MariaDB version, we need to login to MariaDB as below. Use -p if you have set the root password.

$ mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or g.
Your MariaDB connection id is 31
Server version: 10.6.12-MariaDB-1:10.6.12+maria~deb11 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)]>

Then run the following MySQL command to check MariaDB version

MariaDB [(none)]> SELECT VERSION();
+---------------------------------------+
| VERSION()                             |
+---------------------------------------+
| 10.6.12-MariaDB-1:10.6.12+maria~deb11 |
+---------------------------------------+
1 row in set (0.000 sec)

MariaDB [(none)]> exit
Bye

Step 8: MariaDB Basic Commands

To get started with basic commands, we can check to create a database, users and tables.

MariaDB Create Database

To create a database in MariaDB, login as shown above and run the below command.

#Create a new database
MariaDB [(none)]> CREATE DATABASE testdb;

#If the database with the same exists
MariaDB [(none)]> CREATE DATABASE testdb;
ERROR 1007 (HY000): Can't create database 'testdb'; database exists

#Create a database if already exits
MariaDB [(none)]> CREATE OR REPLACE DATABASE testdb;
Query OK, 2 rows affected (0.009 sec)

#First check if a database exists 
MariaDB [(none)]> CREATE DATABASE IF NOT EXISTS testdb;
Query OK, 1 row affected, 1 warning (0.000 sec)

# Check Databases MariaDB
MariaDB [(none)]> SHOW DATABASES;

MariaDB add User and Grant Privileges

To create a user and grant privileges;

#Create user mariadb
CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'mypassword';

#Grant all privileges to the user
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'localhost' IDENTIFIED BY 'mypassword';

#Grant privileges to a specific database
GRANT ALL PRIVILEGES ON 'DB1'.* TO 'user1'@'localhost';

#Remember to refresh the privileges
FLUSH privileges;

#To check user grants in MariaDB
SHOW GRANTS FOR 'myuser'@'locahost';

Create a Table and Add Data MariaDB

Once you have created a database, you can create table and add data into it

CREATE TABLE employees (id INT, name VARCHAR(20), email VARCHAR(20));
INSERT INTO employees (id,name,email) VALUES(01,"lorna","lorna@example.com")

MariaDB Clean up

To completely remove MariaDB, run the following commands.

sudo apt purge mariadb-server
sudo rm -rf /var/lib/mysql/

That’s it. You have successfully installed MariaDB 10.6 on Debian 11/10/9. It is a simple and straightforward installation. I hope the guide has been helpful.

More interesting guides below:

Cart

Your Cart is Empty

Back To Shop