How to Completely Remove and Install MariaDB 10.1.39v on CentOS 7.6

Removing and Installing MariaDB on CentOS 7.6

Prerequisite:

1)Check the installed rpm packages of MariaDB.

2)Go the yum repositories location.

3)Disable the MariaDB repo if you have configured a repository, else skip this step.

4)Remove the Packages as follows:

Configuration file

Data Directory

Mysql user

5)Check whether could you login to the MariaDB database securely.

6)Check the Service Of MAriaDB.

Deletion Of MAriaDB packages

And now, list all the installed MariaDB packages.

[root@linuxhelp ~]# rpm -qa | grep "MariaDB"
MariaDB-server-10.1.39-1.el7.centos.x86_64
MariaDB-common-10.1.39-1.el7.centos.x86_64
MariaDB-client-10.1.39-1.el7.centos.x86_64
MariaDB-shared-10.1.39-1.el7.centos.x86_64

And then, go to the location of yum repositories list.

[root@linuxhelp ~]# cd /etc/yum.repos.d/

List the contents inside the repository list.

[root@linuxhelp yum.repos.d]# ll
total 92
-rw-r--r--. 1 root root 1664 Nov 23 18:46 CentOS-Base.repo
-rw-r--r--. 1 root root 1309 Nov 23 18:46 CentOS-CR.repo
-rw-r--r--. 1 root root  649 Nov 23 18:46 CentOS-Debuginfo.repo
-rw-r--r--. 1 root root  314 Nov 23 18:46 CentOS-fasttrack.repo
-rw-r--r--. 1 root root  630 Nov 23 18:46 CentOS-Media.repo
-rw-r--r--. 1 root root 1331 Nov 23 18:46 CentOS-Sources.repo
-rw-r--r--. 1 root root 5701 Nov 23 18:46 CentOS-Vault.repo
-rw-r--r--  1 root root  951 Oct  2  2017 epel.repo
-rw-r--r--  1 root root 1050 Oct  2  2017 epel-testing.repo
-rw-r--r--  1 root root  139 May  8 17:33 MariaDB.repo
-rw-r--r--  1 root root  446 Mar  8 13:04 remi-glpi91.repo
-rw-r--r--  1 root root  446 Mar  8 13:04 remi-glpi92.repo
-rw-r--r--  1 root root  446 Mar  8 13:04 remi-glpi93.repo
-rw-r--r--  1 root root  446 Mar  8 13:04 remi-glpi94.repo
-rw-r--r--  1 root root  855 Mar  8 13:04 remi-modular.repo
-rw-r--r--  1 root root  456 Mar  8 13:04 remi-php54.repo
-rw-r--r--  1 root root 1314 Mar  8 13:04 remi-php70.repo
-rw-r--r--  1 root root 1314 Mar  8 13:04 remi-php71.repo
-rw-r--r--  1 root root 1314 Apr 15 11:07 remi-php72.repo
-rw-r--r--  1 root root 1314 Mar  8 13:04 remi-php73.repo
-rw-r--r--  1 root root 2605 Mar  8 13:04 remi.repo
-rw-r--r--  1 root root  750 Mar  8 13:04 remi-safe.repo

Disable the MariaDB repo by running the following command.

[root@linuxhelp yum.repos.d]# yum-config-manager --disable MariaDB
Loaded plugins: fastestmirror, langpacks
============================== repo: Mariadb ===============================
[Mariadb]
async = True
bandwidth = 0
base_persistdir = /var/lib/yum/repos/x86_64/7
baseurl = http://yum.mariadb.org/10.1/centos7-amd64
cache = 0
cachedir = /var/cache/yum/x86_64/7/Mariadb
check_config_file_age = True
compare_providers_priority = 80
cost = 1000
deltarpm_metadata_percentage = 100
deltarpm_percentage = 
.
.
.
.
throttle = 0
timeout = 30.0
ui_id = Mariadb
ui_repoid_vars = releasever,
   basearch
username = 

You can now remove the MariaDB rpm packages.

[root@linuxhelp yum.repos.d]# yum remove "MariaDB*" -y
Loaded plugins: fastestmirror, langpacks
Resolving Dependencies
--> Running transaction check
---> Package MariaDB-client.x86_64 0:10.1.39-1.el7.centos will be erased
---> Package MariaDB-common.x86_64 0:10.1.39-1.el7.centos will be erased
---> Package MariaDB-server.x86_64 0:10.1.39-1.el7.centos will be erased
---> Package MariaDB-shared.x86_64 0:10.1.39-1.el7.centos will be erased
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: perl-DBD-MySQL-4.023-6.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18()(64bit) for package: 2:postfix-2.10.1-7.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: perl-DBD-MySQL-4.023-6.el7.x86_64
--> Processing Dependency: libmysqlclient.so.18(libmysqlclient_18)(64bit) for package: 2:postfix-2.10.1-7.el7.x86_64
--> Running transaction check
.
.
.
.
..
Removed:
  MariaDB-client.x86_64 0:10.1.39-1.el7.centos                              
  MariaDB-common.x86_64 0:10.1.39-1.el7.centos                              
  MariaDB-server.x86_64 0:10.1.39-1.el7.centos    
