≡ Menu

6 Steps to Install and Configure MariaDB MySQL on CentOS / RedHat

MariaDB Install and ConfigStarting from CentOS 7, you will not see a package called mysql-server in the yum repository.

Now the package is called as mariadb-server.

The original MySQL is now owned by Oracle corporation.

But MariaDB is a fork of the original MySQL database. Just like the original MySQL, MariaDB is also open source, developed by open source community, maintained and supported by MariaDB corporation.

From our point of view, only the package name is changed. MariaDB is still MySQL, and all the mysql command line utilities are still exactly named the same including the command called mysql.

This tutorial explains step-by-step on how to install and configure MariaDB on CentOS or RedHat based Linux distros.

1. MariaDB MySQL Packages

The following are the three main MariaDB packages:

  • mariadb-5.5.52-1.el7.x86_64 -This contains several MySQL client programs and utilities.
  • mariadb-server-5.5.52-1.el7.x86_64 – This is the main MariaDB MySQL database server.
  • mariadb-libs-5.5.52-1.el7.x86_64 – This contains the shared libraries that are required for client program interface.

The current version of MariaDB-server that is available on CentOS 7 yum repository is 5.5.52 as shown below.

# yum info mariadb-server
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: repos-va.psychz.net
 * extras: linux.cc.lehigh.edu
 * updates: mirror.us.leaseweb.net
Available Packages
Name        : mariadb-server
Arch        : x86_64
Epoch       : 1
Version     : 5.5.52
Release     : 1.el7
Size        : 11 M
Repo        : base/7/x86_64

2. Install MariaDB MySQL Server

Install the MariaDB MySQL server package as shown below using yum install.

# yum install mariadb-server

In this case, on this server, it has installed mariadb-server along with the following dependent packages.

  • mariadb-server.x86_64 1:5.5.52-1.el7
  • mariadb-libs.x86_64 1:5.5.52-1.el7
  • mariadb.x86_64 1:5.5.52-1.el7
  • libaio.x86_64 0:0.3.109-13.el7
  • perl-DBD-MySQL.x86_64 0:4.023-5.el7
  • perl-DBI.x86_64 0:1.627-4.el7
  • perl-Compress-Raw-Bzip2.x86_64 0:2.061-3.el7
  • perl-Compress-Raw-Zlib.x86_64 1:2.061-4.el7
  • perl-Data-Dumper.x86_64 0:2.145-3.el7
  • perl-IO-Compress.noarch 0:2.061-2.el7
  • perl-Net-Daemon.noarch 0:0.48-5.el7
  • perl-PlRPC.noarch 0:0.2020-14.el7

Verify to make sure this has installed the three important MariaDB mysql packages.

# rpm -qa | grep -i maria

If you are new to MySQL/MariaDB, this will give you a good jumpstart: How to Create MySQL Table, Insert and Select Records

3. Startup MariaDB Database

As you see below, mariadb database server module is loaded, but not started yet.

# systemctl status mariadb
? mariadb.service - MariaDB database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled; vendor preset: disabled)
   Active: inactive (dead)

Start the MariaDB mysql server using systemctl as shown below.

# systemctl start mariadb

Verify the systemctl status to make sure the mariadb database server is started successfully.

# systemctl status mariadb
? mariadb.service - MariaDB database server
   Loaded: loaded (/usr/lib/systemd/system/mariadb.service; disabled; vendor preset: disabled)
   Active: active (running) since Thu 2017-06-26 18:26:35 UTC; 13s ago
  Process: 4049 ExecStartPost=/usr/libexec/mariadb-wait-ready $MAINPID (code=exited, status=0/SUCCESS)
  Process: 3969 ExecStartPre=/usr/libexec/mariadb-prepare-db-dir %n (code=exited, status=0/SUCCESS)
 Main PID: 4048 (mysqld_safe)
   CGroup: /system.slice/mariadb.service
           +-4048 /bin/sh /usr/bin/mysqld_safe --basedir=/usr
           +-4206 /usr/libexec/mysqld --basedir=/usr --datadir=/var/lib/mysql --plugin-dir=/usr/lib64/mysql/plugin --log-error=/var/log/mariadb/ma...

