1.安装repo
yum localinstall https://dev.mysql.com/get/mysql57-community-release-el7-9.noarch.rpm
2.安装 MySQL 5.7 Server
sudo yum install mysql-community-server --nogpgcheck
这一步可能会出现 ”异常1“ 中所示的现象,按照提供的方式解决后,再从新执行步骤2。
3.启动 MySQL Service
service mysqld start
4.获取临时密码
grep 'A temporary password' /var/log/mysqld.log |tail -1
输出
2022-06-09T16:09:21.898987Z 1 [Note] A temporary password is generated for root@localhost: qjdC0<O<GRC5
5.登录 mysql
mysql -h localhost -uroot -pqjdC0<O<GRC5;
登录后需要修改密码,不然没法进行下一步操作。
mysql> ALTER USER 'root'@'localhost' IDENTIFIED BY 'new-password';
6.查看数据库
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| information_schema |
| mysql |
| performance_schema |
| sys |
+--------------------+
4 rows in set (0.00 sec)
到此,安装成功。
7.查看 mysql 版本
mysql -V
# 结果
mysql Ver 14.14 Distrib 5.7.38, for Linux (x86_64) using EditLine wrapper
异常1:GPG key 不正确
异常现象:
The GPG keys listed for the "MySQL 5.7 Community Server" repository are already installed but they are not correct for this package.
Check that the correct key URLs are configured for this repository.
Failing package is: mysql-community-libs-compat-5.7.37-1.el7.x86_64
GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
解决办法:
rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
参考连接: https://tecadmin.net/install-mysql-5-7-centos-rhel/