How to Install MySQL on CentOS 7

r00t December 2, 2017

Install MySQL on CentOS 7

In this tutorial we’ll learn how to install MySQL on CentOS 7. We will also install and configure its prerequisites. MySQL is one of the most frequently used database management systems one of website/server applications. It allows users to store their databases and handle them using SQL commands on various platforms.

I recommend to use a minimal CentOS server setup as a basis for the tutorial, that can be a virtual or a root server image with an CentOS 7 minimal install from a web hosting company or you use our minimal server tutorial to install a server from scratch.

Install MySQL on CentOS 7

Step 1. First, ensure your system is fully up-to-date by running the following:

yum -y update

Step 2. Install MySQL.

MySQL is no longer distributed through base operating system image or available in OS repositories. So, you would need to add an official repository of MySQL to install MySQL community server:

rpm -ivh

You can verify that the MySQL Yum repository has been added successfully by using following command:

yum repolist all | grep mysql | grep enabled


mysql-connectors-community/x86_64  MySQL Connectors Community enabled: 42
mysql-tools-community/x86_64 MySQL Tools Community enabled: 53
mysql57-community/x86_64 MySQL 5.7 Community Server enabled: 227

Install latest version of MySQL (currently 5.7) using the following command:

yum -y install mysql-community-server

Next, Start the MySQL service and make it auto-start on system boot:

systemctl start mysqld
systemctl enable mysqld

Step 3. Secure MySQL.

Once the MySQL or MariaDB server has started, the service will then need to be secured. The mysql_secure_installation script will assist with this process by presenting several questions. It is recommended to accept the default action for all questions which is yes.


You will be given the choice to change the MySQL root password, remove anonymous user accounts, disable root logins outside of localhost, and remove test databases:

  • Set root password? [Y/n] Y
  • Remove anonymous users? [Y/n] Y
  • Disallow root login remotely? [Y/n] Y
  • Remove test database and access to it? [Y/n] Y
  • Reload privilege tables now? [Y/n] Y

Once the database server is secured, check it’s installed version and login to the MySQL command shell as follows:

mysql -V

To access the MariaDB instance, run the following command on the terminal.

mysql -u root -p

Congratulation’s! You have successfully install and configured MySQL on your CentOS 7 server. Thanks for using this tutorial for installing MySQL data base on CentOS 7 system.

The Tags:

Leave a Comment

Comments are closed.