Install MariaDB in Linux (CentOS)

MariaDB is a community developed fork of a MySQL RDBMS.

Add MariaDB repository

# Create mariadb.repo file in /etc/yum.repos.d/ folder
[mariadb]
name = MariaDB
baseurl = http://yum.mariadb.org/10.4/centos7-amd64
gpgkey=https://yum.mariadb.org/RPM-GPG-KEY-MariaDB
gpgcheck=1

This repo file will download the latest version that is available in the mariadb repository. In case if you want any specific subversion you can replace 10.4 with 10.4.* E.g. The latest currently available stable version is 10.4.13. But in case if you want download 10.4.11, then instead of 10.4, we can specify 10.4.11 so that yum command will download that specific version.

Make sure the added repo is working correctly by using yum repolist command.

yum repolist command

Install MariaDB

Install packages using yum install command as below.

sudo yum -y install MariaDB-server MariaDB-client

Start and Enable the MariaDB server to start the service automatically once system rebooted.

sudo systemctl start mariadb
sudo systemctl enable --now mariadb

Make sure MariaDB is started and running fine using systemctl status command before proceeding to configure the Database.

Configure MariaDB server

We can configure the Mariadb server using mysql_secure_installation

sudo mysql_secure_installation

Login and Check the default databases list

Default collation settings for MariaDB are:

Configure the MariaDB Server with custom configurations

  • Enable Table names are stored in lowercase on disk and name comparisons are not case-sensitive.
    • lower_case_table_names = 1
  • Configuring Application Character Set and Collation
    • collation-server = ‘utf8_general_ci’
    • init-connect=’SET NAMES utf8′
    • character-set-server = utf8

Default Configuration file location – /etc/my.cnf.d/server.cnf

Add the above parameters to server.cnf file

Restart the MariaDB server

systemctl restart mariadb

Verify the updated collation settings

Create or Update User

By default root user is connected from localhost only (i.e.. from that machine itself). To enable root user connect from the all hosts we use the below queries.

CREATE USER 'root' IDENTIFIED BY '<Password>';
GRANT ALL privileges ON . TO 'root'@'{ac45f3a693ed5e334b014fd0ae9db178220484e629051bcc2c09944bacacdb21}';
flush privileges;

#To enable root as super user use the below query
GRANT SUPER ON . TO 'root'@'{ac45f3a693ed5e334b014fd0ae9db178220484e629051bcc2c09944bacacdb21}' IDENTIFIED BY '<Password2020>';
Update root user privileges to connect from all hosts

To create a new user

CREATE USER 'username' IDENTIFIED BY '<password>';
GRANT ALL privileges ON . TO 'username'@'{ac45f3a693ed5e334b014fd0ae9db178220484e629051bcc2c09944bacacdb21}';
flush privileges;

Create Data Base

Use the below query to create a database

create database test;
Create Data Base
0 Shares:
Leave a Reply

Your email address will not be published. Required fields are marked *

You May Also Like