How to Install and Configure Mysql Database in Centos 7 , Redhat 7 , Fedora

Share on :

How to Install and Configure MySQL Database in Centos 7 , Redhat 7 , Fedora

MySQL is one of the most used relational database. It is Open source and can be integrated with many programming languages like php , java , python and many more..
It works on 3306 port with tcp protocol
Now Lets Install MySQL in Linux.

1) Install Packages.

We are going to install two Packages to setup mysql one is mariadb which is a client package to access mysql server and mariadb-server is the mysql server package it is used to setup mysql server.
lets check these packages info.

yum info mariadb
Name : mariadb
Arch : x86_64
Epoch : 1
Version : 5.5.60
Release : 1.el7_5
Size : 49 M
Repo : installed
From repo : base
Summary : A community developed branch of MySQL
URL : http://mariadb.org
License : GPLv2 with exceptions and LGPLv2 and BSD
Description : MariaDB is a community developed branch of MySQL.
MariaDB is a multi-user, multi-threaded SQL database server.
It is a client/server implementation consisting of a server daemon
(mysqld) and many different client programs and libraries. The
base package contains the standard MariaDB/MySQL client programs
and generic MySQL files.

yum info mariadb-server
Name : mariadb-server
Arch : x86_64
Epoch : 1
Version : 5.5.60
Release : 1.el7_5
Size : 58 M
Repo : installed
From repo : base
Summary : The MariaDB server and related files
URL : http://mariadb.org
License : GPLv2 with exceptions and LGPLv2 and BSD
Description : MariaDB is a multi-user, multi-threaded SQL database server. It is
a client/server implementation consisting of a server daemon
(mysqld) and many different client programs and libraries. This
package contains the MariaDB server and some accompanying files
and directories. MariaDB is a community developed branch of MySQL.

——< for Centos 7 / Rhel 7 >——
yum install mariadb mariadb-server -y
——-< Fedora >——
dnf install mariadb mariadb-server -y

2) Start and Enable the service.

systemctl start mariadb
systemctl enable mariadb

3) Apply the firewall rule.

firewall-cmd –permanent –add-service=mysql
firewall-cmd –reload

4) Configure Mysql.

Parameters used in setting up mariadb. According to your scenario you can setup using these parameters.

Set root password? [Y/n] – Y (To Setup Root Password to the database)
Remove anonymous users? [Y/n] – Y (To Remove Anonymous Users from database)
Disallow root login remotely? [Y/n] – Y (To Disallow Remote Root login to Database)
Remove test database and access to it? [Y/n] – Y (To Remove Test Database)
Reload privilege tables now? [Y/n] – Y (To Reload Priviege)

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.

Enter current password for root (enter for none):Hit Enter
OK, successfully used password, moving on…

Setting the root password ensures that nobody can log into the MariaDB
root user without the proper authorisation.

Set root password? [Y/n] Y
New password:
Re-enter new password:
Password updated successfully!
Reloading privilege tables..
… Success!

By default, a MariaDB installation has an anonymous user, allowing anyone
to log into MariaDB without having to have a user account created for
them. This is intended only for testing, and to make the installation
go a bit smoother. You should remove them before moving into a
production environment.

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.


Disallow root login remotely? [Y/n] Y
… Success!


By default, MariaDB comes with a database named ‘test’ that anyone can
access. This is also intended only for testing, and should be removed
before moving into a production environment.


Remove test database and access to it? [Y/n] Y
– Dropping test database…
… Success!
– Removing privileges on test database…
… Success!

https://www.techrepublic.com/article/how-to-speed-up-apache-with-varnish-http-cache/
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.


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!

Now Lets Connect to our Database.

mysql -u root -p
Enter password: Enter the Root Password
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 2
Server version: 5.5.60-MariaDB MariaDB ServerCopyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

MariaDB [(none)]>


Share on :

You may also like...

Leave a Reply

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