2 Ways to Install MariaDB on CentOS 7

install Mariadb CentOS 7

MariaDB is a popular open-source SQL database management system that is a fork and drop-in replacement for MySQL.  Since the acquisition of MySQL by Oracle, MariaDB has become the database system of choice by the open-source community. MariaDB provides improved performance with faster replication speeds,  tighter security measures, and additional storage engines to mention a few benefits.

In this guide, you will learn how to install MariaDB on CentOS 7.

There are two ways of installing the MariaDB server. You can install the default version that is available on CentOS 7 repositories or install the latest version by manually adding the MariaDB repository.

1) Install MariaDB on CentOS 7 using Yum

The default version of MariaDB in CentOS repositories is MariaDB 5.5. Though not the latest version, it is quite stable and comes highly recommended.

To install MariaDB 5.5 on CentOS 7, log in to your server instance and use the yum package manager as shown.

$ sudo yum install mariadb-server

When prompted, press 'y' for Yes to proceed with the installation process.

To start the MariaDB database server, issue the command:

$ sudo systemctl start mariadb

Additionally, you can enable MariaDB to start upon booting using the command:

$ sudo systemctl enable mariadb

To confirm if MariaDB is running, run:

$ sudo systemctl status  mariadb
MariaDB on CentOS 7 check mariadb status
check mariadb status

The output above confirms that MariaDB is up and running. To confirm the version of MariaDB installed simply run the command

 
nbsp; mysql -V
Check MariadB version
Check MariaDB version

You can also use the rpm command shown:

$ rpm -qi | grep mariadb
rpm command to check version of mariadb
rpm command to check MariaDB version

You can also check the version of MariaDB when logging in to the database.

$ sudo mysql -u root -p
log into MariaDB server
log into MariaDB server

2) Install  MariaDB from Repo

At the time of writing this guide, the latest version of MariaDB is MariaDB 10.4. To install it, first create a repository file as shown:

$ sudo vim /etc/yum.repos.d/mariadb.repo

Next, paste the following content:


[mariadb]

name = MariaDB baseurl = http://yum.mariadb.org/10.4/centos7-amd64 gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB gpgcheck=1

Save and exit the file.

Next, update the yum cache index as shown.

$ sudo yum makecache fast

To install MariaDB 10.4, run the command:

$ sudo yum install mariadb-server mariadb-client

When prompted, press 'y' for Yes to proceed with the installation process.

To start the MariaDB database server, run  the command:

$ sudo systemctl start mariadb

Also, you can enable MariaDB to start on boot by invoking:

$ sudo systemctl enable mariadb

To confirm if MariaDB is running, run:

$ sudo systemctl status  mariadb

Again, you can use various ways to confirm the version of MariaDB as explained earlier.

$ rpm -qi MariaDB-server
MariaDB on CentOS 7
confirm latest MariaDB server is installed

Access MariaDB database from command-line

To access the MariaDB database as a root user, invoke the command:

$ sudo mysql -u root -p

You will be prompted for a sudo password, then later followed by the root password.

log into MariaDB server

Additionally, you can create another user and assign privileges as shown

MariaDB [(none)] >  create user 'linoxide'@'localhost' IDENTIFIED BY  'Password';
MariaDB [(none)] > GRANT ALL PRIVILEGES ON *.* TO 'linoxide'@'localhost';

Next, log  out using the command:

MariaDB [(none)] > quit;

Then log in using the user

$ sudo mysql -u linoxide  -p

Remove MariaDB from CentOS 7

If you wish to remove your instance of MariaDB from CentOs 7, first stop MariaDB service.

$ sudo systemctl stop mariadb.service

Next, completely remove MariaDB from CentOS 7 using the command:

$ sudo yum remove -y mariadb-server mariadb-client

Finally, remove all the data files as shown.

$ sudo rm -rf /var/lib/mysql  /etc/my.cnf

Related Read:

Conclusion

In this guide, we walked you through the steps of installing MariaDB on CentOS 7. We covered installing the default and stable version of MariaDB as well as installing the latest version.

2 Comments... add one

Leave a Comment