Introduction MariaDB 10.6
MariaDB, an open-source relational database management system, is a powerful alternative to MySQL. Its latest version, MariaDB 10.6, brings enhanced features and performance improvements. If you’re using an Ubuntu Server 22.04, this step-by-step guide will walk you through the process of install MariaDB 10.6, ensure optimal performance and data management for your applications.
Table of Contents
- Introduction MariaDB 10.6
- Prerequisites for Install MariaDB 10.6
- Install MariaDB 10.6 on Ubuntu Server 22.04
- Step 1: Update System Packages
- Step 2: Install Required Packages for MariaDB
- Step 3: Add MariaDB Repository
- Step 4: Install MariaDB on Ubuntu 22.04
- Step 5: Start and Enable MariaDB
- Step 6: Install Secure MariaDB
- Step 7: Check MariaDB Version
- Step 8: Basic MariaDB Commands
- Step 9: Optional: Configure MariaDB
- MariaDB Clean up
- Conclusion
Prerequisites for Install MariaDB 10.6
Before we dive into the installation process, there is prerequisite you need to ensure are in place:
- Ubuntu Server: Make sure you have a clean installation of Ubuntu Server. To set this up, follow our guide Initial Setup Ubuntu Server 22.04. You can deploy this on a physical machine or a virtual environment like VMware or VirtualBox.
Install MariaDB 10.6 on Ubuntu Server 22.04
Follow these steps to install MariaDB 10.6 on your Ubuntu Server 22.04 and enjoy its benefits:
Step 1: Update System Packages
Start by updating your system’s package list to ensure you’re working with the latest software versions:
samm@mariadb:~$ sudo apt-get update
samm@mariadb:~$ sudo apt-get upgrade
Updating the packages provides a stable foundation for the installation process.
Step 2: Install Required Packages for MariaDB
samm@mariadb:~$ sudo apt-get install wget curl
samm@mariadb:~$ sudo apt-get install software-properties-common dirmngr ca-certificates apt-transport-https -y
Step 3: Add MariaDB Repository
samm@mariadb:~$ sudo curl -o /etc/apt/trusted.gpg.d/mariadb_release_signing_key.asc 'https://mariadb.org/mariadb_release_signing_key.asc'
samm@mariadb:~$ curl -LsS -O https://downloads.mariadb.com/MariaDB/mariadb_repo_setup
samm@mariadb:~$ sudo bash mariadb_repo_setup --os-type=ubuntu --os-version=focal --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
MariaDB APT repository file is located inside the /etc/apt/sources.list.d
directory:
samm@mariadb:~$ cat /etc/apt/sources.list.d/mariadb.list
# MariaDB Server
# To use a different major version of the server, or to pin to a specific minor version, change URI below.
deb [arch=amd64,arm64] https://dlm.mariadb.com/repo/mariadb-server/10.6/repo/ubuntu focal main
deb [arch=amd64,arm64] https://dlm.mariadb.com/repo/mariadb-server/10.6/repo/ubuntu focal main/debug
# MariaDB MaxScale
# To use the latest stable release of MaxScale, use "latest" as the version
# To use the latest beta (or stable if no current beta) release of MaxScale, use "beta" as the version
deb [arch=amd64] https://dlm.mariadb.com/repo/maxscale/latest/apt focal main
# MariaDB Tools
deb [arch=amd64] http://downloads.mariadb.com/Tools/ubuntu focal main
Step 4: Install MariaDB on Ubuntu 22.04
Next, update packages and install MariaDB server
samm@mariadb:~$ sudo apt-get update
samm@mariadb:~$ sudo apt-get install mariadb-server mariadb-client
“During my attempt to install the mariadb-client package, I came across an error notification.”:
mariadb-client-core-10.6 : Depends: libreadline5 (>= 5.2) but it is not installable
The work around was manually download and install libreadline5 package for Debian Buster
samm@mariadb:~$ wget http://ftp.us.debian.org/debian/pool/main/r/readline5/libreadline5_5.2+dfsg-3+b13_amd64.deb
samm@mariadb:~$ wget http://archive.ubuntu.com/ubuntu/pool/main/o/openssl/libssl1.1_1.1.1f-1ubuntu2_amd64.deb
Next install the packages with following command:
samm@mariadb:~$ sudo apt-get -y install libdbd-mysql-perl libssl-dev
samm@mariadb:~$ sudo dpkg -i libreadline5_5.2+dfsg-3+b13_amd64.deb
samm@mariadb:~$ sudo dpkg -i libssl1.1_1.1.1f-1ubuntu2_amd64.deb
The remaining step is install of MariaDB 10.6 Server and Client packages on Ubuntu 22.04:
samm@mariadb:~$ sudo apt-get update
samm@mariadb:~$ sudo apt-get install mariadb-server mariadb-client
Agree to continue with the installation of MariaDB 10.6 on Ubuntu 22.04:
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
After install MariaDB, now run the following commands to start MariaDB and enable it to automatically start on system reboot
samm@mariadb:~$ sudo systemctl start mariadb
samm@mariadb:~$ sudo systemctl enable mariadb
Synchronizing state of mariadb.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable mariadb
Ensure that MariaDB is up and running. You can check its status using:
samm@mariadb:~$ sudo systemctl status mariadb
● mariadb.service - MariaDB 10.6.12 Database Staging
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 Wed 2022-12-14 23:54:00 WIB; 5s ago
Docs: man:mariadbd(8)
https://mariadb.com/kb/en/library/systemd/
Process: 7856 ExecStartPre=/usr/bin/install -m 755 -o mysql -g root -d /var/run/mysqld (code=exited, status=0/SUCCESS)
Process: 7857 ExecStartPre=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
Process: 7859 ExecStartPre=/bin/sh -c [ ! -e /usr/bin/galera_recovery ] && VAR= || VAR=`cd /usr/bin/..; /usr/bin/galera_recovery`; [ $? -eq 0 ] && systemctl set-enviro>
Process: 7897 ExecStartPost=/bin/sh -c systemctl unset-environment _WSREP_START_POSITION (code=exited, status=0/SUCCESS)
Process: 7899 ExecStartPost=/etc/mysql/debian-start (code=exited, status=0/SUCCESS)
Main PID: 7885 (mariadbd)
Status: "Taking your SQL requests now..."
Tasks: 11 (limit: 4676)
Memory: 83.0M
CPU: 257ms
CGroup: /system.slice/mariadb.service
└─7885 /usr/sbin/mariadbd
Dec 14 23:54:00 mariadb mariadbd[7885]: 2022-12-14 23:54:00 0 [Warning] You need to use --log-bin to make --expire-logs-days or --binlog-expire-logs-seconds work.
Dec 14 23:54:00 mariadb mariadbd[7885]: 2022-12-14 23:54:00 0 [Note] Server socket created on IP: '0.0.0.0'.
Dec 14 23:54:00 mariadb mariadbd[7885]: 2022-12-14 23:54:00 0 [Note] Server socket created on IP: '::'.
Dec 14 23:54:00 mariadb mariadbd[7885]: 2022-12-14 23:54:00 0 [Note] InnoDB: Buffer pool(s) load completed at 221214 23:54:00
Dec 14 23:54:00 mariadb mariadbd[7885]: 2022-12-14 23:54:00 0 [Note] /usr/sbin/mariadbd: ready for connections.
Dec 14 23:54:00 mariadb mariadbd[7885]: Version: '10.6.12-MariaDB-1:10.6.12+maria~deb11' socket: '/run/mysqld/mysqld.sock' port: 3306 mariadb.org binary distributi>
Dec 14 23:54:00 mariadb systemd[1]: Started MariaDB 10.6.12 Database Staging.
Dec 14 23:54:00 mariadb /etc/mysql/debian-start[7901]: Upgrading MySQL tables if necessary.
Dec 14 23:54:00 mariadb /etc/mysql/debian-start[7912]: Checking for insecure root accounts.
Dec 14 23:54:00 mariadb /etc/mysql/debian-start[7916]: Triggering myisam-recover for all MyISAM tables and aria-recover for all Aria tables
Step 6: Install Secure MariaDB
Once MariaDB is successfully installed, proceed to secure it as below:
samm@mariadb:~$ 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: [Your Password]
Re-enter new password: [Your 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.
samm@mariadb:~$ mysql -u root -p
Enter password: [Your password]
Welcome to the MariaDB monitor. Commands end with ; or g.
Your MariaDB connection id is 129
Server version: 10.6.11-MariaDB-1:10.6.11+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)]> SELECT VERSION();
+---------------------------------------+
| VERSION() |
+---------------------------------------+
| 10.6.12-MariaDB-1:10.6.11+maria~deb11 |
+---------------------------------------+
1 row in set (0.000 sec)
Step 8: Basic MariaDB Commands
Before you start using MariaDB, here some basic commands:
To access the MariaDB shell, use:
samm@mariadb:~$ mysql -u root -p
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 sammlinux_db;
#If the database with the same exists
MariaDB [(none)]> CREATE DATABASE sammlinux_db;
ERROR 1007 (HY000): Can't create database 'sammlinux_db'; database exists
#Create a database if already exits
MariaDB [(none)]> CREATE OR REPLACE DATABASE sammlinux_db;
Query OK, 2 rows affected (0.009 sec)
#First check if a database exists
MariaDB [(none)]> CREATE DATABASE IF NOT EXISTS sammlinux_db;
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 'sammlinux-user'@'localhost' IDENTIFIED BY 'your-password';
#Grant all privileges to the user
GRANT ALL PRIVILEGES ON *.* TO 'sammlinux-user'@'localhost' IDENTIFIED BY 'your-password';
#Grant privileges to a specific database
GRANT ALL PRIVILEGES ON 'sammlinux_db'.* TO 'sammlinux-user'@'localhost';
#Remember to refresh the privileges
FLUSH privileges;
#To check user grants in MariaDB
SHOW GRANTS FOR 'sammlinux-user'@'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 articles (articles_id INT, name VARCHAR(20), channel VARCHAR(20));
INSERT INTO articles (id,name,email) VALUES(56701,"samm","Linux")
Step 9: Optional: Configure MariaDB
Depending on your requirements, you can configure MariaDB for optimal performance. Open the configuration file:
samm@mariadb:~$ sudo vi /etc/mysql/mariadb.conf.d/50-server.cnf
Here, you can adjust settings like innodb_buffer_pool_size
to allocate memory for caching data, or max_connections
to control the number of concurrent connections.
MariaDB Clean up
To completely remove MariaDB, run the following commands.
samm@mariadb:~$ sudo apt purge mariadb-server
samm@mariadb:~$ sudo rm -rf /var/lib/mysql/
Conclusion
Installing MariaDB 10.6 on your Ubuntu Server 22.04 is a strategic move that brings performance enhancements, security features, and extended functionalities to your applications. By following this step-by-step guide, you’ve ensured a seamless installation process. With MariaDB 10.6’s powerful capabilities, your database management becomes more efficient and robust, positively impacting your applications’ performance and user experience. Embrace the benefits of MariaDB 10.6 and elevate your database management to new heights.
Also Read Our Other Guides :
- How To Install MongoDB 6.0 on Debian 10 & 11
- How To Install MongoDB 6.0 on Rocky Linux 9
- How To Install MariaDB 10.6 on Debian 11 Server
- How To Install MySQL 8.0 on Ubuntu Server 22.04
- How To Install MongoDB 6.0 on Rocky Linux 9
- How To Install DBeaver Community on Ubuntu 22.04
Finally, now you have learned how to install MariaDB 10.6 on Ubuntu Server 22.04.