Install MySQL 5.7 on CentOS7

July 5, 2022

TL;DR: download rpm, import GPG key and yum install.

MySQL 5.7 improves security and performance over previous versions, also introduces the JSON data type, allowing to store non relational data.

Download repository definition

Download the package by typing the following command (if wget is not installed you can install it by running sudo yum -y install wget):

1
wget https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm

Install repository definition

1
sudo rpm -ivh mysql57-community-release-el7-9.noarch.rpm

Update

Before installing MySQL, it is recommended to upgrade the OS. Then reboot the system.

1
2
sudo yum update 
sudo reboot

Install MySQL

1
sudo yum install mysql-community-server

Check MySQL status

Check if the MySQL service is runnin using systemd (systemd is a replacement for SysV system initialization is also a suite of service management and configurations for the GNU / Linux operating system) as shown in the message MySQL service is stopped, note Active: inactive (dead) line.

1
2
3
4
5
6
$ sudo systemctl status mysqld
● mysqld.service - MySQL Server
   Loaded: loaded (/usr/lib/systemd/system/mysqld.service; enabled; vendor preset: disabled)
   Active: inactive (dead)
     Docs: man:mysqld(8)
           http://dev.mysql.com/doc/refman/en/using-systemd.html

Start MySQL service

After starting the MySQL server it will be ready to handle DB connections.

1
sudo systemctl start mysqld

When the service is started the MySQL server MySQL generates a temporary password. We can check the password using following command

1
grep -i password /var/log/mysqld.log 

This characteristic is introduced since MySQL 5.7 out of security.

Check MySQL status

Again we check the status of the MySQL service, note Active: active (running) line. Now it should be running.

Automatic Start

With the following command, the MySQL service is started together with the OS.

1
sudo systemctl enable mysqld

You can check if MySQL service starts with the OS running:

1
sudo systemctl is-enabled mysqld

To disable,

1
sudo systemctl disable mysqld

Basic MySQL security step

After running the above steps we must ensure a basic security, to do this, run the script mysql_secure_installation. When asked the “password for root”, you should use the temporary password generated by the MySQL Server. When asked to input new password, you should think of a password satisfied with requirements. Default requirements is MEDIUM.

  • LOW Length >= 8 characters.
  • MEDIUM Length >= 8, numeric, mixed case, and special characters.
  • STRONG Length >= 8, numeric, mixed case, special characters and dictionary file.

    We can check the requirement level with command SHOW VARIABLES LIKE 'validate_password%';

Run mysql

1
mysql -u root -p