阿里云服务器Centos搭建mysql环境踩过的坑以及解决办法:
这里以MySQL5.7为例:
1 .下载并安装MySQL的 Yum Repository
[root@hzt ~]# wget -i -c http://dev.mysql.com/get/mysql57-community-release-el7-10.noarch.rpm
安装:
[root@hzt ~]# yum -y install mysql57-community-release-el7-10.noarch.rpm
2.安装MySQL服务器
[root@hzt ~]# yum -y install mysql-community-server
这里会发现第一个问题:
Public key for mysql-community-server-5.7.37-1.el7.x86_64.rpm is not installed
Failing package is: mysql-community-server-5.7.37-1.el7.x86_64
GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
完整内容如下:
Total 7.5 MB/s | 203 MB 00:26
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Importing GPG key 0x5072E1F5:
Userid : "MySQL Release Engineering <mysql-build@oss.oracle.com>"
Fingerprint: a4a9 4068 76fc bd3c 4567 70c8 8c71 8d3b 5072 e1f5
Package : mysql57-community-release-el7-10.noarch (@/mysql57-community-release-el7-10.noarch)
From : /etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Public key for mysql-community-server-5.7.37-1.el7.x86_64.rpm is not installed
Failing package is: mysql-community-server-5.7.37-1.el7.x86_64
GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
原因:由于CentOS 7已经不支持MySQL了,取而代之在CentOS7内部集成了mariadb,而安装MySQL的话会和MariaDB的文件冲突。
3.查看centos自带的是 mariadb,将其卸载:
[root@hzt ~]# rpm -qa|grep mariadb
mariadb-libs-5.5.68-1.el7.x86_64
4.卸载mariadb
[root@hzt ~]# yum remove -y mariadb-libs-5.5.68-1.el7.x86_64
5.再次执行安装指令
[root@hzt ~]# yum -y install mysql-community-server
注意这里可能会出现第二个问题:
Install 1 Package (+4 Dependent packages)
Total size: 202 M
Installed size: 878 M
Downloading packages:
warning: /var/cache/yum/x86_64/7/mysql57-community/packages/mysql-community-server-5.7.37-1.el7.x86_64.rpm: Header V4 RSA/SHA256 Signature, key ID 3a79bd29: NOKEY
Retrieving key from file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
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-server-5.7.37-1.el7.x86_64
GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
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-server-5.7.37-1.el7.x86_64
GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
翻译为:“MySQL 5.7 Community Server”存储库列出的GPG密钥已经安装,但不适用于此软件包。检查是否为此存储库配置了正确的密钥URL。
失败的包是:mysql-community-server-5.7.37-1.el7.x86_64
GPG密钥配置为:file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
6.在运行安装程序之前导入密钥:
[root@hzt ~]# rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
7.执行安装指令
[root@hzt ~]# yum -y install mysql-community-server
8.最终终于安装成功
........
Installed:
mysql-community-server.x86_64 0:5.7.37-1.el7
Dependency Installed:
libaio.x86_64 0:0.3.109-13.el7 mysql-community-client.x86_64 0:5.7.37-1.el7
mysql-community-common.x86_64 0:5.7.37-1.el7 mysql-community-libs.x86_64 0:5.7.37-1.el7
Complete!