Step 1 - Add the new MySQL repository to the CentOS 7 server with this yum command.
yum localinstall https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
Step 2 - Install MySQL 5.7
yum -y install mysql-community-server
Step 3 - Start MySQL and Enable Start at Boot Time
systemctl start mysqld
systemctl enable mysqld
Step 4 - Configure the MySQL Root Password
On CentOS 7, MySQL will generate a strong default password when MySQL is started the first time, the default password is shown in the mysqld.log file. You can use the grep command below for showing the default MySQL password.
grep 'temporary' /var/log/mysqld.log
You will see default MySQL root password, and we should set a new default password now.
Connect to the MySQL shell with the default password.
mysql -u root -p
TYPE DEFAULT PASSWORD
Now replace the default password with a new and strong password, in my case, I will set the password 'Newhakase-labs123@' with the MySQL query below.
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Newhakase-labs123@';
THEN
flush privileges; (Don't forget)
The default password has been changed.
ALTER USER 'root'@'localhost' IDENTIFIED BY 'Root-yuan1234@';