Install MariaDB Server 10 on CentOS 7 and RHEL 7 by using yum

In this post we will how to install MariaDB Server 10.4.7 version on CentOS 7 and RHEL 7 (Red Hat Enterprise Linux 7 ) by using yum command.

We are doing fresh installation of MariaDB Server on minimal installed CentOS 7 version. The method is applicable to RHEL 7 as well.

While installing MariaDB 10 on CentOS 7 ,we faced some problems. We are sharing the same in this post.

Note: We recommend you to follow this method only in server where MariaDB Server or MySQL Server are not installed yet.

Follow the given below steps to install MariaDB-Server 10

Create MariaDB yum repo file

Create new file /etc/yum.repos.d/MariaDB.repo

vi /etc/yum.repos.d/MariaDB.repo

And paste below given contents in same file. (Below section updated on Aug-08-2019)

[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.4.7/rhel7-amd64/
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

Save the file

Check latest stable MariaDB server is available

Now run the command below given command to check which is latest stable MariaDB server available in the yum repo.

yum list|grep  MariaDB-server

In our server, at the time of writing MariaDB Server 10.0.14 stable release is availble. Hence by default we will install the same version.

[root@nix ~]# yum list|grep  MariaDB-server
MariaDB-server.x86_64                       10.4.7-1.el7.centos        @mariadb 
MariaDB-server-debuginfo.x86_64             10.4.7-1.el7.centos        mariadb
[root@nix ~]# 

Importing MariaDB Signing Key

Manually importing the signing key by using below given command.

rpm --import https://yum.mariadb.org/RPM-GPG-KEY-MariaDB

Install MariaDB server and client

Now in this section, we will also take you through the problem which will be occurred during installation.

To install MariaDB server and client, use the below given yum command.

yum install MariaDB-server MariaDB-client MariaDB-devel MariaDB-shared

Note: The given below error we have not found in version 10.4.7 .

Most probably you may get “Transaction check error” . If you are not seeing the below given error it means, the MariaDB server is installed and following the next step is not required.

Transaction check error:
file /etc/my.cnf from install of MariaDB-common-10.0.14-1.el6.x86_64 conflicts with file from package mariadb-libs-1:5.5.35-3.el7.x86_64
file /usr/share/mysql/charsets/Index.xml from install of MariaDB-common-10.0.14-1.el6.x86_64 conflicts with file from package mariadb-libs-1:5.5.35-3.el7.x86_64

Because of mariadb-libs-1:5.5.35-3.el7.x86_64 package, we are getting conflicts while installing MariaDB server.

Note: mariadb-libs-1:5.5.35-3.el7.x86_64 is also a dependency for postfix 10 .

Now, we will remove postfix and mariadb-libs-1:5.5.35-3.el7.x86_64 from system.Later we will re-install postfix only.

yum remove postfix
rpm -ev mariadb-libs-5.5.35-3.el7.x86_64 

Now we again re-run the yum command for installing MariaDB server

yum install MariaDB-server MariaDB-client MariaDB-devel MariaDB-shared

You can also check by running rpm query to find MariaDB related installed rpm.

[root@localhost ~]# rpm -qa|grep -i maria
MariaDB-common-10.0.14-1.el6.x86_64
MariaDB-server-10.0.14-1.el6.x86_64
MariaDB-devel-10.0.14-1.el6.x86_64
MariaDB-compat-10.0.14-1.el6.x86_64
MariaDB-client-10.0.14-1.el6.x86_64
MariaDB-shared-10.0.14-1.el6.x86_64
[root@localhost ~]#

As we know in above some step , we have removed postfix. Now we will install postfix once again. It is your decision that do you want the postfix in this server or not. If yes, then run the below given command.

yum install postfix

I hope all are done, without any problem.

Time to reset MariaDB root’s password

For security reason we will recommend you to reset MariaDB’s root password. ByDefault the root’s password is blank hence anyone can login.

First start the Maridb service. It is almost similar to start/stop/status/restart the MySQL Service. (Because it is fork of MySQL)

systemctl start mysql.service

Now MariaDB server is running. And listening at port no. 3306 . In CentOS 7 and RHEL 7, ss command is availble, which is also an alternate of netstat command. (In minimal installed RHEL 7/CentOS 7 system, bydefault netstat command is not shipped)

[root@localhost ~]# ss -ltnp|grep mysql
LISTEN     0      128                      :::3306                    :::*      users:(("mysqld",3405,16))
[root@localhost ~]#

Reset MariaDB server’s root password

There are multiple ways to reset the root password. Use anyone of them. We recommend to use mysql_secure_installation command on new MariaDB server.

1. Using command mysql_secure_installation : Just run the command on terminal and follow the instruction

mysql_secure_installation

You will get following questions on screen after using mysql_secure_installation command.

Enter current password for root (enter for none): [Press Enter, because it is blank]
Set root password? [Y/n] y
New password: [Give your password]
Re-enter new password: [Rewrite your given password]
Remove anonymous users? [Y/n] y
Disallow root login remotely? [Y/n] y
Remove test database and access to it? [Y/n] y
Reload privilege tables now? [Y/n] y

Now login into MariaDB Server by using newly set password.

mysql -u root -p

The given below is reference from our system.

[root@localhost ~]# mysql -u root -p
Enter password: 
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 9
Server version: 10.4.7-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)]> 

