环境:
OS:UOS Server 20 统信服务器操作系统V20(1070)
mysql:5.7.42
操作系统下载
https://www.chinauos.com/resource/download-server
查看系统glibc版本
[root@localhost yum.repos.d]# ldd --version
ldd (GNU libc) 2.28
Copyright (C) 2018 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.
[root@localhost yum.repos.d]# getconf -a | grep glibc
GNU_LIBC_VERSION glibc 2.28
1.查看操作系统
[root@localhost yum.repos.d]# uname -a
Linux localhost.localdomain 4.19.90-2409.6.0.0297.101.uel20.x86_64 #1 SMP Wed Jul 2 19:39:26 CST 2025 x86_64 x86_64 x86_64 GNU/Linux
[root@localhost yum.repos.d]# cat /etc/os-release
PRETTY_NAME="UOS Server 20"
NAME="UOS Server 20"
VERSION_ID="20"
VERSION="20"
ID=uos
HOME_URL="https://www.chinauos.com/"
BUG_REPORT_URL="https://bbs.chinauos.com/"
VERSION_CODENAME=fuyu
PLATFORM_ID="platform:uel20"
2.获取mysql安装介质
mysql-5.7.42-linux-glibc2.12-x86_64.tar.gz
3.创建mysql用户和用户组(系统已经创建不需要创建)
[root@localhost soft]#groupadd mysql
[root@localhost soft]#useradd mysql -s /sbin/nologin -M -g mysql
4.创建安装主目录
[root@localhost soft]#mkdir -p /home/middle/
5.下载解压安装
[root@localhost soft]# tar -xvf mysql-5.7.42-linux-glibc2.12-x86_64.tar.gz
[root@localhost soft]# mv mysql-5.7.42-linux-glibc2.12-x86_64 /home/middle/mysql57
6.创建相应的目录
[root@node1 mysql8]# cd /home/middle/mysql57
[root@localhost mysql8]# mkdir data ##数据文件目录
[root@localhost mysql8]# mkdir conf ## 配置文件目录
[root@localhost mysql8]# mkdir -p mysqllog/relaylog ##主从环境relaylog
[root@localhost mysql8]# mkdir -p mysqllog/logfile ##错误日志文件
[root@localhost mysql8]# mkdir -p mysqllog/binlog ##binlog文件
[root@localhost mysql8]# mkdir -p secure_file ##secure_file_priv参数指定路
7.初始化数据库
root账户下
[root@localhost mysql57]# cd /home/middle/mysql57/bin
[root@localhost bin]# ./mysqld --initialize --user=mysql --basedir=/home/middle/mysql57 --datadir=/home/middle/mysql57/data --lc_messages_dir=/home/middle/mysql57/share --lc_messages=en_US
2025-09-18T06:00:55.919169Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2025-09-18T06:00:56.423394Z 0 [Warning] InnoDB: New log files created, LSN=45790
2025-09-18T06:00:56.491328Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2025-09-18T06:00:56.557030Z 0 [Warning] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: d7b45ab2-9454-11f0-b19f-080027cc83cf.
2025-09-18T06:00:56.559366Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2025-09-18T06:00:56.832678Z 0 [Warning] A deprecated TLS version TLSv1 is enabled. Please use TLSv1.2 or higher.
2025-09-18T06:00:56.832815Z 0 [Warning] A deprecated TLS version TLSv1.1 is enabled. Please use TLSv1.2 or higher.
2025-09-18T06:00:56.833676Z 0 [Warning] CA certificate ca.pem is self signed.
2025-09-18T06:00:56.873903Z 1 [Note] A temporary password is generated for root@localhost: %RJ7covHN&:l
8.准备配置文件
root@db:/home/middle/mysql57/conf# more my.cnf
[mysqld]
port=13306
server-id=1
basedir=/home/middle/mysql57
datadir=/home/middle/mysql57/data
max_connections = 5000
character_set_server=utf8mb4
collation-server=utf8mb4_general_ci
init_connect='SET collation_connection = utf8mb4_general_ci'
init_connect='SET NAMES utf8mb4'
interactive_timeout=86400
wait_timeout=86400
skip-external-locking
key_buffer_size= 128M
max_allowed_packet=32M
query_cache_size=32M
read_buffer_size=2M
sort_buffer_size=1M
join_buffer_size= 128M
innodb_file_per_table= 1
innodb_open_files= 5000
innodb_buffer_pool_size= 4G
innodb_write_io_threads= 16
innodb_read_io_threads= 16
innodb_thread_concurrency = 0
innodb_purge_threads= 1
innodb_flush_log_at_trx_commit= 2
innodb_log_buffer_size=16M
innodb_log_file_size=512M
innodb_log_files_in_group= 5
innodb_max_dirty_pages_pct= 90
innodb_lock_wait_timeout= 120
bulk_insert_buffer_size= 64M
myisam_sort_buffer_size=64M
myisam_max_sort_file_size= 10G
log_bin_trust_function_creators=1
event_scheduler=1
max_binlog_size=100M
binlog_format=row
log-bin=/home/middle/mysql57/mysqllog/binlog/binlog.bin
slow_query_log=on
slow_query_log_file=/home/middle/mysql57/mysqllog/logfile/slow-query.log
long_query_time=1
log_queries_not_using_indexes=on
log-error=/home/middle/mysql57/mysqllog/logfile/mysql-err.log
binlog_cache_size=4MB
skip-host-cache
skip-name-resolve
expire_logs_days=15
skip-slave-start
relay-log-index=/home/middle/mysql57/mysqllog/relaylog/slave-relay-bin.index
relay-log=/home/middle/mysql57/mysqllog/relaylog/relaylog-binlog
replicate-ignore-db=information_schema,performance_schema,sys
slave_net_timeout=60
language=/home/middle/mysql57/share/english
early-plugin-load=""
explicit_defaults_for_timestamp=true
log_slave_updates=1
gtid_mode=ON
enforce_gtid_consistency = ON
lower_case_table_names=1
sql_mode='STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION'
secure_file_priv=/home/middle/mysql57/secure_file[client]
port = 13306
default-character-set = utf8mb4[mysqldump]
quick
max_allowed_packet = 32M
[myisamchk]
key_buffer_size = 8M
sort_buffer_size = 8M
read_buffer = 4M
write_buffer = 4M
9.生成错误日志文件
[root@localhost conf]# echo>/home/middle/mysql57/mysqllog/logfile/mysql-err.log
10.修改目录权限
[root@localhost mha]# cd /home/middle
[root@localhost opt]# chown -R mysql:mysql ./mysql57
11.启动
(在root用户下执行)
[root@node1 opt]# /home/middle/mysql57/bin/mysqld_safe --defaults-file=/home/middle/mysql57/conf/my.cnf --user=mysql &
12.登陆数据库修改相应用户密码
[root@localhost middle]# /home/middle/mysql57/bin/mysql -h localhost -uroot -P13306 -p
mysql> set password=password('mysql');
Query OK, 0 rows affected, 1 warning (0.05 sec)
##############################xtrabackup备份##############################
1.获取介质
percona-xtrabackup-2.4.28-Linux-x86_64.glibc2.17.tar.gz
下载地址
https://www.percona.com/downloads
2.解压安装
[root@localhost soft]# tar -xvf percona-xtrabackup-2.4.28-Linux-x86_64.glibc2.17.tar.gz
[root@localhost soft]# mv percona-xtrabackup-2.4.28-Linux-x86_64.glibc2.17 /opt/xtrabackup-2.4.28
3.备份
/opt/xtrabackup-2.4.28/bin/innobackupex --defaults-file=/home/middle/mysql57/conf/my.cnf --user=root --password=mysql --socket=/tmp/mysql.sock --stream=tar /tmp|gzip >/tmp/xtrabackup_20250912.tar.gz