Installing MySQL on CentOS Server

Installing MySQL on CentOS

MySQL is an open-source database management system, commonly installed as part of the popular LAMP (Linux, Apache, MySQL, PHP/Python/Perl) stack. It uses a relational database and SQL (Structured Query Language) to manage its data. Let's see Installing MySQL on CentOS server.

Installing MySQL 5.6

To install MySQL 5.6 this way, update the package index on your server with below command

yum update

Now download the Yum Repo package of MySQL Server 5.6


Below rpm command helps you install the rpm package which was already downloaded in the above step.

rpm -ivh mysql-community-release-el6-5.noarch.rpm

After this installation completes, we can see two new yum repo's  related to MySQL.

 [root@localhost ~]# ls -1 /etc/yum.repos.d/mysql-community* /etc/yum.repos.d/mysql-community.repo /etc/yum.repos.d/mysql-community-source.repo

Using the below yum command, now we can install MySQL Server 5.6 . All dependencies will be installed itself.

yum install mysql-server
Installing MySQL 5.7

To install MYSQL 5.7, need to download  yum repo package of MySQL Server 5.7. Using the URL you can download using "wget" command.

wget 7.noarch.rpm
yum localinstall mysql57-community-release-el7-7.noarch.rpm

Now install MYSQL with the below command.

yum install mysql-server
Configuring MySQL

This version of Oracle MySQL sets a root password by default. We need to retrieve it from the mysql logs.

cat /var/log/mysqld.log

For MYSQL 5.7 default password is generated while downloading and installing MYSQL 5.7 repo.

When it comes to MYSQL 5.6 we need to follow the below process using "mysql_secure_installation".

A temporary password is generated for root@localhost: *password*


You’ll be prompt to enter your current password. Enter the root MySQL password set during installation.

Enter current password for root (enter for none):

Then, assuming you set a strong root password, go ahead and enter nat the following prompt:

Change the root password? [Y/n] n
Remove anonymous users, Y:
Remove anonymous users? [Y/n] Y
Disallow root logins remotely, Y:
Disallow root login remotely? [Y/n] Y
Remove test database and access to it, Y:
Remove test database and access to it? [Y/n] Y
And reload privilege tables, Y:
Reload privilege tables now? [Y/n] Y

In another method, you can log into MySQL server database and reset the password in secure way.

mysql -u root

You will see mysql prompt like this mysql> . Use the below given commands to reset root’s password.

mysql> use mysql;
mysql> update user set password=PASSWORD("GIVE-NEW-ROOT-PASSWORD") where User='root';
mysql> flush privileges;
mysql> quit

Below are some MYSQL commands

To stop MySQL
service mysql stop
To start MySQL
service mysql start
To check the status of MySQL
service mysql status
To restart MySQL
Service mysqld restart
Sources to install MySQL

The below URL allows you to find MySQL repo to install it on your CentOs server.

Hope this article helps you. You can comment below if you have any queries.

  • by Shiva
  • |
  • December 28, 2016
Click Here to Leave a Comment Below

Leave a Comment:

Get a Free Hosting Trial and Test Our Services. It Costs Nothing! Get it Here!