How to Install MariaDB 10.4 on CentOS 7
CentOS 7 actually comes with MariaDB, but the default version on upstream repositories are still using version 5.5. This article will guide you how to install the latest version of MariaDB (10.4 at the time of this writing).
If you already have some databases on your existing MySQL/MariaDB installation, please back them up first. Here's my post explaining how to backup MySQL databases, but if you're in a hurry, the command to backup all databases is:
$ mysqldump --opt -u [uname] -p[pass] --all-databases > [backupfile.sql]
This process could take some time depends on the size of your existing databases.
Remove Existing MariaDB Installation
To remove existing MariaDB installation, type this command:
$ sudo yum remove mariadb-server
After pressing "Enter" and prompted for password, you should see something like this:
Loaded plugins: fastestmirror, langpacks
--> Running transaction check
---> Package mariadb-server.x86_64 1:5.5.60-1.el7_5 will be erased
--> Finished Dependency Resolution
Package Arch Version Repository Size
mariadb-server x86_64 1:5.5.60-1.el7_5 @base 58 M
Remove 1 Package
Installed size: 58 M
Is this ok [y/N]: y
Just press "y" and "Enter". Your old MariaDB server installation will be removed from system. Now we're ready to continue with installation.
MariaDB 10.4 Installation
Adding the MariaDB YUM repository
First step is to configure yum to install from MariaDB Corporation's MariaDB Package Repository by using the MariaDB Package Repository setup script.
MariaDB Corporation provides a MariaDB Package Repository for several Linux distributions that use yum to manage packages. This repository contains software packages related to MariaDB Server, including the server itself, clients and utilities, client libraries, plugins, and Mariabackup. The MariaDB Package Repository setup script automatically configures your system to install packages from the MariaDB Package Repository.
To use the script, execute the following command:
$ curl -sS https://downloads.mariadb.com/MariaDB/mariadb_repo_setup | sudo bash
It will responds with something like this:
[info] Repository file successfully written to /etc/yum.repos.d/mariadb.repo.
[info] Adding trusted package signing keys...
[info] Succeessfully added trusted package signing keys.
The script will also install the GPG public keys used to verify the signature of MariaDB software packages. If you want to avoid that, then you can use the
If you want to download the script, rather than executing it, then you can do so in the following way:
$ curl -O https://downloads.mariadb.com/MariaDB/mariadb_repo_setup
MariaDB Server and Client Installation
After we've added MariaDB repository, let's continue with installation itself. At your shell, type:
$ sudo yum install MariaDB-server MariaDB-client
System will respond similar like this:
... some lines snipped
Package Arch Version Repository Size
MariaDB-client x86_64 10.4.6-1.el7.centos mariadb-main 12 M
replacing mariadb.x86_64 1:5.5.60-1.el7_5
MariaDB-compat x86_64 10.4.6-1.el7.centos mariadb-main 2.8 M
replacing mariadb-libs.x86_64 1:5.5.60-1.el7_5
MariaDB-server x86_64 10.4.6-1.el7.centos mariadb-main 25 M
Installing for dependencies:
MariaDB-common x86_64 10.4.6-1.el7.centos mariadb-main 81 k
boost-program-options x86_64 1.53.0-27.el7 base 156 k
galera-4 x86_64 26.4.2-1.rhel7.el7.centos mariadb-main 9.4 M
Install 3 Packages (+3 Dependent packages)
Total download size: 49 M
Is this ok [y/d/N]: y
Just press "y" and "Enter". System will continue with MariaDB server and client installation.
Let's verify that we've correctly installed MariaDB 10.4. At your shell, type:
$ mysql --version
You should see something like this:
mysql Ver 15.1 Distrib 10.4.6-MariaDB, for Linux (x86_64) using readline 5.1
Usually the first thing you would've done after MariaDB installation is setting up a password for unprotected superuser account. This is not the case now. But if you want to do it anyway, to set root password just type this command:
$ sudo mysql
Your terminal will change to MariaDB monitor. It's like a terminal where you can enter your SQL commands there. To set root password, enter this command:
MariaDB [(none)]> ALTER USER root@localhost IDENTIFIED VIA mysql_native_password USING PASSWORD("verysecret");
Change "verysecret" with your preferred password.
If you've forgotten your root password, no problem — you can still connect using sudo and change the password.
To add another user, supply these commands to your MariaDB monitor:
MariaDB [(none)]> CREATE USER 'adjie'@'localhost' IDENTIFIED BY 'verysecret';
MariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* TO 'adjie'@'localhost' WITH GRANT OPTION;
MariaDB [(none)]> FLUSH PRIVILEGES;
As usual, change "verysecret" with your preferred password.
Although in most cases you should still see your existing database after upgrade to MariaDB 10.4, it's still possible that your databases wiped out. No worries, if you followed this guide exactly as it is, you should already have database backup. To restore your database using this command:
$ mysql -u [uname] -p[pass] < [backupfile.sql]
I hope that you now know how to install MariaDB 10.4 on CentOS 7. If you run into any issues or have any feedback feel free to drop a comment below.