• 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. How to Install Gnome Desktop Environment onto Oracle Linux 6.x
  2. CentOS / RHEL : How to block incoming and outgoing ports using iptables
  3. How to Restart Network Services in CentOS/RHEL 8
  4. CentOS / RHEL : How to change password hashing algorithm
  5. How to Count lines in a file in UNIX/Linux
  6. Beginners Guide to Managing Package Module Streams in CentOS/RHEL 8
  7. 5 Useful Examples of firewall-cmd command
  8. How to change a system’s machine-ID in Oracle Enterprise Linux 7
  9. Beginners Guide to User and Group Administration in Linux
  10. How to copy directories recursively using rsync while excluding specific files

You May Also Like

Primary Sidebar

Recent Posts

  • How to disable ACPI in CentOS/RHEL 7
  • How to Use real-time query to access data on a physical standby database
  • CentOS/RHEL 8: “ACPI MEMORY OR I/O RESET_REG” Server Hung after reboot
  • How to Create a Physical Standby Database by Using SQL and RMAN Commands
  • Archives
  • Contact Us
  • Copyright

© 2021 · The Geek Diary