2. Using command mysqladmin

Use the given below command.Replace new-password with your desired password.

Note: Here is the drawback, we will write password on terminal and when any user login into server and run history command, he will able to see root’s password.

/usr/bin/mysqladmin -u root password 'new-password'

3. Reset by login into MariaDB console

MariaDB root’s password is blank hence it will allow us to login into MariaDB server without asking password.

mysql -u root

Now follow below given sql commands.

mysql> use mysql;
mysql> update user set password=PASSWORD("GIVE-NEW-ROOT-PASSWORD") where User='root';
mysql> flush privileges;
mysql> quit

Start,Stop,Status,Restart MariaDB Service

To start MariaDB Server

systemctl start mysql.service

To re-start MariaDB Server

systemctl restart mysql.service

To stop MariaDB Server

systemctl stop mysql.service

To check status of MariaDB service

systemctl status mysql.service

Enable or Disable MariaDB Service at booting

Enable MariaDB Service to run at booting of system.

systemctl enable mysql.service

Disable MariaDB Service to run at booting of system.

systemctl disable mysql.service

15 thoughts on “Install MariaDB Server 10 on CentOS 7 and RHEL 7 by using yum”

  1. nice, but when i install some packages, it requires mariadb-libs-5.5 ;((
    =
    Transaction check error:
    file /etc/my.cnf from install of mariadb-libs-1:5.5.44-1.el7_1.x86_64 conflicts with file from package MariaDB-common-10.0.21-1.el6.x86_64
    =
    for example.

    • Hi,

      I faced same issue and shared the solution in same post also [Error is written in bold letters]. Let me know , even after following the same steps you are still getting problem.

      Regards
      Sharad

  2. hi bro
    there is some problems on my server.i cannot enable MariaDB Service at booting.
    when i type “systemctl enable mysql.service”, error message like this:

    mysql.service is not a native service, redirecting to /sbin/chkconfig.
    Executing /sbin/chkconfig mysql on
    The unit files have no [Install] section. They are not meant to be enabled
    using systemctl.
    Possible reasons for having this kind of units are:
    1) A unit may be statically enabled by being symlinked from another unit’s
    .wants/ or .requires/ directory.
    2) A unit’s purpose may be to act as a helper for some other unit which has
    a requirement dependency on it.
    3) A unit may be started when needed via activation (socket, path, timer,
    D-Bus, udev, scripted systemctl call, …).

    centos 7.1.1503 mariadb 10.0.17

Comments are closed.