This guide is to help you with Installing MySQL Server on CentOS 7 / CentOS 6. I’ll show you how to install MySQL 5.5/5.6/5.7 and the latest stable release of MySQL, which as of this writing is MySQL 8.0

To start installing MySQL server on CentOS 7/6, you need to add the official MySQL community repository to your system. Run below commands to add it,

sudo yum localinstall

Install MySQL 8 on CentOS

Now that repo is added, you can install MysQL 8 without editing repository content since repo for 8 is enabled by default.

sudo yum --enablerepo=mysql80-community install mysql-community-server

Install MySQL 5.7 on CentOS

To install MySQL 5.7, you need to disable mysql80-community repository then download it.

sudo yum --disablerepo=mysql80-community --enablerepo=mysql57-community install mysql-community-server

Install MySQL 5.6 on CentOS

To install MySQL 5.6, you need to disable mysql80-community repository then download it.

sudo yum --disablerepo=mysql80-community --enablerepo=mysql56-community install mysql-community-server

Start MySQL Service

For CentOS 7, use systemd to start mysql service:

sudo systemctl enable  --now mysqld.service

For CentOS 6, use service command line tool.

sudo /etc/init.d/mysql start 
sudo chkconfig --levels 235 mysqld on

Set MySQL root password

Installation of MySQL on CentOS 6 generates a temporary password for you. You can get it by running:

grep 'A temporary password is generated for [email protected]' /var/log/mysqld.log |tail -1

It will look like below:

# [email protected]: ?h(UwcrvQ7jr

Change mysql root user password

# mysqladmin -u root password [your_password_here]
# mysql_secure_installation

Configure Firewall

With iptables:

sudo iptables -A INPUT -m state --state NEW -m tcp -p tcp --dport 3306 -j ACCEPT
sudo service iptables restartt


sudo firewall-cmd --add-service mysql --permanent
sudo firewall-cmd --reload

Test your settings:

$ mysql -u root -p
Enter password: 
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 7
Server version: 5.7.22 MySQL Community Server (GPL)

Copyright (c) 2000, 2018, Oracle and/or its affiliates. All rights reserved.

Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

mysql> show databases;

Your support is our everlasting motivation,
that cup of coffee is what keeps us going!

As we continue to grow, we would wish to reach and impact more people who visit and take advantage of the guides we have on our blog. This is a big task for us and we are so far extremely grateful for the kind people who have shown amazing support for our work over the time we have been online.

Thank You for your support as we work to give you the best of guides and articles. Click below to buy us a coffee.


Please enter your comment!
Please enter your name here