Friday, November 1, 2024
Google search engine
HomeData Modelling & AIHow To Install MariaDB 10.7 on Debian 11 / Debian 10

How To Install MariaDB 10.7 on Debian 11 / Debian 10

A database is a key component for every production environment. MariaDB is a free and commercially supported fork of the MySQL relational database management system. Just like MySQL, Maria DB has gained popularity ever since its invention in 2009. Its invention was spearheaded by the fear of MySQL acquisition by Oracle Inc and suddenly becoming a paid service. Therefore, MariaDB was developed with the intention of acting as a drop-in replacement for MySQL. MariaDB maintains high compatibility with MySQL with library binary parity and exact API and commands matching with MySQL.

The latest release, MariaDB 10.7 comes with improvements:

  • Password reuse prevention plugin
  • JSON Histograms: improve histogram collection
  • Compression provider plugins
  • UUID data type
  • A function for natural sorting of strings
  • Custom formatting of strings in MariaDB queries
  • Convert table to partition and vice-versa

This guide aims to demonstrate systematically, how to Install MariaDB 10.7 on Debian 11 / Debian 10.

Step 1. Update your system

Before we plunge into the crux of this matter, you need to have your system packages updated to their latest stable versions.

sudo apt update
sudo apt upgrade -y

Step 2. Install Dependencies on Debian 11 / Debian 10

Install the required packages for the installation of MariaDB 10.7 as below.

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

Step 3. Add MariaDB 10.7 Repository on Debian 11 / Debian 10

Now before we can install this new MariaDB version, we need to add the repository for MariaDB.

There are two methods to add the MariaDB 10.7 repository on Debian 11 / Debian 10.

  • Using the official MariaDB bash script
  • Using Mirror Servers

3.1 Add MariaDB 10.7 Repo using Official Bash Script

This s the preferred official method to add MariaDB repositories since all the updates are instantly received once deployed in the repository. Although users far away from these servers face problems through not a common issue to the majority.

curl -LsS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash -s -- --mariadb-server-version=10.7 --skip-maxscale --skip-tools

Sample Output:

