Centos Stream10 安装 MySQL-9.7.2-linux-glibc2.28-x86_64.tar

Centos Stream10 安装 MySQL-9.7.2-linux

Version: MySQL-9.7.2-linux-glibc2.28-x86_64.tar.xz

更新系统

小白认为吧!保持系统最新,还是有必要的,当然我是个个例。

shell 复制代码
# 清理所有旧的软件包缓存和仓库元数据
dnf clean all
# 自动卸载系统不再需要的孤立依赖包
dnf autoremove -y
# 先确认当前正在运行的内核,绝对不要删除这个版本
uname -r
# 自动清理所有旧内核,仅保留当前在用版本
dnf remove --oldinstallonly -y

官网下载

wget 方式下载(建议使用)

shell 复制代码
sudo wget https://dev.mysql.com/get/Downloads/MySQL-9.7/mysql-9.7.2-linux-glibc2.28-x86_64.tar.xz

官网下载

查看其他资料,哈哈哈!

MySQL安装流程

基础依赖库

包含 libaio、numactl、wget、vim

shell 复制代码
sudo dnf install -y libaio numactl wget vim

删除MySQL残留

卸载系统自带的 MariaDB 和旧版 MySQL 残留

shell 复制代码
# 查看已安装的数据库相关包
sudo rpm -qa | grep -iE 'mysql|mariadb'
# 批量卸载所有相关包
sudo dnf remove -y mariadb* mysql*
# 删除残留数据目录
sudo rm -rf /var/lib/mysql /etc/my.cnf /var/log/mysqld.log

MySQL 安装

创建系统用户

mysql不能在 Root用户下运行,so 必须创建一个非 Root 用户

shell 复制代码
### 创建用户
useradd mysql
### 设置密码
passwd mysql
输入密码
### 删除用户
userdel mysql
### 切换用户命令
su mysql

创建系统所需文件夹

包括 数据文件夹、安装文件夹

数据文件夹:

binlog、datas、logs、secure_data

安装文件夹:

/server/tools

bash 复制代码
## create base package file
mkdir -p /server/tools
### create tool datas  file
mkdir -p /data/mysql/{binlog,datas,logs,secure_data}

开放 mysql防火墙端口

添加端口

shell 复制代码
firewall-cmd --add-port=3306/tcp --permanent

刷新防火墙

shell 复制代码
firewall-cd --reload

查看端口

shell 复制代码
firewall-cmd --list-port

解压

将mysql-9.7.2 解压至指定文件件

bash 复制代码
## 解压
tar -xvf mysql-9.7.2-linux-glibc2.28-x86_64.tar.xz -C /server/tools/

## 重命名 mysql 解压缩文件(decompressing files)
cd /server/tools/
mv mysql-9.7.2-linux-glibc2.28-x86_64 mysql-9.7.2
软连接
shell 复制代码
ln -s /server/tools/mysql-9.7.2 /usr/local/mysql

编辑mysql 配置文件

shell 复制代码
vi /etc/mysql.cnf
shell 复制代码
[mysqld]
# ========== 基础路径与身份 ==========
user=mysql
port=3306
basedir=/server/tools/mysql-9.7.2
datadir=/data/mysql/datas
socket=/tmp/mysql.sock
pid-file=/server/tools/mysql-9.7.2/mysqld.pid
log-error=/data/mysql/logs/error.log
lc-messages-dir=/server/tools/mysql-9.7.2/share

# ========== 字符集与时区 ==========
character-set-server=utf8mb4
collation-server=utf8mb4_0900_ai_ci
default-time-zone=+08:00
# skip-character-set-client-handshake=1

# ========== 连接与基础限制 ==========
max_connections=1000
max_connect_errors=100000
wait_timeout=28800
interactive_timeout=28800
back_log=2048
max_allowed_packet=64M
open_files_limit=65535

# ========== InnoDB 核心优化(32G内存专属) ==========
default-storage-engine=INNODB
innodb_buffer_pool_size=16G
innodb_buffer_pool_instances=8
# innodb_log_file_size=1G
innodb_redo_log_capacity=1G
# innodb_log_files_in_group=2
innodb_flush_log_at_trx_commit=1
innodb_flush_method=O_DIRECT
innodb_io_capacity=4000
innodb_io_capacity_max=8000
innodb_read_io_threads=16
innodb_write_io_threads=16
innodb_thread_concurrency=0
innodb_autoinc_lock_mode=2
innodb_adaptive_hash_index=ON
innodb_lru_scan_depth=4096
innodb_page_cleaners=16
innodb_purge_threads=4

# ========== 事务与隔离级别 ==========
transaction_isolation=READ-COMMITTED
innodb_strict_mode=ON