Complete!

Remove the configuration file of MariaDB.

[root@linuxhelp yum.repos.d]# rm -rf /etc/my.cnf

Remove the data directory of MariaDB.

[root@linuxhelp yum.repos.d]# rm -rf /var/lib/mysql

Delete the mysql user in /etc/passwd.

[root@linuxhelp yum.repos.d]# grep mysql /etc/passwd
mysql:x:27:27:MariaDB Server:/var/lib/mysql:/sbin/nologin
[root@linuxhelp yum.repos.d]# userdel -r mysql
userdel: mysql mail spool (/var/spool/mail/mysql) not found
userdel: mysql home directory (/var/lib/mysql) not found
[root@linuxhelp yum.repos.d]# grep mysql /etc/passwd

And then, login to the MariaDB database to verify the removal of secure installation.

[root@linuxhelp yum.repos.d]# mysql -u root -p
bash: /usr/bin/mysql: No such file or directory

Check the status of MariaDB.

[root@linuxhelp yum.repos.d]# systemctl status mariadb
'Unit mariadb.service could not be found.

Installation of MariaDB

Enable the MariaDB repo to install the server.

[root@linuxhelp yum.repos.d]# yum-config-manager --enable MariaDB
Loaded plugins: fastestmirror, langpacks
============================== repo: Mariadb ===============================
[Mariadb]
async = True
bandwidth = 0
base_persistdir = /var/lib/yum/repos/x86_64/7
baseurl = http://yum.mariadb.org/10.1/centos7-amd64
cache = 0
cachedir = /var/cache/yum/x86_64/7/Mariadb
check_config_file_age = True
compare_providers_priority = 80
cost = 1000
.
.
..
sslclientcert = 
sslclientkey = 
sslverify = True
throttle = 0
timeout = 30.0
ui_id = Mariadb
ui_repoid_vars = releasever,
   basearch
username = 

You shall now install MariaDB by executing the following command.

[root@linuxhelp yum.repos.d]# yum install MariaDB-server MariaDB-client -y
Loaded plugins: fastestmirror, langpacks
Loading mirror speeds from cached hostfile
 * base: mirror.dhakacom.com
 * epel: www.ftp.ne.jp
 * extras: mirror.dhakacom.com
 * remi-php72: remi.schlundtech.de
 * remi-safe: remi.schlundtech.de
 * updates: mirror.nbrc.ac.in
Resolving Dependencies
.
.
.
Dependency Installed:
  MariaDB-common.x86_64 0:10.1.39-1.el7.centos            boost-program-options.x86_64 0:1.53.0-27.el7            galera.x86_64 0:25.3.26-1.rhel7.el7.centos            jemalloc.x86_64 0:3.6.0-1.el7           

Replaced:
  mariadb.x86_64 1:5.5.60-1.el7_5                                   mariadb-libs.x86_64 1:5.5.60-1.el7_5                                   mariadb-server.x86_64 1:5.5.60-1.el7_5                                  

Enable the service of MariaDB.

[root@linuxhelp ~]# systemctl enable mariadb
Created symlink from /etc/systemd/system/mysql.service to /usr/lib/systemd/system/mariadb.service.
Created symlink from /etc/systemd/system/mysqld.service to /usr/lib/systemd/system/mariadb.service.
Created symlink from /etc/systemd/system/multi-user.target.wants/mariadb.service to /usr/lib/systemd/system/mariadb.service.

Start the service of MariaDB.

[root@linuxhelp ~]# systemctl start mariadb

Check the status of MariaDB.

[root@linuxhelp ~]# systemctl status mariadb
● mariadb.service - MariaDB 10.1.39 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 Wed 2019-05-08 17:36:28 IST; 11s ago

Secure the MariaDB through the below installation method

[root@linuxhelp ~]# mysql_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
you haven't set the root password yet, the password will be blank,
so you should just press enter here.

Enter current password for root (enter for none): 
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!

Therefore, we have successfully removed the MariaDB package on CentOS completely and installed it successfully on CentOS 7.6

Tag : MariaDB CentOS
FAQ
Q
Are the commands in Mariadb similar in MYSQL?
A
Yes.the mariadb commands are similar in mysql
Q
Why was MariaDB created ?
A
It was primarily developed due to concerns that arose when MySQL was acquired by ORACLE Inc.MAriaDB is a general purpose DBMS engineered with extensible architecture to support a broad set of use cases via pluggable storage engines.
Q
What is the command to delete the mariadb user on centos 7.6?
A
userdel -r mysql is the command to delete the mariadb user on centos 7.6
Q
What is the user that mariadb has by default on centOS 7.6?
A
mysql is the MAriadb user has by default on centos 7.6
Q
What is the MariaDB On CentOS 7.6?
A
Mariadb is a database that stores the information in the form of tables.