Installing Mariadb (MySQL) On Centos 7

After installing apache now its time to install database management system.
Mariadb which is an equivalent of MySQL is the default relational database management package that comes with centos 7.

Run the following command to install database management system
sudo yum -y install mariadb-server

Start the service
sudo systemctl start mariadb

Enable it to start automatically at boot
sudo systemctl enable mariadb.service

RDBMS is up and running now lets secure it by removing some of the defaults.
sudo mysql_secure_installation

mariadb centos

Do not type anything just press enter and then you will be asked to set root password for mariadb.

After setting the root password you will be asked a bunch of questions.
Input y (yes) to remove anonymous users.
Disallow root login remotely ? – enter y (yes)
Remove test database and access to it ? – enter y
Reload privilege table now ? – input y for this as well.

You have successfully removed the insecure defaults and secured the database management system.

Now its time to create a new database and a user, you need to remember the database name, username and password because it is going to be used later on when you install wordpress. So either keep it in your mind or save the details in a secure place to be used later.

First login into the database management system using the command below
mysql -u root -p

You will be asked to enter the password it is the same password which you set previously during the mysql_secure_installation

Now enter the following to create a database
CREATE DATABASE database_Name;
Replace database_Name with the name you want to give to your database.

create database mariadb

So I created a database with the name MarxDBxyz and now its time to assign a user to the database.

With the help of the command below a new user will be created, a password will be given to that and also the user will be granted all the privileges which would allow it to function normally.

grant all privileges on MarxDBxyz.* to Marx1234z@localhost identified by ‘password123’;
In the above command replace MarxDBxyz with your database name, Marx1234z with the username you prefer and enter a strong password in place of password123

All done, now type quit and hit enter to exit the database management system.

Some useful commands that might come in handy

If you want to view all the databases in MariaDb
show DATABASES;

In case you want to view all users that currently exist
SELECT User, Host, Password FROM mysql.user;

To delete database
DROP DATABASE enter_database_name;

To delete user
DROP USER enter_user_name;

Next you can Install PHP

Previous Post
Apache HTTP Server Installation On Centos 7
Next Post
Installing PHP 7.x on Centos 7

Related Posts

1 Comment. Leave new

  • Whenever I issue this command;

    sudo mysql_secure_installation

    I get this error;

    Enter current password for root (enter for none):
    ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: NO)

    Please advise.

    Reply

Leave a Reply

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

Fill out this field
Fill out this field
Please enter a valid email address.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

alert('dsf'); console.log("dsdsdsd");