[info] Checking for script prerequisites.
[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

3.2 Add MariaDB 10.7 using Mirror Server

This is yet another method you can use to add the MariaDB 10.7 repository on your Debian 11 / Debian 10 system.

First import the GPG key signing as below.

sudo apt-key adv --fetch-keys 'https://mariadb.org/mariadb_release_signing_key.asc'

Now add the repository for MariaDB as below.

## Debian 11 ###
sudo add-apt-repository 'deb [arch=amd64,i386,arm64,ppc64el] https://mariadb.mirror.liquidtelecom.com/repo/10.7/debian bullseye main'

### Debian 10 ###
sudo add-apt-repository 'deb [arch=amd64,i386,arm64,ppc64el] https://mariadb.mirror.liquidtelecom.com/repo/10.7/debian buster main'

Step 4. Install MariaDB 10.7 on Debian 11 / Debian 10

Regardless of whichever method you used to add the MariaDB repository, update your APT package index and install MariaDB 10.7 as demonstrated.

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

Dependency tree:

The following additional packages will be installed:
  galera-4 gawk libcgi-fast-perl libcgi-pm-perl libconfig-inifiles-perl
  libdaxctl1 libdbd-mariadb-perl libdbi-perl libfcgi-bin libfcgi-perl
  libfcgi0ldbl libhtml-template-perl libmariadb3 libndctl6 libpmem1
  libsigsegv2 libterm-readkey-perl mariadb-client-10.7
  mariadb-client-core-10.7 mariadb-common mariadb-server-10.7
  mariadb-server-core-10.7 mysql-common rsync socat
Suggested packages:
  gawk-doc libmldbm-perl libnet-daemon-perl libsql-statement-perl
  libipc-sharedcache-perl mailx mariadb-test netcat-openbsd
The following NEW packages will be installed:
  galera-4 gawk libcgi-fast-perl libcgi-pm-perl libconfig-inifiles-perl
  libdaxctl1 libdbd-mariadb-perl libdbi-perl libfcgi-bin libfcgi-perl
  libfcgi0ldbl libhtml-template-perl libmariadb3 libndctl6 libpmem1
  libsigsegv2 libterm-readkey-perl mariadb-client mariadb-client-10.7
  mariadb-client-core-10.7 mariadb-common mariadb-server
  mariadb-server-10.7 mariadb-server-core-10.7 mysql-common rsync socat
0 upgraded, 27 newly installed, 0 to remove and 13 not upgraded.
Need to get 28.1 MB of archives.
After this operation, 216 MB of additional disk space will be used.
Do you want to continue? [Y/n] y

Once the installation is complete, verify the installed MariaDB version.

$ mariadb --version
mariadb  Ver 15.1 Distrib 10.7.1-MariaDB, for debian-linux-gnu (x86_64) using readline EditLine wrapper

Step 5. Manage MariaDB 10.7 on Debian 11 / Debian 10.

MariaDB is managed as a systemd servicea nd can be started using the command:

sudo systemctl start mariadb

Check the status of MariaDB.

$ systemctl status mariadb
● mariadb.service - MariaDB 10.7.1 database server
     Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor preset: enabled)
    Drop-In: /etc/systemd/system/mariadb.service.d
             └─migrated-from-my.cnf-settings.conf
     Active: active (running) since Tue 2021-11-23 04:23:21 EST; 41s ago
       Docs: man:mariadbd(8)
             https://mariadb.com/kb/en/library/systemd/
    Process: 62865 ExecStartPre=/usr/bin/install -m 755 -o mysql -g root -d /var/run/mysqld (code=exited, status=0/SUCCESS)
    Process: 62866 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
    Process: 62868 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= ||   VAR=`cd /usr/bin/..; /usr/bin/galera_recovery`; [ $? -eq 0 >
    Process: 62931 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
    Process: 62933 ExecStartPost=/etc/mysql/debian-start (code=exited, status=0/SUCCESS)
   Main PID: 62915 (mariadbd)
     Status: "Taking your SQL requests now..."
      Tasks: 15 (limit: 4663)
     Memory: 83.5M
        CPU: 815ms
     CGroup: /system.slice/mariadb.service
             └─62915 /usr/sbin/mariadbd

Enable MariaDB to run automatically on boot.

sudo systemctl enable mariadb

This service can be restarted as below.

sudo systemctl restart mariadb

Step 6. Secure MariaDB Installation on Debian

Once MariaDB is installed, the instance is not secure, we, therefore, need to harden the installation by creating a password for the root user.

sudo mysql_secure_installation 

Proceed as below.

Enter current password for root (enter for none): Press Enter
....
Switch to unix_socket authentication [Y/n] y
.......
Change the root password? [Y/n] y
New password: Enter Password
Re-enter new password: Re-Enter 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
.....
Thanks for using MariaDB!

Step 7. Use MariaDB 10.7 on Debian 11 / Debian 10

We will now test the installed MariaDB 10.7 to see if it is working perfectly. First login to the MariaDB shell.

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

Create a Database in MariaDB.

To create a database, let’s say testdb, run the command:

CREATE DATABASE testdb;

You can also replace the database if it exists.

CREATE OR REPLACE DATABASE testdb;

Check if the database has been created by showing all available databases.

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

Create a User and Grant Privileges.

User the commands below to create and assign privileges to users in MariaDB.

#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 'testdb'.* TO 'myuser'@'localhost';

#Grant privileges to all databases
GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'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 to MariaDB.

With a database created, add you can create a table and add data into it as below.

USE testdb;
CREATE TABLE employees (id INT, name VARCHAR(20), email VARCHAR(20));
INSERT INTO employees (id,name,email) VALUES(01,"thor","[email protected]");

Show tables in the database:

MariaDB [testdb]> show tables;
+------------------+
| Tables_in_testdb |
+------------------+
| employees        |
+------------------+
1 row in set (0.000 sec)

SHow columns in the table.

MariaDB [testdb]> SHOW COLUMNS FROM employees;
+-------+-------------+------+-----+---------+-------+
| Field | Type        | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id    | int(11)     | YES  |     | NULL    |       |
| name  | varchar(20) | YES  |     | NULL    |       |
| email | varchar(20) | YES  |     | NULL    |       |
+-------+-------------+------+-----+---------+-------+
3 rows in set (0.001 sec)

Exit the mariaDB shell.

MariaDB [testdb]> exit
Bye

Step 8. Remove/Uninstall MariaDB on Debian 11 / Debian 10 (Bonus)

You can uninstall and completely remove MariaDB on your Debian 11 / Debian 10 using:

##Remove data from MariaDB
sudo apt purge mariadb-server
sudo rm -rf /var/lib/mysql/

Completely uninstall MariaDB on your system.

sudo apt autoremove mariadb-server mariadb-client

Conclusion.

That marks the end of this guide! You have managed to install MariaDB 10.7 on Debian 11 / Debian 10. I hope you found this guide significant.

See more guides:

RELATED ARTICLES

Most Popular

Recent Comments