In this article we will look at how you can install MariaDB 10.5 on CentOS 8 | CentOS 7 Linux machine. MariaDB is a community fork of MySQL relational database management system with huge community support. The stable version of MariaDB 10.5 was released on June 2020 and it will be supported until June 2025. You can see all the new features in MariaDB 10.5 from the changes page. The software can be used free of charge under the conditions of the GNU General Public License Version 2.
If you’re doing an upgrade from another version like 10.4 check the official upgrade guide and take note of the differences between the two versions of MariaDB. This is important for production use cases where custom variables have been used to tune the database and ensure efficiency in transactions.
Install MariaDB 10.5 on CentOS 8 | CentOS 7
The MariaDB team provides maintained repositories with the latest packages for different flavors of Linux. For CentOS we’ll use YUM repository.
Step 1: Add MariaDB YUM repository
Run the following commands to add the repository provided by MariaDB to your CentOS server.
curl -LsS -O https://downloads.mariadb.com/MariaDB/mariadb_repo_setup sudo bash mariadb_repo_setup --mariadb-server-version=10.5
Confirm the repository is working by updating cache.
sudo yum makecache
List available repositories:
$ sudo yum repolist repo id repo name appstream CentOS Linux 8 - AppStream baseos CentOS Linux 8 - BaseOS droplet-agent DigitalOcean Droplet Agent extras CentOS Linux 8 - Extras mariadb-main MariaDB Server mariadb-maxscale MariaDB MaxScale mariadb-tools MariaDB Tools
Step 2: Install MariaDB 10.5 on CentOS 8 | CentOS 7
Once the repository has been added and confirmed to be working we can proceed with the installation of MariaDB 10.5 on CentOS 8 / CentOS 7 Linux machine.
sudo dnf module reset mariadb -y sudo yum install MariaDB-server MariaDB-client MariaDB-backup
sudo yum install MariaDB-server MariaDB-client MariaDB-backup
You can check list of packages to be installed and agree if okay with it.
..... Installing weak dependencies: perl-IO-Socket-IP noarch 0.39-5.el8 AppStream 47 k perl-IO-Socket-SSL noarch 2.066-4.el8 AppStream 297 k perl-Mozilla-CA noarch 20160104-7.el8 AppStream 15 k Enabling module streams: perl 5.26 perl-DBI 1.641 Transaction Summary ================================================================================================================================================================ Install 54 Packages Total download size: 67 M Installed size: 298 M Is this ok [y/N]: y
Also agree to import GPG key when prompted.
..... Importing GPG key 0x1BB943DB: Userid : "MariaDB Package Signing Key
" Fingerprint: 1993 69E5 404B D5FC 7D2F E43B CBCB 082A 1BB9 43DB From : https://yum.mariadb.org/RPM-GPG-KEY-MariaDB Is this ok [y/N]: y
RPM package details:
$ rpm -qi MariaDB-server Name : MariaDB-server Version : 10.5.12 Release : 1.el7.centos Architecture: x86_64 Install Date: Tue Oct 19 11:52:49 2021 Group : Applications/Databases Size : 136027872 License : GPLv2 Signature : DSA/SHA1, Wed Aug 4 18:14:56 2021, Key ID cbcb082a1bb943db Source RPM : MariaDB-server-10.5.12-1.el7.centos.src.rpm Build Date : Tue Aug 3 12:10:25 2021 Build Host : centos74-amd64 Relocations : (not relocatable) Vendor : MariaDB Foundation URL : http://mariadb.org ...
Step 3: Start MariaDB Service on CentOS 8 | CentOS 7
Both CentOS 8 and CentOS 7 uses Systemd init system. We can start the service with systemctl command as shown below.
sudo systemctl start mariadb
To enable the service to be started when the server is rebooted use the following command:
$ sudo systemctl enable mariadb Created symlink /etc/systemd/system/multi-user.target.wants/mariadb.service → /usr/lib/systemd/system/mariadb.service.
Check service status with systemctl status command:
$ systemctl status mariadb ● mariadb.service - MariaDB 10.5.4 database server Loaded: loaded (/usr/lib/systemd/system/mariadb.service; enabled; vendor preset: disabled) Drop-In: /etc/systemd/system/mariadb.service.d └─migrated-from-my.cnf-settings.conf Active: active (running) since Sun 2020-06-28 19:34:56 CEST; 1min 35s ago Docs: man:mariadbd(8) https://mariadb.com/kb/en/library/systemd/ Main PID: 4328 (mariadbd) Status: "Taking your SQL requests now..." Tasks: 9 (limit: 24392) Memory: 67.7M CGroup: /system.slice/mariadb.service └─4328 /usr/sbin/mariadbd Jun 28 19:34:56 centos.computingforgeeks.com mariadbd: 2020-06-28 19:34:56 0 [Note] InnoDB: 10.5.4 started; log sequence number 45041; transaction id 21 Jun 28 19:34:56 centos.computingforgeeks.com mariadbd: 2020-06-28 19:34:56 0 [Note] Plugin 'FEEDBACK' is disabled. Jun 28 19:34:56 centos.computingforgeeks.com mariadbd: 2020-06-28 19:34:56 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool Jun 28 19:34:56 centos.computingforgeeks.com mariadbd: 2020-06-28 19:34:56 0 [Note] InnoDB: Buffer pool(s) load completed at 200628 19:34:56 Jun 28 19:34:56 centos.computingforgeeks.com mariadbd: 2020-06-28 19:34:56 0 [Note] Server socket created on IP: '::'. Jun 28 19:34:56 centos.computingforgeeks.com mariadbd: 2020-06-28 19:34:56 0 [Note] Reading of all Master_info entries succeeded Jun 28 19:34:56 centos.computingforgeeks.com mariadbd: 2020-06-28 19:34:56 0 [Note] Added new Master_info '' to hash table Jun 28 19:34:56 centos.computingforgeeks.com mariadbd: 2020-06-28 19:34:56 0 [Note] /usr/sbin/mariadbd: ready for connections. Jun 28 19:34:56 centos.computingforgeeks.com mariadbd: Version: '10.5.4-MariaDB' socket: '/var/lib/mysql/mysql.sock' port: 3306 MariaDB Server Jun 28 19:34:56 centos.computingforgeeks.com systemd: Started MariaDB 10.5.4 database server. ...
If you need other systems in the network to access the database server allow port 3306:
sudo firewall-cmd --add-service=mysql --permanent sudo firewall-cmd --reload
For remote connection to work the service should be listening on an IP address and not localhost loopback interface.
# Listen on specific IP address in the server bind-address=172.21.200.12 # Listen on all available interfaces bind-address=0.0.0.0
Step 4: Secure MariaDB Database on CentOS 8 | CentOS 7
There is a script provided for hardening MariaDB database server. The script helps you to:
- Set root password
- Remove anonymous database users
- Disallow remote database login as root user
- Remove test databases
To start the database hardening process run the command 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!
Test login as root user without password:
$ mysql -u root
You should get an access denied error:
ERROR 1698 (28000): Access denied for user 'root'@'localhost'
Now try as root user and provide the pasword:
$ mysql -u root -p Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 24 Server version: 10.5.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)]> SELECT VERSION(); +----------------+ | VERSION() | +----------------+ | 10.5.4-MariaDB | +----------------+ 1 row in set (0.001 sec) MariaDB [(none)]> QUIT Bye
Your database server is now ready for use. The only additional setting that you may require is tuning it to optimal performance depending on your application requirements and use case.