Jun 26 18:26:32 deploy mariadb-prepare-db-dir[3969]: The latest information about MariaDB is available at http://mariadb.org/.
Jun 26 18:26:32 deploy mariadb-prepare-db-dir[3969]: You can find additional information about the MySQL part at:
Jun 26 18:26:32 deploy mariadb-prepare-db-dir[3969]: http://dev.mysql.com
Jun 26 18:26:32 deploy mariadb-prepare-db-dir[3969]: Support MariaDB development by buying support/new features from MariaDB
Jun 26 18:26:32 deploy mariadb-prepare-db-dir[3969]: Corporation Ab. You can contact us about this at sales@mariadb.com.
Jun 26 18:26:32 deploy mariadb-prepare-db-dir[3969]: Alternatively consider joining our community based development effort:
Jun 26 18:26:32 deploy mariadb-prepare-db-dir[3969]: http://mariadb.com/kb/en/contributing-to-the-mariadb-project/
Jun 26 18:26:32 deploy mysqld_safe[4048]: 170601 18:26:32 mysqld_safe Logging to '/var/log/mariadb/mariadb.log'.
Jun 26 18:26:32 deploy mysqld_safe[4048]: 170601 18:26:32 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
Jun 26 18:26:35 deploy systemd[1]: Started MariaDB database server.

If you are a programmer, and use PHP, you’ll find this helpful: 3 Methods to Connect to MySQL from PHP using Example Code

4. Connect and Verify MariaDB Server

Use the mysql command as shown below to connect to the database using mysql’s root user.

# mysql -u root
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.52-MariaDB MariaDB Server

Copyright (c) 2000, 2016, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]>

The following show database command will display the default mysql databases.

MariaDB [(none)]> show databases;
| Database           |
| information_schema |
| mysql              |
| performance_schema |
| test               |

5. Perform MariaDB Post Installation Steps

As you see from above, by default, the installation doesn’t assign any password to MySQL root account.

To set the mysql root user password and perform other security configuration on the database, execute the mysql_secure_installation script as shown below.

# /usr/bin/mysql_secure_installation


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.

Since this is the first time we are running this script, there is no password assigned for the mysql root account. So, press enter here.

Enter current password for root (enter for none): 
OK, successfully used password, moving on...

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

At this stage, say “y” to assign a password for the MySQL root account. Enter the password after that.

Please note that this mysql root account is different than the linux root account. So, here we are setting the password for the mysql root account, which has nothing to do with Linux root account.

Set root password? [Y/n] y
New password: 
Re-enter new password: 
Password updated successfully!
Reloading privilege tables..
 ... Success!

As part of the default installation, mysql installs anonymous user who can login to the database without a real user. So, we should really remove this user.

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.

As you can imagine, mysql root account will have access to all mysql database. So, it is important to keep this secure. Also, we should make sure remote clients from other servers are not allowed to connect using this mysql root account.

Instead, only the localhost (where the mysql server is installed) can connect using root account. So, we should really disallow root login remotely.

Disallow root login remotely? [Y/n] y
 ... Success!

This is the default test database, which we should be removed.

Remove test database and access to it? [Y/n] y
 - Dropping test database...
 ... Success!
 - Removing privileges on test database...
 ... Success!

Type y here to make sure all the changes we did so far will take into 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!

6. Validate MySQL root access

Now, if you connect to Mysql without a root password you’ll get the following access denied error message.

# mysql -u root
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: NO)

To specify the password, use the -p option as shown below. This will prompt the user to enter the password.

# mysql -u root -p
Enter password: 

Also, as you see below from the show databases command, the test database is now removed.

MariaDB [(none)]> show databases;
| Database           |
| information_schema |
| mysql              |
| performance_schema |

If you want to pass the password in the mysql command line, specify it right next to -p option as shown below.

# mysql -u root -pMySecurePassword

Note: There is no space between -p and the password. This might cause some confusion, as we have space between -u and username. But, there is no space between -p and password.

If you enjoyed this article, you might also like..

  1. 50 Linux Sysadmin Tutorials
  2. 50 Most Frequently Used Linux Commands (With Examples)
  3. Top 25 Best Linux Performance Monitoring and Debugging Tools
  4. Mommy, I found it! – 15 Practical Linux Find Command Examples
  5. Linux 101 Hacks 2nd Edition eBook Linux 101 Hacks Book

Bash 101 Hacks Book Sed and Awk 101 Hacks Book Nagios Core 3 Book Vim 101 Hacks Book

{ 1 comment… add one }

  • Robert June 27, 2017, 4:16 pm

    Hi, !!
    How are you?

    One question..
    How can I configure database location , because when I install the database, I can’t configure where the database will be installed..

    Please help me out..!!

    Thanks a lot.!!!

Leave a Comment