# ========== Binlog 与复制配置 ==========
log-bin=/data/mysql/binlog/mysql-bin
binlog_format=ROW
binlog_row_image=MINIMAL
binlog_expire_logs_seconds=604800
server-id=1
log_bin_index=/data/mysql/binlog/mysql-bin.index
sync_binlog=1
binlog_cache_size=1M
max_binlog_cache_size=8M

# ========== 慢查询与审计 ==========
slow_query_log=ON
slow_query_log_file=/data/mysql/logs/slow.log
long_query_time=2
log_queries_not_using_indexes=OFF
min_examined_row_limit=1000
log_slow_admin_statements=ON

# ========== 排序与临时表优化 ==========
sort_buffer_size=4M
join_buffer_size=4M
read_buffer_size=2M
read_rnd_buffer_size=4M
tmp_table_size=64M
max_heap_table_size=64M

# ========== 安全配置 ==========
bind-address=0.0.0.0
sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_ENGINE_SUBSTITUTION
local_infile=OFF
skip_name_resolve=ON
secure_file_priv=/data/mysql/secure_data

# ========== 表空间与新特性兼容 ==========
innodb_file_per_table=ON
enforce-gtid-consistency=ON
gtid_mode=ON

[client]
socket=/tmp/mysql.sock
default-character-set=utf8mb4
port=3306

[mysql]
default-character-set=utf8mb4

赋权

赋权给 解压文件夹和数据文件夹

shell 复制代码
## 解压文件夹路径
chown -R mysql:mysql /server
## 数据文件夹路径
chown -R mysql:mysql /data

mysql添加至系统环境

bash 复制代码
vim /etc/profile
bash 复制代码
# mysql home
MYSQL_HOME=/server/tools/mysql-9.7.2

# path evironment
PATH=$PATH:$JAVA_HOME/bin:$MAVEN_HOME/bin:$MYSQL_HOME/bin

export PATH JAVA_HOME MAVEN_HOME MYSQL_HOME
重载资源
shell 复制代码
source /etc/profile

初始化mysql

初始化命令:

-- initialize 初始化

-- user=mysql 指定用户

-- basedir=/server/tools/mysql-9.7.2 mysql解压目录, = 亲后不能有空格

-- datadir=/data/mysql/datas mysql数据目录,= 亲后不能有空格

shell 复制代码
/server/tools/mysql-9.7.2/bin/mysqld --initialize --user=mysql --basedir=/server/tools/mysql-9.7.2 --datadir=/data/mysql/datas

查看输出日志

shell 复制代码
cat /data/mysql/logs/error.log

后台输出

bash 复制代码
2026-11-02T19:16:47.294720Z 0 [System] [MY-015017] [Server] MySQL Server Initialization - start.
2026-11-02T19:16:47.296060Z 0 [Warning] [MY-011070] [Server] 'binlog_format' is deprecated and will be removed in a future release.
2026-11-02T19:16:47.296488Z 0 [System] [MY-013169] [Server] /server/tools/mysql-9.7.2/bin/mysqld (mysqld 9.7.2) initializing of server in progress as process 7918
2026-11-02T19:16:47.302893Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2026-11-02T19:16:48.706906Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2026-11-02T19:16:49.210278Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: a%RJou9XfQz9
2026-11-02T19:16:50.703428Z 0 [System] [MY-015018] [Server] MySQL Server Initialization - end.

查看mysql临时密码

shell 复制代码
sudo grep 'temporary password' /data/mysql/logs/error.log

后台输出

bash 复制代码
2026-11-02T19:16:49.210278Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: a%RJou9XfQz9

MySQL 服务

启动服务命令

加载服务
shell 复制代码
sudo systemctl daemon-reload
启动服务
shell 复制代码
sudo systemctl start mysqld
重启服务
shell 复制代码
sudo systemctl restart mysqld
失败后重新设置重启
shell 复制代码
sudo systemctl reset-failed mysqld
查看服务状态
shell 复制代码
sudo systemctl status mysqld
设置服务开机自启
shell 复制代码
sudo systemctl enable mysqld

编写mysql 服务配置文件

在系统中服务文件下创建mysqld.service文件

bash 复制代码
vim /etc/systemd/system/mysqld.service

具体内容

shell 复制代码
[Unit]
Description=MySQL Server
After=network.target

[Service]
Type=simple
User=mysql
Group=mysql
ExecStart=/server/tools/mysql-9.7.2/bin/mysqld --defaults-file=/etc/my.cnf
LimitNOFILE=65535
Restart=on-failure
RestartSec=5
PrivateTmp=false
ProtectHome=false
ProtectSystem=false
NoNewPrivileges=false

