阿里云服务器安装Mysql

添加MySQL Yum仓库:
首先,访问MySQL官方下载页面获取最新的Yum仓库链接。

CentOS 7示例:

sudo rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm

CentOS 8示例:

sudo rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el8-2.noarch.rpm


安装MySQL服务器:

sudo yum install mysql-community-server

安装后你可能会遇到
Import of key(s) didn't help, wrong key(s)?
Public key for mysql-community-client-8.0.36-1.el8.x86_64.rpm is not installed. Failing package is: mysql-community-client-8.0.36-1.el8.x86_64
 GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Public key for mysql-community-client-plugins-8.0.36-1.el8.x86_64.rpm is not installed. Failing package is: mysql-community-client-plugins-8.0.36-1.el8.x86_64
 GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Public key for mysql-community-common-8.0.36-1.el8.x86_64.rpm is not installed. Failing package is: mysql-community-common-8.0.36-1.el8.x86_64
 GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Public key for mysql-community-icu-data-files-8.0.36-1.el8.x86_64.rpm is not installed. Failing package is: mysql-community-icu-data-files-8.0.36-1.el8.x86_64
 GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Public key for mysql-community-libs-8.0.36-1.el8.x86_64.rpm is not installed. Failing package is: mysql-community-libs-8.0.36-1.el8.x86_64
 GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
Public key for mysql-community-server-8.0.36-1.el8.x86_64.rpm is not installed. Failing package is: mysql-community-server-8.0.36-1.el8.x86_64
 GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql
The downloaded packages were saved in cache until the next successful transaction.
You can remove cached packages by executing 'yum clean packages'.
Error: GPG check FAILED

根据您提供的错误信息,这个问题通常发生在使用 Yum 或 DNF 时,当您尝试安装的包所需要的 GPG 密钥(用于验证包的真实性)已存在但并不对应该包时。要解决这个问题,您需要导入正确的 GPG 密钥或者禁用 GPG 检查,虽然禁用检查不是推荐做法,因为它可能会使您的系统面临安全风险。

接下来,我会提供针对这两个应对措施的具体步骤:

解决方案 1:导入正确的 GPG 密钥
首先,确保您有正确版本的 GPG 密钥。可从 MySQL 官方仓库导入:

sudo rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
如果上述密钥导入后没解决问题,建议从 MySQL 官方文档查找对应您要安装版本的正确密钥。

解决方案 2:禁用 GPG 检查
这不是推荐的做法,但如果您需要立即安装并信任软件来源,可以在安装命令中添加选项来禁用 GPG 检查:

sudo yum install mysql-community-server --nogpgcheck
清理旧密钥
如果错误消息表明已安装了某个密钥,您可能需要先删除错误的密钥。使用以下命令:

sudo rpm -e --allmatches gpg-pubkey-5072e1f5
请将 gpg-pubkey-5072e1f5 替换为错误消息中提到的相关密钥。


启动MySQL服务:

sudo systemctl start mysqld


运行安全安装脚本:

sudo mysql_secure_installation


和Ubuntu一样,设置root密码和其他安全选项。

检查MySQL服务:

sudo systemctl status mysqld


登录MySQL:
MySQL 5.7及以上版本在安装时会在/var/log/mysqld.log文件中生成一个临时密码。通过以下命令获取该密码:

sudo grep 'temporary password' /var/log/mysqld.log

随后使用此临时密码登录MySQL:

mysql -u root -p

然后你会需要更改密码,检查一下密码要求

SHOW VARIABLES LIKE 'validate_password%'; 

修改密码

ALTER USER 'root'@'localhost' IDENTIFIED BY 'NewPassword'; 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值