Get your server issues fixed by our experts for a price starting at just 25 USD/Hour. Click here to register and open a ticket with us now!

Author Topic: Install and Configure MariaDB MySQL on CentOS / RedHat  (Read 1831 times)

0 Members and 1 Guest are viewing this topic.

akhilt

  • Guest
Install and Configure MariaDB MySQL on CentOS / RedHat
« on: August 05, 2018, 12:05:33 pm »
Install and Configure MariaDB MySQL on CentOS / RedHat

Starting 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.

Code: [Select]
# 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.
Code: [Select]
# 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.
Code: [Select]
# rpm -qa | grep -i maria
mariadb-5.5.52-1.el7.x86_64
mariadb-server-5.5.52-1.el7.x86_64
mariadb-libs-5.5.52-1.el7.x86_64

3. Startup MariaDB Database

As you see below, mariadb database server module is loaded, but not started yet.
Code: [Select]
? 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.
Code: [Select]
# systemctl start mariadb
Verify the systemctl status to make sure the mariadb database server is started successfully.
Code: [Select]
# 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.

4. Connect and Verify MariaDB Server

Use the mysql command as shown below to connect to the database using mysql’s root user.
Code: [Select]
# 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.
Code: [Select]
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.
Code: [Select]
# /usr/bin/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.

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.

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.

Code: [Select]
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.

Code: [Select]
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.

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

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

Code: [Select]
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.
Code: [Select]
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.

Code: [Select]
# 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.

Code: [Select]
# mysql -u root -p
Enter password:

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

Code: [Select]
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.
Code: [Select]
# mysql -u root -pMySecurePassword
Hope you will like this artuicle,Thank you!