MariaDB is a commonly used OpenSource database mainly known for being robust and scalable with new storage engines. MariaDB is a development of MySQL which puts focus on stability and performance and to make it free to users. It is the default database in most Linux distribution. With a variety of tools and plugins, MariaDB is widely applicable.
In this guide, we are going to look at how to install MariaDB 10.6 on CentOS 7 | CentOS 8
Features of MariaDB 10.6
MariaDB 10.6 is the current stable version of MariaDB and comes with a number of new features as discussed below:
- 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.
The Improvements in MariaDB 10.6 from MariaDB 10.5 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.
Step 1: Update System Packages
Ensure that you are running the latest system packages before installation to avoid possible inconveniences with dependencies.
sudo dnf upgrade
Step 2: Add MariaDB Repository
We need to create a MariaDB repo file and add the content for MariaDB installation
curl -LsS -O https://downloads.mariadb.com/MariaDB/mariadb_repo_setup
sudo bash mariadb_repo_setup --mariadb-server-version=10.6
Command execution output:
[info] Checking for script prerequisites.
[info] Repository file successfully written to /etc/yum.repos.d/mariadb.repo
[info] Adding trusted package signing keys...
/etc/pki/rpm-gpg /home/rocky
/home/rocky
[info] Successfully added trusted package signing keys
[info] Cleaning package cache...
62 files removed
Step 3: Install MariaDB 10.6
Once you have saved the repo file, proceed to install MariaDB 10.6
sudo dnf install MariaDB-server MariaDB-client
Step 4: Start and Enable MariaDB
Once installed, start mariadb and also enable it to start automatically on system reboot.
sudo systemctl start mariadb
sudo systemctl enable mariadb
Secure database server installation:
$ 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 5: Check MariaDB Version
We need to first login to MariaDB to be able to check the installed version.
$ mysql -u root -p
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 3
Server version: 10.6.4-MariaDB MariaDB Server
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)]>
You can already see the installed MariaDB version from the output above. However, you can also run the below command to check MariaDB version
MariaDB [(none)]> SELECT VERSION();
+-------------------------------------+
| VERSION() |
+-------------------------------------+
| 10.6.4-MariaDB |
+-------------------------------------+
1 row in set (0.000 sec)
MariaDB [(none)]>
Step 6: Create a Database in MariaDB
Once you login to Mariadb, create a database as below:
#Create a new database
MariaDB [(none)]> CREATE DATABASE db1;
Query OK, 1 row affected (0.000 sec)
#If the database with the same name exists, you should get an error
ERROR 1007 (HY000): Can't create database 'db1'; database exists
#Create a database if already exits, replace
MariaDB [(none)]> CREATE OR REPLACE DATABASE db1;
Query OK, 2 rows affected (0.009 sec)
#First check if a database exists
MariaDB [(none)]> CREATE DATABASE IF NOT EXISTS db1;
Query OK, 1 row affected, 1 warning (0.000 sec)
# Check Databases MariaDB
MariaDB [(none)]> SHOW DATABASES;
Step 7: Create User and Grant Privileges in Mariadb
To create a user and grant privileges to the databases, run the commands as shown:
#Create user mariadb
MariaDB [(none)]> CREATE USER 'myuser'@'localhost' IDENTIFIED BY 'mypassword';
#Grant all privileges to the user
MariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* TO 'myuser'@'localhost' IDENTIFIED BY 'mypassword';
#Grant privileges to a specific database
MariaDB [(none)]> GRANT ALL PRIVILEGES ON 'DB1'.* TO 'user1'@'localhost';
#Remember to refresh the privileges
MariaDB [(none)]> FLUSH privileges;
#To check user grants in MariaDB
MariaDB [(none)]> SHOW GRANTS FOR 'myuser'@'localhost';
Step 8: Creating Table and Adding Data
Since we already have a database, we can proceed to create a table and add some values.
MariaDB [(none)]> USE db1;
MariaDB [(none)]> CREATE TABLE employees (id INT, name VARCHAR(20), email VARCHAR(20));
MariaDB [(none)]> INSERT INTO employees (id,name,email) VALUES(01,"lorna","[email protected]")
Cleaning Up MariaDB
To completely remove MariaDB, run the following commands:
sudo dnf remove MariaDB-server MariaDB-client
sudo rm -rf /var/lib/mysql/
sudo rm /etc/my.cnf
You have successfully installed the latest MariaDB version, MariaDB 10.6. We have also seen how you can clean up your MariaDB installation. I hope the guide has been helpful.