How to install MariaDB on CentOS 7 linux step by step guide
In this
article we learn what is MariaDB and how
to install MariaDB on CentOS 7 linux step by step.
What is MariaDB
MariaDB is
one of the popular database server all over the world. MariaDB is free and open
source database server which is drop-in replacement for MySQL. Mariadb is used because MariaDB is fast, reliable and robust database
server.
Installation of MariaDB on CentOS 7
In this demonstration
we install MariaDB on CentOS 7 using the default yum repositories. To install
MariaDB on CentOS 7 we need to execute the below command.
Start and enable MariaDB service on CentOS 7
To start
and enable the MariaDB service on CentOS 7 we need to execute the below
command.
#systemctl start
mariadb
#systemctl enable
mariadb
Setup firewall rule for MariaDB service on CentOS 7
CentOS
7 uses firewalld as a software firewall instead
of iptables. By default MariaDB server is running on 3306 port. We need to
allow this port into firewall rule to access it. To allow the incoming connection
to the standard MySQL tcp port we need to execute the below command.
#firewall-cmd - -permanent - -add-service=mysql
#firewall-cmd -- reload
To secure MariaDB we use “mysql_secure_installation” .After
executing the “mysql_secure_installation”
command we need to set root password,remove test database, remove anonymous
user login and disable the remote login.
#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):
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!
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!
After that restart the service using
the below command.
#systemctl restart
mariadb
We can login the database using root user executing the below command
and execute a simple query on database.
#mysql
–u root –p
After that type
the root password and enter the SQL promt.
[root@localhost
~]# mysql -uroot -p
Enter
password:
Welcome
to the MariaDB monitor. Commands end
with ; or \g.
Your
MariaDB connection id is 12
Server
version: 5.5.60-MariaDB MariaDB Server
Copyright
(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)]> show databases;
+--------------------+
|
Database |
+--------------------+
|
information_schema |
|
mysql |
|
performance_schema |
+--------------------+
3 rows
in set (0.00 sec)
To change MariaDB port
Suppose we
are going to change MariaDB port from 3306 to 7706,to change the default port
we need to open /etc/my.cnf file and add the below line.
[mysqld]
Port = 7706
After that restart the service using
the below command.
#systemctl restart
mariadb
After that allow the firewall access
for new port. To allow the access in firewall we execute the below commands.
#firewall-cmd -- permanent
-- add-port=7706/tcp
#firewall-cmd -- reload
Recommended Read:
https://techrideradmin.blogspot.com/2018/10/iptables-firewall-rule-chains-configuration-guide-on-linux-with-examples-for-beginners.html
That’s all if this article is helpful please
share it!!!!!!!!
This one really worked , thanks for the guide!
ReplyDelete