• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

The Geek Diary

CONCEPTS | BASICS | HOWTO

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • Linux Services
    • VCS
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
    • Data Guard
  • DevOps
    • Docker
    • Shell Scripting
  • Interview Questions
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

How to install and configure MariaDB in CentOS / RHEL 7

By admin

MariaDB is the default implementation of MySQL in Red Hat Enterprise Linux 7. MariaDB is a community-developed fork of the MySQL database project, and provides a replacement for MySQL.

Installing MariaDB

1. As the MariaDB Database Management System (DBMS) is not installed by default on RHEL/CentOS 7, we will start this recipe by installing the required packages.

# yum install -y mariadb mariadb-server

Here,
mariadb-server – is the MariaDB server package
mariadb – is the client shell interface for controlling and querying the server.

2. Enable the service to ensure the service starts at boot and start the mariadb service:

# systemctl enable mariadb
# systemctl start mariadb

Securing Default Installation

1. At this point we have a working installation, but in order to ensure that our installation is safe we then need to invoke the secure installation script in order to guide us through a few simple steps to harden our basic installation.

# mysql_secure_installation

2. By default MariaDB “root” does not have a password, you have to change the root password after you install it the first time. You might get an error as shown below if you try to use root password.

MariaDB error access denied for root user

3. When it prompt to enter current password for root user, simply press “Enter” button. It will take us to next step where we can set the new password for root user.

set root password mariaDB

4. Now you will be asked a number of simple questions which will help you in the process of hardening your MariaDB DBMS system. It is a good advice to choose Yes (Y) to every question for maximum security unless you are already a MariaDB expert and really require a certain feature.

mariadb secure the installation

Testing the Connection to MariaDB database

Finally, test if you can connect and login to the MariaDB service locally using the MariaDB command-line client called mysql.

# mysql -u root -p

Testing mariadb connection

Firewall Configuration

If you want to access the database from a different server, then add the MySql service to the firewall configuration and reload it:

# firewall-cmd --permanent --add-service=mysql
success
# firewall-cmd --reload
success

Managing a MariaDB Database

Once you are done Installing and securing the MariaDB, its time to create a new database and database user. Known as the MariaDB shell, this simple interactive and text based-command line facility supports the full range of SQL commands and affords both local and remote access to your database server.

1. To begin with, lets login to the database using the MariaDB adminitrator user “root” and the password we defined while sucuring the MariaDB installation.

# mysql -u root -p

2. Next is to create a new database using the below syntax. Replace the database_name using the name of your choice for the new database.

MariaDB [(none)]> CREATE DATABASE [database_name] CHARACTER SET utf8 COLLATE utf8_general_ci;

For Example:

MariaDB [(none)]> CREATE DATABASE geekdb CHARACTER SET utf8 COLLATE utf8_general_ci;
Query OK, 1 row affected (0.00 sec)
Note: Make sure you end each command with a semicolon(;) in the MariaDB shell.

3. Having created the database, we will need to create the database user. Replace the “database_name”, “username” and “password” in the below command.

MariaDB [(none)]> GRANT ALL ON [database_name].* TO '[username]'@'localhost' IDENTIFIED BY '[password]' WITH GRANT OPTION;

For Example:

MariaDB [(none)]> GRANT ALL ON geekdb.* TO 'geekuser'@'localhost' IDENTIFIED BY 'getmein' WITH GRANT OPTION;
Query OK, 0 rows affected (0.00 sec)

4. Next, make the MariaDB DBMS aware of your new user:

MariaDB [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

5. Now, logout and login using the new user you just created.

# mysql -u geekuser -p getmein

6. Run the “SHOW DATABASES” command to verify the database name we created.

MariaDB [(none)]> SHOW DATABASES;

show databases MariaDB

Filed Under: CentOS/RHEL 7, Linux, MariaDB

Some more articles you might also be interested in …

  1. CentOS / RHEL 7 : How to modify the kernel command line
  2. CentOS / RHEL : How to add, delete and display LVM tags
  3. What is the purpose of “mysql.sys@localhost” user
  4. CentOS / RHEL 7 : Unable To Start The Samba Service
  5. The System Continuously Displayed the Error Message from the “avahi-demon” in /var/log/messages
  6. Oracle Software Group Accounts OSDBA, OSOPER, Oracle Inventory group
  7. How to Mount Guest Qcow2 Virtual disk Image containing LVM on KVM Host Machine
  8. How to Configure Interface(s) in promiscuous mode on CentOS/RHEL 7 (persistently)
  9. Understanding iscsiadm Utility in CentOS / RHEL
  10. CentOS / RHEL : How to add a null route in Linux

You May Also Like

Primary Sidebar

Recent Posts

  • How to Disable IPv6 on Ubuntu 18.04 Bionic Beaver Linux
  • How to Capture More Logs in /var/log/dmesg for CentOS/RHEL
  • Unable to Start RDMA Services on CentOS/RHEL 7
  • How to rename a KVM VM with virsh
  • Archives
  • Contact Us
  • Copyright

© 2021 · The Geek Diary