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 https://dev.mysql.com/get/mysql80-community-release-el7-1.noarch.rpm
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] or # 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
Firewalld:
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 owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show databases;