11

Install MariaDB 10.6 on Debian 10| Debian 9

 3 years ago
source link: https://computingforgeeks.com/how-to-install-mariadb-on-debian-linux/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client
Install MariaDB 10.6 on Debian 10| Debian 9
Search

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 10 and Debian 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 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
sudo reboot

Step 2: Install required Packages

Next, install necessary packages as below:

sudo apt-get install software-properties-common dirmngr

Step 3: Add MariaDB Signing Key and APT Repository

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

For Debian 10 (Buster)

sudo apt-key adv --fetch-keys 'https://mariadb.org/mariadb_release_signing_key.asc'
sudo add-apt-repository 'deb [arch=amd64,arm64,ppc64el] https://mariadb.mirror.liquidtelecom.com/repo/10.6/debian buster main'

For Debian 9 “Stretch”

sudo apt-key adv --fetch-keys 'https://mariadb.org/mariadb_release_signing_key.asc'
sudo add-apt-repository 'deb [arch=amd64,arm64,i386,ppc64el] https://mariadb.mirror.liquidtelecom.com/repo/10.6/debian stretch main'

Step 4: Install MariaDB on Debian 10|9

Next, update packages and install MariaDB server

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

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.3 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 Wed 2021-07-28 23:03:14 EAT; 8min 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 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
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 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)]>

Then run the following MySQL command to check MariaDB version

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

MariaDB [(none)]>

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
CREATE DATABASE testdb;
Query OK, 1 row affected (0.000 sec)

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

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

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

# Check Databases MariaDB
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","[email protected]")

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 10 and Debian 9. It is a simple and straightforward installation. I hope the guide has been helpful.

Udemy Video Courses to Learn MySQL / MariaDB Databases:

More interesting guides below:


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK