CentOS Stream release 9安装 MySQL(一)

CentOS Stream 上安装 MySQL 的方法与传统的 CentOS 类似,但由于 CentOS Stream 的软件包更新策略不同,可能会遇到一些依赖问题。以下是详细安装步骤:

1. 添加 MySQL 官方 Yum 仓库

复制代码
sudo rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el9-1.noarch.rpm

注意

  • 如果是 CentOS Stream 8 ,使用 el8 版本:

    复制代码
    sudo rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el8-4.noarch.rpm
  • 如果是 CentOS Stream 9 ,使用 el9 版本(如上)。


2. 检查可用的 MySQL 版本

复制代码
sudo dnf module list mysql

如果默认启用的是 MySQL 8.0,可以直接安装。如果需要 MySQL 5.7(不推荐,即将停止支持),可以禁用 8.0 并启用 5.7:

复制代码
sudo dnf config-manager --disable mysql80-community
sudo dnf config-manager --enable mysql57-community

3. 安装 MySQL Server

复制代码
sudo dnf install mysql-community-server

如果遇到依赖问题(如 libssllibcrypto 缺失),可以尝试:

复制代码
sudo dnf install openssl

或手动安装兼容版本:

复制代码
sudo dnf install openssl1.1
在运行sudo dnf install mysql-community-server命令时报错
复制代码
MySQL 8.0 Community Server                                                                                                                                                                                                                                                                                    3.0 MB/s | 3.1 kB     00:00    
GPG key at file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022 (0x3A79BD29) is already installed
The GPG keys listed for the "MySQL 8.0 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-client-8.0.41-1.el9.x86_64
 GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022
Public key for mysql-community-client-plugins-8.0.41-1.el9.x86_64.rpm is not installed. Failing package is: mysql-community-client-plugins-8.0.41-1.el9.x86_64
 GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022
Public key for mysql-community-common-8.0.41-1.el9.x86_64.rpm is not installed. Failing package is: mysql-community-common-8.0.41-1.el9.x86_64
 GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022
Public key for mysql-community-icu-data-files-8.0.41-1.el9.x86_64.rpm is not installed. Failing package is: mysql-community-icu-data-files-8.0.41-1.el9.x86_64
 GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022
Public key for mysql-community-libs-8.0.41-1.el9.x86_64.rpm is not installed. Failing package is: mysql-community-libs-8.0.41-1.el9.x86_64
 GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022
Public key for mysql-community-server-8.0.41-1.el9.x86_64.rpm is not installed. Failing package is: mysql-community-server-8.0.41-1.el9.x86_64
 GPG Keys are configured as: file:///etc/pki/rpm-gpg/RPM-GPG-KEY-mysql-2022
The downloaded packages were saved in cache until the next successful transaction.
You can remove cached packages by executing 'dnf clean packages'.
Error: GPG check FAILED

这个错误是因为 MySQL 的 GPG 密钥验证失败(因为我之前安装了别的版本),导致无法安装软件包。错误信息表明:

  1. GPG 密钥已安装,但不匹配The GPG keys listed for the "MySQL 8.0 Community Server" repository are already installed but they are not correct for this package)。

  2. 部分软件包的公共密钥未安装Public key for mysql-community-xxx is not installed)。


解决方案:重新导入正确的 MySQL GPG 密钥
1. 删除旧的 GPG 密钥
复制代码
sudo rpm -e --allmatches gpg-pubkey $(rpm -qa | grep gpg-pubkey | grep -i mysql)

这会移除所有与 MySQL 相关的旧 GPG 密钥。

2. 重新下载并导入最新的 MySQL GPG 密钥
复制代码
sudo rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2023

注意

  • 如果 2023 版本的密钥仍然有问题,可以尝试 2022

    复制代码
    sudo rpm --import https://repo.mysql.com/RPM-GPG-KEY-mysql-2022
3. 清理缓存并重新安装
复制代码
sudo dnf clean all
sudo dnf install mysql-community-server

4. 启动 MySQL 并设置开机自启

复制代码
sudo systemctl start mysqld
sudo systemctl enable mysqld

5. 获取临时 root 密码

复制代码
sudo grep 'temporary password' /var/log/mysqld.log

输出类似:

复制代码
2023-01-01T12:00:00.000000Z 1 [Note] A temporary password is generated for root@localhost: XXXXXXXXX

6. 运行安全配置向导

复制代码
sudo mysql_secure_installation

按照提示:

  1. 输入临时密码。

  2. 设置新密码(需符合 MySQL 密码策略)。

  3. 移除匿名用户?Y

  4. 禁止 root 远程登录?Y

  5. 删除测试数据库?Y

  6. 重新加载权限表?Y

相关推荐
孤岛与风1 分钟前
CentOS扩容非LVM分区
linux·运维·centos
BIBI20492 分钟前
如何使用 Xshell 8 连接到一台 CentOS 7 电脑(服务器)
linux·服务器·centos
卑微的小李8 分钟前
Qt在Linux下编译发布 -- linuxdeployqt的使用
linux·c++·qt
小猪写代码20 分钟前
Ubuntu 的磁盘管理
linux·ubuntu
御坂1002721 分钟前
SQL查询-设置局部变量(PostgreSQL、MySQL)
sql·mysql·postgresql
Jasonakeke1 小时前
【重学 MySQL】九十二、 MySQL8 密码强度评估与配置指南
android·数据库·mysql
Seven972 小时前
一文带你了解缓存和数据库一致性问题
redis·mysql
用户51681661458412 小时前
[VMware 无法检测此光盘中映像中的操作系统] VMware创建虚拟机无法检测操作系统iso镜像文件
linux·前端
MacroZheng2 小时前
斩获 7.8K star!一款堪称开源监控新标杆的项目,牛皮!
java·linux·后端
秋难降3 小时前
零基础学习SQL(九)——存储引擎
前端·sql·mysql