Skip to main content
☘️ Septvean's Documents
Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Toggle Dark/Light/Auto mode Back to homepage

在 AlmaLinux 9 上安装 MySQL 8.4

运维环境:

  • 操作系统:AlmaLinux 9.7
  • 数据库版本:Percona Server 8.4

准备工作

⚠️ 不推荐 Percona 官方的 YUM 仓库,因为有些版本可能较低,或者兼容性有问题。

推荐下载 RPM 包,并手动安装。

下载 RPM 包

Percona 官方下载链接:https://www.percona.com/downloads

Percona Distribution for MySQL

  • Select Product:Percona Distribution for MySQL
  • Select Product Version:PERCONA-DISTRIBUTION-MYSQL-PS-8.4.7
  • Select Platform:RED HAT ENTERPRISE LINUX / CENTOS / ORACLE LINUX 9

下载以下文件

  • 注意:平台是 x86_64
jemalloc
jemalloc-devel
percona-icu-data-files
percona-mysql-router
percona-mysql-shell
percona-orchestrator
percona-orchestrator-cli
percona-orchestrator-client
percona-server-client
percona-server-devel
percona-server-js
percona-server-rocksdb
percona-server-server
percona-server-shared
percona-telemetry-agent
percona-toolkit
percona-xtrabackup-84
perl-DBD-MySQL
proxysql2
qpress-11

Percona Server 8.4.7 的相关文件

jemalloc-3.6.0-1.el9.x86_64.rpm
jemalloc-devel-3.6.0-1.el9.x86_64.rpm
percona-icu-data-files-8.4.7-7.1.el9.x86_64.rpm
percona-mysql-router-8.4.7-7.1.el9.x86_64.rpm
percona-mysql-shell-8.4.7-1.el9.x86_64.rpm
percona-orchestrator-3.2.6-19.el9.x86_64.rpm
percona-orchestrator-cli-3.2.6-19.el9.x86_64.rpm
percona-orchestrator-client-3.2.6-19.el9.x86_64.rpm
percona-server-client-8.4.7-7.1.el9.x86_64.rpm
percona-server-devel-8.4.7-7.1.el9.x86_64.rpm
percona-server-js-8.4.7-7.1.el9.x86_64.rpm
percona-server-rocksdb-8.4.7-7.1.el9.x86_64.rpm
percona-server-server-8.4.7-7.1.el9.x86_64.rpm
percona-server-shared-8.4.7-7.1.el9.x86_64.rpm
percona-telemetry-agent-1.0.7-1.el9.x86_64.rpm
percona-toolkit-3.7.1-2.el9.x86_64.rpm
percona-xtrabackup-84-8.4.0-5.1.el9.x86_64.rpm
perl-DBD-MySQL-5.013-1.el9.x86_64.rpm
proxysql2-2.7.3-1.1.el9.x86_64.rpm
qpress-11-4.el9.x86_64.rpm

安装 Percona MySQL

禁用系统默认的 MySQL 仓库

dnf module disable mysql

安装 MySQL 服务端、客户端、运维工具

dnf install -y \
    percona-icu-data-files-*.rpm \
    percona-mysql-shell-*.rpm \
    percona-server-client-*.rpm \
    percona-server-devel-*.rpm \
    percona-server-server-*.rpm \
    percona-server-shared-*.rpm \
    percona-telemetry-agent-*.rpm \
    percona-toolkit-*.rpm \
    percona-xtrabackup-84-*.rpm \
    perl-DBD-MySQL-*.rpm

启动并设置开机自启

# 备份配置文件
cp -v /etc/my.cnf /etc/my.cnf_default

# 使用 Go 语言编写的 gen-mysql-cnf 生成配置文件 mysql.cnf
./gen-mysql-cnf-linux-amd64 -version 8.4

# 拷贝配置文件
cp -v mysql.cnf /etc/my.cnf

# 删除数据目录
rm -rf /data/mysql/8.4/{data,log} /var/lib/mysql /var/run/mysqld

# 创建数据目录
mkdir -p /data/mysql/8.4/{data,log} /var/lib/mysql /var/run/mysqld

# 设置权限
chown -R mysql:mysql /data/mysql/8.4/{data,log} /var/lib/mysql /var/run/mysqld

# 启动服务
systemctl start mysqld

# 首次启动需要等待一会, MySQL 需要初始化数据库

# 查看状态
systemctl status mysqld

# 查看日志
cat /data/mysql/8.4/log/mysqld.log

# 设置开机自启
systemctl enable mysqld

修改 MySQL root 密码

# 获取 MySQL 初始 root 密码
grep 'temporary password' /data/mysql/8.4/log/mysqld.log

# 登录 MySQL
mysql -uroot -p

修改密码:

ALTER USER 'root'@'localhost' IDENTIFIED BY 'KdX3V7nC!9#Q';

CREATE USER 'root'@'127.0.0.1' IDENTIFIED BY 'KdX3V7nC!9#Q';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'127.0.0.1' WITH GRANT OPTION;

CREATE USER 'root'@'%' IDENTIFIED BY 'KdX3V7nC!9#Q';
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;

FLUSH PRIVILEGES;