确认系统架构和 glibc 版本
# 查看系统架构
[root@localhost ~]# uname -m
x86_64
# 查看 glibc 版本(二进制包要求 glibc ≤ 系统 glibc)
[root@localhost ~]# ldd --version
ldd (GNU libc) 2.38
Copyright (C) 2023 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
Written by Roland McGrath and Ulrich Drepper.卸载 mariadb-libs(必须)(没安装就算了)
麒麟 V10/V11 预装了 mariadb-libs,与 MySQL 冲突,必须先卸载
#检查安装包
[root@localhost ~]# rpm -qa | grep -i mariadb
#卸载
[root@localhost ~]# sudo rpm -e --nodeps mariadb-libs-*.rpm
错误:未安装软件包 mariadb-libs-*.rpm
#刷新动态库
[root@localhost ~]# sudo ldconfig安装依赖包
[root@localhost ~]# yum install -y libaio perl perl-devel
Last metadata expiration check: 18:45:07 ago on 2026年05月08日 星期五 13时54分32秒.
Package libaio-0.3.113-9.p01.ky11.x86_64 is already installed.
Package perl-4:5.38.0-9.p01.ky11.x86_64 is already installed.
Package perl-devel-4:5.38.0-9.p01.ky11.x86_64 is already installed.
Dependencies resolved.
Nothing to do.
Complete!优化系统参数
tee -a /etc/security/limits.conf << 'EOF'
* soft nofile 65535
* hard nofile 65535
* soft nproc 65535
* hard nproc 65535
EOF重启后生效或执行 ulimit -n 65535 临时生效。
创建 mysql 用户和目录
#创建用户
sudo groupadd mysql
sudo useradd -r -g mysql -s /bin/false mysql
# 创建安装目录(示例:/opt/app/mysql)
sudo mkdir -p /opt/app/mysql
sudo mkdir -p /opt/app/mysql/data
sudo mkdir -p /opt/app/mysql/logs
# 授权
sudo chown -R mysql:mysql /opt/app/mysql下载 MySQL 二进制包
[root@localhost tmp]# wget https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.46-linux-glibc2.28-x86_64.tar.xz
--2026-05-09 09:05:07-- https://dev.mysql.com/get/Downloads/MySQL-8.0/mysql-8.0.46-linux-glibc2.28-x86_64.tar.xz
正在解析主机 dev.mysql.com (dev.mysql.com)... 184.85.65.251, 2a02:26f0:2780:b98::2e31, 2a02:26f0:2780:b95::2e31
正在连接 dev.mysql.com (dev.mysql.com)|184.85.65.251|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 302 Moved Temporarily
位置:https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.46-linux-glibc2.28-x86_64.tar.xz [跟随至新的 URL]
--2026-05-09 09:05:08-- https://cdn.mysql.com//Downloads/MySQL-8.0/mysql-8.0.46-linux-glibc2.28-x86_64.tar.xz
正在解析主机 cdn.mysql.com (cdn.mysql.com)... 23.48.176.139, 2a02:26f0:2780:b9c::1d68, 2a02:26f0:2780:b90::1d68
正在连接 cdn.mysql.com (cdn.mysql.com)|23.48.176.139|:443... 已连接。
已发出 HTTP 请求,正在等待回应... 200 OK
长度:892567132 (851M) [text/plain]
正在保存至: “mysql-8.0.46-linux-glibc2.28-x86_64.tar.xz”
mysql-8.0.46-linux-glibc2.28- 100%[==============================================>] 851.22M 3.87MB/s 用时 3m 14s
2026-05-09 09:08:23 (4.39 MB/s) - 已保存 “mysql-8.0.46-linux-glibc2.28-x86_64.tar.xz” [892567132/892567132])解压到安装目录
[root@localhost tmp]# tar -xvf mysql-8.0.46-linux-glibc2.28-x86_64.tar.xz -C /opt/app/mysql --strip-components=1
mysql-8.0.46-linux-glibc2.28-x86_64/bin/
mysql-8.0.46-linux-glibc2.28-x86_64/bin/myisam_ftdump
mysql-8.0.46-linux-glibc2.28-x86_64/bin/myisamchk
mysql-8.0.46-linux-glibc2.28-x86_64/bin/myisamlog
mysql-8.0.46-linux-glibc2.28-x86_64/bin/myisampack
mysql-8.0.46-linux-glibc2.28-x86_64/bin/mysql
mysql-8.0.46-linux-glibc2.28-x86_64/bin/mysql_config_editor
mysql-8.0.46-linux-glibc2.28-x86_64/bin/mysql_migrate_keyring
mysql-8.0.46-linux-glibc2.28-x86_64/bin/mysql_secure_installation
mysql-8.0.46-linux-glibc2.28-x86_64/bin/mysql_ssl_rsa_setup
mysql-8.0.46-linux-glibc2.28-x86_64/bin/mysql_tzinfo_to_sql目录授权
[root@localhost tmp]# chown -R mysql:mysql /opt/app/mysql
[root@localhost tmp]#创建my文件
sudo tee /etc/my.cnf << 'EOF'
[client]
port=3306
socket=/opt/app/mysql/mysql.sock
[mysql]
prompt="\u@\h [\d]> "
no-auto-rehash
[mysqld]
user=mysql
port=3306
bind-address=0.0.0.0
socket=/opt/app/mysql/mysql.sock
basedir=/opt/app/mysql
datadir=/opt/app/mysql/data
log-error=/opt/app/mysql/logs/mysqld.log
pid-file=/opt/app/mysql/mysqld.pid
character-set-server=utf8mb4
collation-server=utf8mb4_unicode_ci
lower_case_table_names=0
default-storage-engine=INNODB
max_connections=1000
connect_timeout=10
innodb_buffer_pool_size=1G
innodb_log_file_size=256M
innodb_flush_log_at_trx_commit=1
innodb_flush_method=O_DIRECT
server-id=1
log-bin=/opt/app/mysql/logs/mysql-bin
binlog_format=ROW
expire_logs_days=7
slow_query_log=1
slow_query_log_file=/opt/app/mysql/logs/slow.log
long_query_time=2
table_open_cache=2000
open_files_limit=65535
back_log=600
EOF初始化数据库
[root@localhost tmp]# /opt/app/mysql/bin/mysqld --defaults-file=/etc/my.cnf --initialize --user=mysql
[root@localhost tmp]# 查看临时密码
[root@localhost tmp]# grep 'temporary password' /opt/app/mysql/logs/mysqld.log
2026-05-09T01:13:45.093898Z 6 [Note] [MY-010454] [Server] A temporary password is generated for root@localhost: B!)bsh:tp1wA
[root@localhost tmp]# 配置 systemd 服务
sudo tee /etc/systemd/system/mysql.service << 'EOF'
[Unit]
Description=MySQL Server
After=network.target
[Service]
Type=simple
User=mysql
Group=mysql
ExecStart=/opt/app/mysql/bin/mysqld --defaults-file=/etc/my.cnf
ExecStop=/opt/app/mysql/bin/mysqladmin -u root -p shutdown
Restart=on-failure
RestartSec=10
[Install]
WantedBy=multi-user.target
EOF启动 MySQL 服务
# 重新加载 systemd 配置
systemctl daemon-reload
# 启动 MySQL
systemctl start mysql
# 设置开机自启
systemctl enable mysql
# 检查状态
systemctl status mysql登录 MySQL 并修改 root 密码
登录
[root@localhost tmp]# /opt/app/mysql/bin/mysql -uroot -p
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 9
Server version: 8.0.46
Copyright (c) 2000, 2026, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
修改密码
root@localhost [(none)]> ALTER USER 'root'@'localhost' IDENTIFIED BY 'xxxxxx'; #自己设置哈
Query OK, 0 rows affected (0.02 sec)
root@localhost [(none)]> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)
root@localhost [(none)]> exit
Bye
评论