[Install]
WantedBy=multi-user.target
启动服务

包括服务加载、服务启动、服务状态

shell 复制代码
# 服务加载
sudo systemctl daemon-reload
# 服务启动
sudo systemctl start mysqld
# 服务状态
sudo systemctl status mysqld

后台显示

bash 复制代码
● mysqld.service - MySQL Server
     Loaded: loaded (/etc/systemd/system/mysqld.service; 5:185mdisabled; preset: 5:185m>
     Active: activating (auto-restart) (Result: exit-code) since Tue 2026-1>
 Invocation: b7e18306328f48b0bc174750b32b5750
    Process: 9188 ExecStart=/server/tools/mysql-9.7.2/bin/mysqld --defaults>
   Main PID: 9188 (code=exited, status=203/EXEC)
   Mem peak: 1.2M
        CPU: 6ms

Main PID: 9188 (code=exited, status=203/EXEC)

小白的问题是被selinux 拦截了

SELinux 拦截问题

setenforce 0: 是临时把 SELinux 从 Enforcing 切到 Permissive (只记录不拦截),重启后失效。用来验证刚才的 203/EXEC 是不是 SELinux 引起的

setenforce 1: 是把 SELinux 从 Permissive 切到 Enforcing 。

shell 复制代码
setenforce 0        # 需要 root
getenforce          # 期望输出 Permissive
setenforce 1        # 需要 root
getenforce          # 期望输出 Enforcing

解决SELinux 拦截问题

shell 复制代码
# 临时关闭拦截
setenforce 0        # 需要 root
# 重启服务
sudo systemctl restart mysqld
# 开启拦截
setenforce 1        # 需要 root
# 查看服务状态
sudo systemctl status mysqld

启动服务后查看状态后台输出

bash 复制代码
Active: active (running) since Tue 2026-11-03 02:23:38 CST; 22min ago
bash 复制代码
● mysqld.service - MySQL Server
     Loaded: loaded (/etc/systemd/system/mysqld.service; disabled; preset: disabled)
     Active: active (running) since Tue 2026-11-03 02:23:38 CST; 22min ago
 Invocation: 153f75cf12d5434c8f2e6813eaa7cba9
   Main PID: 10940 (mysqld)
      Tasks: 70 (limit: 22802)
     Memory: 1.9G (peak: 1.9G)
        CPU: 7.471s
     CGroup: /system.slice/mysqld.service
             └─10940 /server/tools/mysql-9.7.2/bin/mysqld --defaults-file=/etc/my.cnf

Nov 03 02:23:38 itcat systemd[1]: Started mysqld.service - MySQL Server.

重启mysql

查看mysql 临时密码

shell 复制代码
sudo grep 'temporary password' /data/mysql/logs/error.log

启动mysql

shell 复制代码
mysql -u root -p 按Enter键
输入临时密码

修改密码

修改root密码

登录成功后立即修改 root 账户的密码

shell 复制代码
ALTER USER 'root'@'localhost' IDENTIFIED BY '你的自定义强密码';
修改远程访问密码

按需开启远程访问权限(生产环境建议限制指定IP访问)

shell 复制代码
# 创建远程密码
CREATE USER 'root'@'%' IDENTIFIED BY '你的root密码';
# 赋权
GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' WITH GRANT OPTION;
# 刷新
FLUSH PRIVILEGES;
# 重置远程密码
ALTER USER 'root'@'%' IDENTIFIED BY '你的新密码';
FLUSH PRIVILEGES;
# 查看所有用户
SELECT user, host, plugin FROM mysql.user;

验证参数信息

shell 复制代码
SHOW VARIABLES LIKE '%innodb_buffer_pool%';
SHOW VARIABLES LIKE 'slow_query_log%';

服务自启

设置服务开机自启

shell 复制代码
sudo systemctl enable mysqld

mysql 服务器启动失败状态为203/EXEC

对了关于Main PID: 9743 (code=exited, status=203/EXEC) 介绍及其他解决方案

203/EXEC的含义

203/EXEC 表示 systemd 无法执行单元里指定的可执行文件(ExecStart 指向的路径) 。注意:它连 MySQL 都没启动起来,是 systemd fork 出去直接失败,所以这条日志里 不会有任何 MySQL 自己的错误日志 。

常见原因

原因 说明
路径写错 ExecStart 里的 /server/tools/mysql-9.7.2/bin/mysqld 拼错/不存在
无执行权限 文件存在但没 x 位
SELinux 拦截 文件的安全上下文不对,systemd 执行被拒
解释器/依赖缺失 动态库缺失、/usr/bin/sh 之类解释器找不到

排查三步

看 systemd 到底想执行什么
shell 复制代码
systemctl cat mysqld

重点看 ExecStart= 这一行的 完整路径 ,和你磁盘上实际路径逐个字符对比。

验证这个路径真实可执行
shell 复制代码
ls -l /server/tools/mysql-9.7.2/bin/mysqld
file /server/tools/mysql-9.7.2/bin/mysqld

期望看到 -rwxr-xr-x 且 file 输出是 ELF 64-bit LSB executable。

如果权限不对

shell 复制代码
# 小白不推荐这样做(因为这样会引起上下文件权限不一,导致不能访问)
chmod 755 /server/tools/mysql-9.7.2/bin/mysqld
chown mysql:mysql /server/tools/mysql-9.7.2/bin/mysqld
# 推荐
chown -R mysql:mysql /server
直接用 systemd 的身份跑一次
shell 复制代码
sudo -u mysql /server/tools/mysql-9.7.2/bin/mysqld --version
  • 报 Permission denied → 权限或 SELinux
  • 报 command not found / No such file → 路径错,或软链接断了
  • 报 error while loading shared libraries → 缺动态库
  • 报 cannot execute binary file → 架构不匹配(比如 aarch64 包装到 x86 上)
  • 正常输出 mysqld Ver 9.7.2 → 那问题就在 SELinux 或 unit 配置

软链接/移动目录导致路径失效

shell 复制代码
readlink -f /server/tools/mysql-9.7.2/bin/mysqld

如果原安装目录被改名或挪过,这条会暴露出来。

SELinux 拦截

shell 复制代码
getenforce
ls -Z /server/tools/mysql-9.7.2/bin/mysqld

正确上下文应该是 bin_t 或 mysqld_exec_t。修复

shell 复制代码
semanage fcontext -a -t bin_t "/server/tools/mysql-9.7.2/bin(/.*)?"
restorecon -Rv /server/tools/mysql-9.7.2/bin
快速验证是否 SELinux 引起的(临时切换后重启服务)
shell 复制代码
setenforce 0
systemctl restart mysqld
# 起来了就是 SELinux 问题,处理完记得 setenforce 1
unit 里写了 Type=forking 但 mysqld 不支持

顺便看一眼 Type=。源码编译安装的推荐写法:

shell 复制代码
[Unit]
Description=MySQL Server 9.7.2
After=network.target

[Service]
Type=simple
User=mysql
Group=mysql
ExecStart=/server/tools/mysql-9.7.2/bin/mysqld --defaults-file=/server/tools/mysql-9.7.2/my.cnf
Restart=on-failure
LimitNOFILE=65535

[Install]
WantedBy=multi-user.target
重启
shell 复制代码
systemctl daemon-reload
systemctl restart mysqld

另外:--initialize 那个问题还在

203/EXEC 解决后,你 还是会撞回上一轮的 data directory has files in it 。这两件事得一起处理:

shell 复制代码
# 先确认数据目录状态,彻底清空
sudo find /data/mysql/datas -mindepth 1 -ls

把这条的输出、以及 systemctl cat mysqld 的结果发我,两条线一起定位。目前的判断是: 数据目录没清干净(上轮遗留)+ unit 的 ExecStart 路径或权限不对(本轮新增) 。

注意:这章节关于203/EXEC 这些方法只提供建议性意见,因为小白并没结果真实的验证,所以不敢直言是正确的,只能说是按照这个方向去试着解决问题

结语

ok了,这就完了,自己玩去吧!小白就不陪您了!

相关推荐
say_fall23 分钟前
【Linux系统编程】Linux进程信号:从“外卖到了“到内核里的一张位图
linux·运维·服务器·车载系统·智能硬件
坤坤子吖1 小时前
Linux网络编程:UDP进阶,从字典服务器到简单聊天室
linux·服务器·网络·c++·笔记·学习
Rabitebla1 小时前
【Linux学习笔记】进程篇(九):进程的创建与退出——fork、写时拷贝与退出码
linux·c++·笔记·学习
Decay__1 小时前
19_MySQL 告警与自动化运维 —— 告警分级收敛 / Webhook / 定时巡检 / 脚本库
运维·数据库·sql·mysql·架构
李松桃1 小时前
基于IP的服务配置
linux·nginx-核心模块配置
FungLeo1 小时前
成为全栈·基础补充·Linux 服务器入门
linux·运维·服务器·ssh·部署·成为全栈
keyipatience1 小时前
MySQL 学习(4)常用数据类型
数据库·mysql
爱和冰阔落2 小时前
【Linux网络】TCP 服务器怎么写?从 listen、accept 到 read/write,手写完整 Echo Server
linux·运维·服务器·网络