Setup MySQL Server on CentOS or RHEL

One of the most common databases is MySQL and the best medium for this database type is Linux. To setup this database, you should follow the following steps in order to install it easily and securely.

These steps contains:

1. Installing MySQL server daemon
2. Installing MySQL module for PHP
3. Starting MySQL daemon
4. Follow security wizard
5. Set MySQL daemon to run at boot

These 5 steps are the most basic things you should do before using your server for business.

1. Installing MySQL server daemon

This is the very first step and you can do it by this command:

yum -y install mysql mysql-server

 

2. Installing MySQL module for PHP

This module is strongly needed if you want to connect to your database via PHP programming language. use this command for installation:

yum -y install php-mysql

 

3. Starting MySQL daemon

Usually daemons in Linux have a “d” letter at the end and they run as service:

service mysqld start

 

4. Follow Security Wizard

MySQL itself has a wizard shell written in bash and can simply help you to quickly improve your database security without strangling with complex commands:

sh /usr/bin/mysql_secure_installation

 

NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE! PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we’ll need the current
password for the root user. If you’ve just installed MySQL, 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):
ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: YES)
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 MySQL
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 MySQL installation has an anonymous user, allowing anyone
to log into MySQL 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, MySQL 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 MySQL
installation should now be secure.

Thanks for using MySQL!

5. Set MySQL daemon to run at boot

Some times when you install a daemon, it may not run after rebooting the server. So it would be better if you set the boot time run lever every time you install a daemon:

chkconfig --level 345 mysqld on

 

Now your MySQL server is fully configured and installed and it is running. now you can use your MySQL.

One thought on “Setup MySQL Server on CentOS or RHEL”

Leave a Reply

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

This is new type of CAPTCHA, make the puzzle please !WordPress CAPTCHA