xtrabackup搭建MySQL 8.0 主从复制
xtrabackup搭建MySQL 8.0 主从复制
- 安装MySQL 8.0.37
- 安装xtrabackup
- GTIDs
- 初始化从库
- 参考:
- GTID概述
- GTID相较与传统复制的优势
- GTID自身存在哪些限制
- GTID工作原理简单介绍
- 如何开启GTID复制
- GTID与传统模式建立复制时候语句的不同点
- 传统复制
- GTID复制
- GTID同步状态简单解析
本次搭建的环境信息如下:
OS版本:Red Hat Enterprise Linux Server release 7.6 (Maipo)
MySQL版本:Server version: 8.0.37
xtrabackup版本:xtrabackup version 8.0.35-31 based on MySQL server 8.0.35 Linux (x86_64) (revision id: 55ec21d7)

本次采用物理备份和还原的方式来进行主从复制的初始化,相比于mysqldump,本方案适合数据量比较大的情况下,初始化很快,而且不像mysqldump的方式,从库不需要先进行初始化。
安装MySQL 8.0.37
groupadd mysql
useradd -g mysql -s /sbin/nologin -d /usr/local/mysql -MN mysql
cd /opt
unxz mysql-8.0.37-linux-glibc2.17-x86_64.tar.xz
tar -xvf mysql-8.0.37-linux-glibc2.17-x86_64.tar
cd /usr/local
ln -s /opt/mysql-8.0.37-linux-glibc2.17-x86_64 mysql
chown -R mysql:mysql /usr/local/mysql/
mkdir -p /data/mysql/mysql3306/{data,logs,tmp}
mv /opt/my.cnf /data/mysql/mysql3306/my3306.cnf
chown -R mysql:mysql /usr/local/mysql/
chown -R mysql:mysql /data/mysql/mysql3306//usr/local/mysql/bin/mysqld --defaults-file=/data/mysql/mysql3306/my3306.cnf --initialize
/usr/local/mysql/bin/mysqld --defaults-file=/data/mysql/mysql3306/my3306.cnf &/usr/local/mysql/bin/mysql -uroot -p -S /tmp/mysql3306.sock
alter user user() identified by 'mysql';
安装xtrabackup
xtrabackup是社区开源产品。但是它不是MySQL自带的工具,需要我们自己进行安装。下面就说下安装过程
1、 下载安装包
由于xtrabackup有版本的区别,根据最佳实践,我们安装的MySQL版本为8.0.37,xtrabackup选择8.0以上最新版本即可,不选择2.4的版本,rpm安装,方便简单。
下载地址:https://www.percona.com/downloads

version:选择最新的
software:选择rpm,就选RHELx。如果是二进制,就选 Linux-Generic
2、安装,为了解决软件依赖问题,采用yum localinstall来安装

缺两个包:zstd和libev.so.4()(64bit),镜像里面没有这两个包,我们手动下载匹配版本进行安装:
# rpm -ivh libev-4.15-7.el7.x86_64.rpm
# rpm -ivh zstd-1.5.5-1.el7.x86_64.rpm
重新安装成功
[root@postgre opt]# yum localinstall percona-xtrabackup-80-8.0.35-31.1.el7.x86_64.rpm
Loaded plugins: langpacks, product-id, search-disabled-repos, subscription-manager
This system is not registered with an entitlement server. You can use subscription-manager to register.
Examining percona-xtrabackup-80-8.0.35-31.1.el7.x86_64.rpm: percona-xtrabackup-80-8.0.35-31.1.el7.x86_64
Marking percona-xtrabackup-80-8.0.35-31.1.el7.x86_64.rpm to be installed
Resolving Dependencies
--> Running transaction check
---> Package percona-xtrabackup-80.x86_64 0:8.0.35-31.1.el7 will be installed
--> Processing Dependency: perl(DBD::mysql) for package: percona-xtrabackup-80-8.0.35-31.1.el7.x86_64
--> Processing Dependency: perl(Digest::MD5) for package: percona-xtrabackup-80-8.0.35-31.1.el7.x86_64
--> Running transaction check
---> Package perl-DBD-MySQL.x86_64 0:4.023-6.el7 will be installed
---> Package perl-Digest-MD5.x86_64 0:2.52-3.el7 will be installed
--> Processing Dependency: perl(Digest::base) >= 1.00 for package: perl-Digest-MD5-2.52-3.el7.x86_64
--> Running transaction check
---> Package perl-Digest.noarch 0:1.17-245.el7 will be installed
--> Finished Dependency ResolutionDependencies Resolved==========================================================================================================================================================================================Package Arch Version Repository Size
==========================================================================================================================================================================================
Installing:percona-xtrabackup-80 x86_64 8.0.35-31.1.el7 /percona-xtrabackup-80-8.0.35-31.1.el7.x86_64 219 M
Installing for dependencies:perl-DBD-MySQL x86_64 4.023-6.el7 base 140 kperl-Digest noarch 1.17-245.el7 base 23 kperl-Digest-MD5 x86_64 2.52-3.el7 base 30 kTransaction Summary
==========================================================================================================================================================================================
Install 1 Package (+3 Dependent packages)Total size: 219 M
Total download size: 193 k
Installed size: 219 M
Is this ok [y/d/N]: y
Downloading packages:
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Total 464 kB/s | 193 kB 00:00:00
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
Warning: RPMDB altered outside of yum.Installing : perl-DBD-MySQL-4.023-6.el7.x86_64 1/4 Installing : perl-Digest-1.17-245.el7.noarch 2/4 Installing : perl-Digest-MD5-2.52-3.el7.x86_64 3/4 Installing : percona-xtrabackup-80-8.0.35-31.1.el7.x86_64 4/4
base/productid | 1.6 kB 00:00:00 Verifying : perl-Digest-1.17-245.el7.noarch 1/4 Verifying : perl-Digest-MD5-2.52-3.el7.x86_64 2/4 Verifying : percona-xtrabackup-80-8.0.35-31.1.el7.x86_64 3/4 Verifying : perl-DBD-MySQL-4.023-6.el7.x86_64 4/4 Installed:percona-xtrabackup-80.x86_64 0:8.0.35-31.1.el7 Dependency Installed:perl-DBD-MySQL.x86_64 0:4.023-6.el7 perl-Digest.noarch 0:1.17-245.el7 perl-Digest-MD5.x86_64 0:2.52-3.el7 Complete!
xtrabackup version 8.0.35-31 based on MySQL server 8.0.35 Linux (x86_64) (revision id: 55ec21d7)
GTIDs
搭建复制最基础的参数:
| gtid_mode | ON |
| binlog_format | ROW |
那么GTID是什么东西哪?为什么在复制环境中这么重要?
他其实就是一串数字,给每个事务做个唯一标识,一般表示为:server_uuid:transaction_id,如:8e14e45d-4ff1-11ef-9808-000c29e3c118:1-6 。其中UUID(即server_uuid) 存于文件:
[root@postgre data]# cat /data/mysql/mysql3306/data/auto.cnf
[auto]
server-uuid=f25d3a39-53a2-11ef-9508-000c29a318a4
是一个MySQL实例的唯一标识。TID代表了该实例上已经提交的事务数量,并且随着事务提交单调递增,所以GTID能够保证每个MySQL实例事务的执行(不会重复执行同一个事务,并且会补全没有执行的事务)。GTID在一组复制中,全局唯一。
GTID用来代替传统复制方法,不再使用MASTER_LOG_FILE+MASTER_LOG_POS开启复制。 而是使用MASTER_AUTO_POSTION=1的方式开始复制;从服务器连接到主服务器之后,把自己执行过的GTID (Executed_Gtid_Set: 即已经执行的事务编码)<SQL线程> 、获取到的GTID (Retrieved_Gtid_Set: 即从库已经接收到主库的事务编号) <IO线程>发给主服务器,主服务器把从服务器缺少的GTID及对应的transactions发过去补全即可。当主服务器挂掉的时候,找出同步最成功的那台从服务器,直接把它提升为主即可。如果硬要指定某一台不是最新的从服务器提升为主, 先change到同步最成功的那台从服务器, 等把GTID全部补全了,就可以把它提升为主了。
GTID是用区间来表示的事务:
第一个事务:8e14e45d-4ff1-11ef-9808-000c29e3c118:1
第二个事务:8e14e45d-4ff1-11ef-9808-000c29e3c118:1-2
第三个事务:8e14e45d-4ff1-11ef-9808-000c29e3c118:1-3
原则上来讲,主从结构的GTIDs是连续的,如果从库上的GTID是不连续,那么肯定就是丢数据了。
既然开启GTID较之前有很多的优势,那么在5.7值后,我们一般都建议开启GTID进行复制。
初始化从库
[root@postgre data]# xtrabackup --defaults-file=/data/mysql/mysql3306/my3306.cnf -S /tmp/mysql3306.sock -uroot -p --backup --target-dir=/data/backup/db3306_full
2024-08-06T13:54:21.177384+08:00 0 [Note] [MY-011825] [Xtrabackup] recognized server arguments: --server-id=3306 --datadir=/data/mysql/mysql3306/data --open_files_limit=65535 --log_bin=/data/mysql/mysql3306/data/mybinlog --innodb_buffer_pool_size=100M --innodb_data_file_path=ibdata1:12M:autoextend --innodb_flush_log_at_trx_commit=1 --innodb_log_buffer_size=32M --innodb_log_file_size=1G --innodb_log_files_in_group=3 --innodb_io_capacity=4000 --innodb_open_files=65535 --innodb_flush_method=O_DIRECT --innodb_adaptive_hash_index=0 --innodb_adaptive_hash_index=0
2024-08-06T13:54:21.177553+08:00 0 [Note] [MY-011825] [Xtrabackup] recognized client arguments: --port=3306 --socket=/tmp/mysql3306.sock --socket=/tmp/mysql3306.sock --user=root --password --backup=1 --target-dir=/data/backup/db3306_full
Enter password:
xtrabackup version 8.0.35-31 based on MySQL server 8.0.35 Linux (x86_64) (revision id: 55ec21d7)
240806 13:54:23 version_check Connecting to MySQL server with DSN 'dbi:mysql:;mysql_read_default_group=xtrabackup;port=3306;mysql_socket=/tmp/mysql3306.sock' as 'root' (using password: YES).
Failed to connect to MySQL server: DBI connect(';mysql_read_default_group=xtrabackup;port=3306;mysql_socket=/tmp/mysql3306.sock','root',...) failed: Authentication plugin 'caching_sha2_password' cannot be loaded: /usr/lib64/mysql/plugin/caching_sha2_password.so: cannot open shared object file: No such file or directory at - line 1535.
2024-08-06T13:54:23.640205+08:00 0 [Note] [MY-011825] [Xtrabackup] Connecting to MySQL server host: localhost, user: root, password: set, port: 3306, socket: /tmp/mysql3306.sock
2024-08-06T13:54:23.655405+08:00 0 [Note] [MY-011825] [Xtrabackup] Using server version 8.0.37
2024-08-06T13:54:23.681865+08:00 0 [Note] [MY-011825] [Xtrabackup] Executing LOCK INSTANCE FOR BACKUP ...
2024-08-06T13:54:23.682950+08:00 0 [Note] [MY-011825] [Xtrabackup] uses posix_fadvise().
2024-08-06T13:54:23.682988+08:00 0 [Note] [MY-011825] [Xtrabackup] cd to /data/mysql/mysql3306/data
2024-08-06T13:54:23.683006+08:00 0 [Note] [MY-011825] [Xtrabackup] open files limit requested 65535, set to 65535
........
performance_schema/keyring_componen_191.sdi to /data/backup/db3306_full/performance_schema/keyring_componen_191.sdi
2024-08-06T13:54:25.828058+08:00 0 [Note] [MY-011825] [Xtrabackup] Finished backing up non-InnoDB tables and files
2024-08-06T13:54:25.828098+08:00 0 [Note] [MY-011825] [Xtrabackup] Executing FLUSH NO_WRITE_TO_BINLOG BINARY LOGS
2024-08-06T13:54:25.884799+08:00 0 [Note] [MY-011825] [Xtrabackup] Selecting LSN and binary log position from p_s.log_status
2024-08-06T13:54:25.950500+08:00 0 [Note] [MY-011825] [Xtrabackup] Copying /data/mysql/mysql3306/data/mybinlog.000003 to /data/backup/db3306_full/mybinlog.000003 up to position 197
2024-08-06T13:54:25.950570+08:00 0 [Note] [MY-011825] [Xtrabackup] Done: Copying /data/mysql/mysql3306/data/mybinlog.000003 to /data/backup/db3306_full/mybinlog.000003
2024-08-06T13:54:25.951697+08:00 0 [Note] [MY-011825] [Xtrabackup] Writing /data/backup/db3306_full/mybinlog.index
2024-08-06T13:54:25.951768+08:00 0 [Note] [MY-011825] [Xtrabackup] Done: Writing file /data/backup/db3306_full/mybinlog.index
2024-08-06T13:54:25.960548+08:00 0 [Note] [MY-011825] [Xtrabackup] Writing /data/backup/db3306_full/xtrabackup_binlog_info
2024-08-06T13:54:25.960619+08:00 0 [Note] [MY-011825] [Xtrabackup] Done: Writing file /data/backup/db3306_full/xtrabackup_binlog_info
2024-08-06T13:54:25.961518+08:00 0 [Note] [MY-011825] [Xtrabackup] Executing FLUSH NO_WRITE_TO_BINLOG ENGINE LOGS...
2024-08-06T13:54:25.988881+08:00 0 [Note] [MY-011825] [Xtrabackup] The latest check point (for incremental): '20338027'
2024-08-06T13:54:25.988974+08:00 0 [Note] [MY-011825] [Xtrabackup] Stopping log copying thread at LSN 20338027
2024-08-06T13:54:25.991165+08:00 1 [Note] [MY-011825] [Xtrabackup] Starting to parse redo log at lsn = 20337695
2024-08-06T13:54:26.016990+08:00 0 [Note] [MY-011825] [Xtrabackup] Executing UNLOCK INSTANCE
2024-08-06T13:54:26.024865+08:00 0 [Note] [MY-011825] [Xtrabackup] All tables unlocked
2024-08-06T13:54:26.025041+08:00 0 [Note] [MY-011825] [Xtrabackup] Copying ib_buffer_pool to /data/backup/db3306_full/ib_buffer_pool
2024-08-06T13:54:26.025488+08:00 0 [Note] [MY-011825] [Xtrabackup] Done: Copying ib_buffer_pool to /data/backup/db3306_full/ib_buffer_pool
2024-08-06T13:54:26.026709+08:00 0 [Note] [MY-011825] [Xtrabackup] Backup created in directory '/data/backup/db3306_full/'
2024-08-06T13:54:26.026735+08:00 0 [Note] [MY-011825] [Xtrabackup] MySQL binlog position: filename 'mybinlog.000003', position '197', GTID of the last change 'f25d3a39-53a2-11ef-9508-000c29a318a4:1-4'
2024-08-06T13:54:26.036177+08:00 0 [Note] [MY-011825] [Xtrabackup] Writing /data/backup/db3306_full/backup-my.cnf
2024-08-06T13:54:26.036245+08:00 0 [Note] [MY-011825] [Xtrabackup] Done: Writing file /data/backup/db3306_full/backup-my.cnf
2024-08-06T13:54:26.078730+08:00 0 [Note] [MY-011825] [Xtrabackup] Writing /data/backup/db3306_full/xtrabackup_info
2024-08-06T13:54:26.078833+08:00 0 [Note] [MY-011825] [Xtrabackup] Done: Writing file /data/backup/db3306_full/xtrabackup_info
2024-08-06T13:54:27.088852+08:00 0 [Note] [MY-011825] [Xtrabackup] Transaction log of lsn (20338027) to (20338893) was copied.
2024-08-06T13:54:27.319018+08:00 0 [Note] [MY-011825] [Xtrabackup] completed OK!
[root@postgre data]#
还原
–prepare的过程,为了避免影响原备份文件,可以先把备份文件拷贝到其他路径,进行prepare。
[root@postgre ~]# xtrabackup --prepare --target-dir=/data/backup/db3306_full
2024-08-06T14:05:25.906594+08:00 0 [Note] [MY-011825] [Xtrabackup] recognized server arguments: --innodb_checksum_algorithm=crc32 --innodb_log_checksums=1 --innodb_data_file_path=ibdata1:12M:autoextend --innodb_log_file_size=1073741824 --innodb_page_size=16384 --innodb_undo_directory=./ --innodb_undo_tablespaces=2 --server-id=3306 --innodb_log_checksums=ON --innodb_redo_log_encrypt=0 --innodb_undo_log_encrypt=0
2024-08-06T14:05:25.906778+08:00 0 [Note] [MY-011825] [Xtrabackup] recognized client arguments: --prepare=1 --target-dir=/data/backup/db3306_full
xtrabackup version 8.0.35-31 based on MySQL server 8.0.35 Linux (x86_64) (revision id: 55ec21d7)
2024-08-06T14:05:25.906804+08:00 0 [Note] [MY-011825] [Xtrabackup] cd to /data/backup/db3306_full/
2024-08-06T14:05:25.906880+08:00 0 [Note] [MY-011825] [Xtrabackup] This target seems to be not prepared yet.
2024-08-06T14:05:25.920383+08:00 0 [Note] [MY-011825] [Xtrabackup] xtrabackup_logfile detected: size=8388608, start_lsn=(20338027)
2024-08-06T14:05:25.924383+08:00 0 [Note] [MY-011825] [Xtrabackup] using the following InnoDB configuration for recovery:
2024-08-06T14:05:25.924414+08:00 0 [Note] [MY-011825] [Xtrabackup] innodb_data_home_dir = .
2024-08-06T14:05:25.924420+08:00 0 [Note] [MY-011825] [Xtrabackup] innodb_data_file_path = ibdata1:12M:autoextend
2024-08-06T14:05:25.924482+08:00 0 [Note] [MY-011825] [Xtrabackup] innodb_log_group_home_dir = .
2024-08-06T14:05:25.924492+08:00 0 [Note] [MY-011825] [Xtrabackup] innodb_log_files_in_group = 1
2024-08-06T14:05:25.924503+08:00 0 [Note] [MY-011825] [Xtrabackup] innodb_log_file_size = 8388608
2024-08-06T14:05:25.924769+08:00 0 [Note] [MY-011825] [Xtrabackup] inititialize_service_handles suceeded
2024-08-06T14:05:25.925177+08:00 0 [Note] [MY-011825] [Xtrabackup] using the following InnoDB configuration for recovery:
2024-08-06T14:05:25.925192+08:00 0 [Note] [MY-011825] [Xtrabackup] innodb_data_home_dir = .
2024-08-06T14:05:25.925198+08:00 0 [Note] [MY-011825] [Xtrabackup] innodb_data_file_path = ibdata1:12M:autoextend
2024-08-06T14:05:25.925209+08:00 0 [Note] [MY-011825] [Xtrabackup] innodb_log_group_home_dir = .
2024-08-06T14:05:25.925215+08:00 0 [Note] [MY-011825] [Xtrabackup] innodb_log_files_in_group = 1
2024-08-06T14:05:25.925220+08:00 0 [Note] [MY-011825] [Xtrabackup] innodb_log_file_size = 8388608
2024-08-06T14:05:25.925229+08:00 0 [Note] [MY-011825] [Xtrabackup] Starting InnoDB instance for recovery.
2024-08-06T14:05:25.925235+08:00 0 [Note] [MY-011825] [Xtrabackup] Using 104857600 bytes for buffer pool (set by --use-memory parameter)
2024-08-06T14:05:25.925265+08:00 0 [Note] [MY-012932] [InnoDB] PUNCH HOLE support available
2024-08-06T14:05:25.925280+08:00 0 [Note] [MY-012944] [InnoDB] Uses event mutexes
2024-08-06T14:05:25.925286+08:00 0 [Note] [MY-012945] [InnoDB] GCC builtin __atomic_thread_fence() is used for memory barrier
2024-08-06T14:05:25.925296+08:00 0 [Note] [MY-012948] [InnoDB] Compressed tables use zlib 1.2.13
2024-08-06T14:05:25.925464+08:00 0 [Note] [MY-012951] [InnoDB] Using hardware accelerated crc32 and polynomial multiplication.
2024-08-06T14:05:25.925838+08:00 0 [Note] [MY-012203] [InnoDB] Directories to scan './'
2024-08-06T14:05:25.925873+08:00 0 [Note] [MY-012204] [InnoDB] Scanning './'
2024-08-06T14:05:25.928700+08:00 0 [Note] [MY-012208] [InnoDB] Completed space ID check of 5 files.
2024-08-06T14:05:25.929854+08:00 0 [Note] [MY-012955] [InnoDB] Initializing buffer pool, total size = 128.000000M, instances = 1, chunk size =128.000000M
2024-08-06T14:05:25.936379+08:00 0 [Note] [MY-012957] [InnoDB] Completed initialization of buffer pool
2024-08-06T14:05:26.059786+08:00 0 [Note] [MY-011951] [InnoDB] page_cleaner coordinator priority: -20
2024-08-06T14:05:26.121777+08:00 0 [Note] [MY-011954] [InnoDB] page_cleaner worker priority: -20
2024-08-06T14:05:26.156695+08:00 0 [Note] [MY-011954] [InnoDB] page_cleaner worker priority: -20
2024-08-06T14:05:26.187928+08:00 0 [Note] [MY-011954] [InnoDB] page_cleaner worker priority: -20
2024-08-06T14:05:26.279548+08:00 0 [Note] [MY-013883] [InnoDB] The latest found checkpoint is at lsn = 20338027 in redo log file ./#innodb_redo/#ib_redo0.
2024-08-06T14:05:26.280684+08:00 0 [Note] [MY-012560] [InnoDB] The log sequence number 19876654 in the system tablespace does not match the log sequence number 20338027 in the redo log files!
2024-08-06T14:05:26.280706+08:00 0 [Note] [MY-012551] [InnoDB] Database was not shutdown normally!
2024-08-06T14:05:26.280716+08:00 0 [Note] [MY-012552] [InnoDB] Starting crash recovery.
2024-08-06T14:05:26.291356+08:00 0 [Note] [MY-013086] [InnoDB] Starting to parse redo log at lsn = 20337695, whereas checkpoint_lsn = 20338027 and start_lsn = 20337664
2024-08-06T14:05:26.291382+08:00 0 [Note] [MY-012550] [InnoDB] Doing recovery: scanned up to log sequence number 20338027
2024-08-06T14:05:26.308762+08:00 0 [Note] [MY-013083] [InnoDB] Log background threads are being started...
2024-08-06T14:05:26.565440+08:00 0 [Note] [MY-012532] [InnoDB] Applying a batch of 0 redo log records ...
2024-08-06T14:05:26.565476+08:00 0 [Note] [MY-012535] [InnoDB] Apply batch completed!
2024-08-06T14:05:26.666404+08:00 0 [Note] [MY-013084] [InnoDB] Log background threads are being closed...
2024-08-06T14:05:26.673366+08:00 0 [Note] [MY-013888] [InnoDB] Upgrading redo log: 1032M, LSN=20338027.
2024-08-06T14:05:26.673404+08:00 0 [Note] [MY-012968] [InnoDB] Starting to delete and rewrite redo log files.
2024-08-06T14:05:26.673476+08:00 0 [Note] [MY-011825] [InnoDB] Removing redo log file: ./#innodb_redo/#ib_redo0
2024-08-06T14:05:26.738599+08:00 0 [Note] [MY-011825] [InnoDB] Creating redo log file at ./#innodb_redo/#ib_redo0_tmp with file_id 0 with size 33554432 bytes
2024-08-06T14:05:26.738808+08:00 0 [Note] [MY-013623] [InnoDB] fallocate() failed with errno 95 - falling back to writing NULLs.
2024-08-06T14:05:26.802147+08:00 0 [Note] [MY-011825] [InnoDB] Renaming redo log file from ./#innodb_redo/#ib_redo0_tmp to ./#innodb_redo/#ib_redo0
2024-08-06T14:05:26.808247+08:00 0 [Note] [MY-012893] [InnoDB] New redo log files created, LSN=20338188
2024-08-06T14:05:26.808323+08:00 0 [Note] [MY-013083] [InnoDB] Log background threads are being started...
2024-08-06T14:05:27.065327+08:00 0 [Note] [MY-013252] [InnoDB] Using undo tablespace './undo_001'.
2024-08-06T14:05:27.066124+08:00 0 [Note] [MY-013252] [InnoDB] Using undo tablespace './undo_002'.
2024-08-06T14:05:27.067420+08:00 0 [Note] [MY-012910] [InnoDB] Opened 2 existing undo tablespaces.
2024-08-06T14:05:27.067537+08:00 0 [Note] [MY-011980] [InnoDB] GTID recovery trx_no: 1567
2024-08-06T14:05:27.113147+08:00 0 [Note] [MY-013777] [InnoDB] Time taken to initialize rseg using 1 thread: 38436 ms.
2024-08-06T14:05:27.116099+08:00 0 [Note] [MY-012923] [InnoDB] Creating shared tablespace for temporary tables
2024-08-06T14:05:27.116255+08:00 0 [Note] [MY-012265] [InnoDB] Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2024-08-06T14:05:27.135449+08:00 0 [Note] [MY-012266] [InnoDB] File './ibtmp1' size is now 12 MB.
2024-08-06T14:05:27.135653+08:00 0 [Note] [MY-013627] [InnoDB] Scanning temp tablespace dir:'./#innodb_temp/'
2024-08-06T14:05:27.148888+08:00 0 [Note] [MY-013018] [InnoDB] Created 128 and tracked 128 new rollback segment(s) in the temporary tablespace. 128 are now active.
2024-08-06T14:05:27.180331+08:00 0 [Note] [MY-012976] [InnoDB] 8.0.35 started; log sequence number 20338198
2024-08-06T14:05:27.180953+08:00 0 [Warning] [MY-012091] [InnoDB] Allocated tablespace ID 1 for sys/sys_config, old maximum was 0
2024-08-06T14:05:27.181888+08:00 0 [Note] [MY-011825] [Xtrabackup] Completed loading of 3 tablespaces into cache in 0.00126516 seconds
2024-08-06T14:05:27.205447+08:00 0 [Note] [MY-011825] [Xtrabackup] Time taken to build dictionary: 0.0235197 seconds
2024-08-06T14:05:27.249975+08:00 0 [Note] [MY-011825] [Xtrabackup] starting shutdown with innodb_fast_shutdown = 1
2024-08-06T14:05:27.250190+08:00 0 [Note] [MY-012330] [InnoDB] FTS optimize thread exiting.
2024-08-06T14:05:28.227326+08:00 0 [Note] [MY-013072] [InnoDB] Starting shutdown...
2024-08-06T14:05:28.332511+08:00 0 [Note] [MY-013084] [InnoDB] Log background threads are being closed...
2024-08-06T14:05:28.349406+08:00 0 [Note] [MY-012980] [InnoDB] Shutdown completed; log sequence number 20338198
2024-08-06T14:05:28.356359+08:00 0 [Note] [MY-011825] [Xtrabackup] completed OK!
–copy-back,此处是把文件从备份处拷贝到datadir下,所以指定了3308的配置文件,里面有datadir具体的路径。
[root@postgre db3306_full]# xtrabackup --defaults-file=/data/mysql/mysql3308/my3308.cnf --copy-back --target-dir=/data/backup/db3306_full/
2024-08-06T14:10:35.140533+08:00 0 [Note] [MY-011825] [Xtrabackup] recognized server arguments: --server-id=3308 --datadir=/data/mysql/mysql3308/data --open_files_limit=65535 --log_bin=/data/mysql/mysql3308/data/mybinlog --innodb_buffer_pool_size=100M --innodb_data_file_path=ibdata1:12M:autoextend --innodb_flush_log_at_trx_commit=1 --innodb_log_buffer_size=32M --innodb_log_file_size=1G --innodb_log_files_in_group=3 --innodb_io_capacity=4000 --innodb_open_files=65535 --innodb_flush_method=O_DIRECT --innodb_adaptive_hash_index=0 --innodb_adaptive_hash_index=0
2024-08-06T14:10:35.140688+08:00 0 [Note] [MY-011825] [Xtrabackup] recognized client arguments: --port=3308 --socket=/tmp/mysql3308.sock --copy-back=1 --target-dir=/data/backup/db3306_full/
xtrabackup version 8.0.35-31 based on MySQL server 8.0.35 Linux (x86_64) (revision id: 55ec21d7)
2024-08-06T14:10:35.140711+08:00 0 [Note] [MY-011825] [Xtrabackup] cd to /data/backup/db3306_full/
2024-08-06T14:10:35.141507+08:00 0 [Note] [MY-011825] [Xtrabackup] Copying undo_001 to /data/mysql/mysql3308/data/undo_001
2024-08-06T14:10:35.200687+08:00 0 [Note] [MY-011825] [Xtrabackup] Done: Copying undo_001 to /data/mysql/mysql3308/data/undo_001
2024-08-06T14:10:35.209907+08:00 0 [Note] [MY-011825] [Xtrabackup] Copying undo_002 to /data/mysql/mysql3308/data/undo_002
2024-08-06T14:10:35.243725+08:00 0 [Note] [MY-011825] [Xtrabackup] Done: Copying undo_002 to /data/mysql/mysql3308/data/undo_002
2024-08-06T14:10:35.260550+08:00 0 [Note] [MY-011825] [Xtrabackup] Copying ibdata1 to /data/mysql/mysql3308/data/ibdata1
......
2024-08-06T14:10:35.557160+08:00 1 [Note] [MY-011825] [Xtrabackup] Copying ./xtrabackup_info to /data/mysql/mysql3308/data/xtrabackup_info
2024-08-06T14:10:35.557220+08:00 1 [Note] [MY-011825] [Xtrabackup] Done: Copying ./xtrabackup_info to /data/mysql/mysql3308/data/xtrabackup_info
2024-08-06T14:10:35.557845+08:00 1 [Note] [MY-011825] [Xtrabackup] Creating directory ./#innodb_redo
2024-08-06T14:10:35.557876+08:00 1 [Note] [MY-011825] [Xtrabackup] Done: creating directory ./#innodb_redo
2024-08-06T14:10:35.557954+08:00 1 [Note] [MY-011825] [Xtrabackup] Copying ./ibtmp1 to /data/mysql/mysql3308/data/ibtmp1
2024-08-06T14:10:35.595855+08:00 1 [Note] [MY-011825] [Xtrabackup] Done: Copying ./ibtmp1 to /data/mysql/mysql3308/data/ibtmp1
2024-08-06T14:10:35.618690+08:00 0 [Note] [MY-011825] [Xtrabackup] completed OK!
启动
/usr/local/mysql/bin/mysqld --defaults-file=/data/mysql/mysql3308/my3308.cnf &[root@postgre data]# /usr/local/mysql/bin/mysql -uroot -p -S /tmp/mysql3308.sock
Enter password:
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
Server version: 8.0.37 MySQL Community Server - GPLCopyright (c) 2000, 2024, 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.mysql> show master status;
+-----------------+----------+--------------+------------------+------------------------------------------+
| File | Position | Binlog_Do_DB | Binlog_Ignore_DB | Executed_Gtid_Set |
+-----------------+----------+--------------+------------------+------------------------------------------+
| mybinlog.000004 | 197 | | | f25d3a39-53a2-11ef-9508-000c29a318a4:1-4 |
+-----------------+----------+--------------+------------------+------------------------------------------+
1 row in set (0.00 sec)
xtrabackup还原后,可以看到从库的GTID信息已经有了,而且是和主库一致的,那么此时我们就可以直接change
mysql> change master to master_host='10.1.11.30', master_port=3306, master_user='repl', master_password='repl',master_auto_position=1;
Query OK, 0 rows affected, 8 warnings (0.03 sec)
mysql> start slave;
Query OK, 0 rows affected, 1 warning (0.37 sec)mysql> show slave status\G
*************************** 1. row ***************************Slave_IO_State: Connecting to sourceMaster_Host: 10.1.11.30Master_User: replMaster_Port: 3306Connect_Retry: 60Master_Log_File: Read_Master_Log_Pos: 4Relay_Log_File: postgre-relay-bin.000001Relay_Log_Pos: 4Relay_Master_Log_File: Slave_IO_Running: ConnectingSlave_SQL_Running: YesReplicate_Do_DB: Replicate_Ignore_DB: Replicate_Do_Table: Replicate_Ignore_Table: Replicate_Wild_Do_Table: Replicate_Wild_Ignore_Table: Last_Errno: 0Last_Error: Skip_Counter: 0Exec_Master_Log_Pos: 0Relay_Log_Space: 157Until_Condition: NoneUntil_Log_File: Until_Log_Pos: 0Master_SSL_Allowed: NoMaster_SSL_CA_File: Master_SSL_CA_Path: Master_SSL_Cert: Master_SSL_Cipher: Master_SSL_Key: Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: NoLast_IO_Errno: 2061Last_IO_Error: Error connecting to source 'repl@10.1.11.30:3306'. This was attempt 1/86400, with a delay of 60 seconds between attempts. Message: Authentication plugin 'caching_sha2_password' reported error: Authentication requires secure connection.Last_SQL_Errno: 0Last_SQL_Error: Replicate_Ignore_Server_Ids: Master_Server_Id: 0Master_UUID: Master_Info_File: mysql.slave_master_infoSQL_Delay: 0SQL_Remaining_Delay: NULLSlave_SQL_Running_State: Replica has read all relay log; waiting for more updatesMaster_Retry_Count: 86400Master_Bind: Last_IO_Error_Timestamp: 240806 14:22:03Last_SQL_Error_Timestamp: Master_SSL_Crl: Master_SSL_Crlpath: Retrieved_Gtid_Set: Executed_Gtid_Set: f25d3a39-53a2-11ef-9508-000c29a318a4:1-4Auto_Position: 1Replicate_Rewrite_DB: Channel_Name: Master_TLS_Version: Master_public_key_path: Get_master_public_key: 0Network_Namespace:
1 row in set, 1 warning (0.35 sec)mysql> show slave status\G
*************************** 1. row ***************************
......Slave_IO_Running: ConnectingSlave_SQL_Running: Yes
.....Last_IO_Error: Error connecting to source 'repl@10.1.11.30:3306'. This was attempt 1/86400, with a delay of 60 seconds between attempts. Message: Authentication plugin 'caching_sha2_password' reported error: Authentication requires secure connection.
......Retrieved_Gtid_Set: Executed_Gtid_Set: f25d3a39-53a2-11ef-9508-000c29a318a4:1-4
.....
1 row in set, 1 warning (0.07 sec)
直接start slave,会报错。这是MySQL 8.0新的密码机制决定的,我们手动登录一次即可或者change加参数GET_MASTER_PUBLIC_KEY=1或者改为原始的认证方式mysql_native_passwor ,三者选其一即可。
我们采用第二种:
mysql> stop slave;
Query OK, 0 rows affected, 1 warning (0.07 sec)mysql> change master to Get_master_public_key=1;
Query OK, 0 rows affected, 2 warnings (0.01 sec)mysql> start slave;
Query OK, 0 rows affected, 1 warning (0.12 sec)
恢复正常:
mysql> show slave status\G
*************************** 1. row ***************************Slave_IO_State: Waiting for source to send eventMaster_Host: 10.1.11.30Master_User: replMaster_Port: 3306Connect_Retry: 60Master_Log_File: mybinlog.000004Read_Master_Log_Pos: 737Relay_Log_File: postgre-relay-bin.000002Relay_Log_Pos: 911Relay_Master_Log_File: mybinlog.000004Slave_IO_Running: YesSlave_SQL_Running: Yes
.......Retrieved_Gtid_Set: f25d3a39-53a2-11ef-9508-000c29a318a4:5-6Executed_Gtid_Set: f25d3a39-53a2-11ef-9508-000c29a318a4:1-6Auto_Position: 1
......Get_master_public_key: 1
还有一点,在上面start slave之前,状态是这样的:

Executed_Gtid_Set:表示从库已经执行了的GTID,就跟前面一致,现在从库的GTID已经执行到4 seq#,,如果此时主库的GTID执行比4大,那么Retrieved_Gtid_Set就会显示新的值,比4大的,从库缺少的从4以来的记录。
参考:
MySQL主从复制之GTID模式介绍
GTID概述
MySQL5.6 在原有主从复制的基础上增加了一个新的复制方式,即基于GTID的复制方式,它由UUID和事务ID两个部分组成,具有如下特点。
GTID事务是全局唯一性的,并且一个事务对应一个GTID值。
一个GTID值在同一个MySQL实例上只会执行一次。
GTID相较与传统复制的优势
主从搭建更加简便,不用手动特地指定position位置。
复制集群内有一个统一的标识,识别、管理上更方便。
故障转移更容易,不用像传统复制那样需要找 log_file 和 log_Pos的位置。
通常情况下GTID是连续没有空洞的,更能保证数据的一致性,零丢失。
相对于ROW复制模式,数据安全性更高,切换更简单。
比传统的复制更加安全,一个GTID在一个MySQL实例上只会执行一次,避免重复执行导致数据混乱或者主从不一致。
GTID自身存在哪些限制
在一个复制组中,必须都要开启GTID。
MySQL5.6开启GTID需要重启。
不支持sql_slave_skip_counte操作,传统复制可以使用这个命令跳过事务。
不允许在一个SQL同时更新一个事务引擎和非事务引擎的表,如InnoDB和MyISAM。
对于create temporary table 和drop temporary table语句不支持。
不支持create table … select 语句复制。
GTID工作原理简单介绍
master节点在更新数据的时候,会在事务前产生GTID信息,一同记录到binlog日志中。
slave节点的io线程将binlog写入到本地relay log中。
然后SQL线程从relay log中读取GTID,设置gtid_next的值为该gtid,然后对比slave端的binlog是否有记录。
如果有记录的话,说明该GTID的事务已经运行,slave会忽略。
如果没有记录的话,slave就会执行该GTID对应的事务,并记录到binlog中。
如何开启GTID复制
除传统复制需要开启的binlog相关参数之外,GTID同步需额外开启如下参数设置,注意主从节点需要同步开启。

查看GTID相关参数

参数简要说明

GTID与传统模式建立复制时候语句的不同点
传统复制
change master to master_host=“127.0.0.1”,master_port=3310,MASTER_USER=‘sync’,MASTER_PASSWORD=‘GreatSQL’,MASTER_LOG_FILE=‘log-bin.000005’, MASTER_LOG_POS=4111;
GTID复制
change master to master_host=“127.0.0.1”,master_port=3310,MASTER_USER=‘sync’,MASTER_PASSWORD=‘GreatSQL’,MASTER_AUTO_POSITION=1
GTID同步在建立复制的时候,将传统复制由人为指定binlog的pos位点改为了MASTER_AUTO_POSITION=1自动获取binlog的pos位点。
GTID同步状态简单解析
除了传统的查看binlog和pos值之外,GTID模式可以更直观的查看某个事务执行的情况。
[root@GreatSQL][(none)]>show slave status\G;
*************************** 1. row ***************************
Slave_IO_State: Waiting for master to send event
Master_Host: 192.168.6.215
Master_User: sync
Master_Port: 3306
Connect_Retry: 60
Master_Log_File: binlog.000001
Read_Master_Log_Pos: 2425
Relay_Log_File: mgr2-relay-bin.000002
Relay_Log_Pos: 2634
Relay_Master_Log_File: binlog.000001
Slave_IO_Running: Yes
Slave_SQL_Running: Yes
Replicate_Do_DB:
Replicate_Ignore_DB:
Replicate_Do_Table:
Replicate_Ignore_Table:
Replicate_Wild_Do_Table:
Replicate_Wild_Ignore_Table:
Last_Errno: 0
Last_Error:
Skip_Counter: 0
Exec_Master_Log_Pos: 2425
Relay_Log_Space: 2842
Until_Condition: None
Until_Log_File:
Until_Log_Pos: 0
Master_SSL_Allowed: No
Master_SSL_CA_File:
Master_SSL_CA_Path:
Master_SSL_Cert:
Master_SSL_Cipher:
Master_SSL_Key:
Seconds_Behind_Master: 0
Master_SSL_Verify_Server_Cert: No
Last_IO_Errno: 0
Last_IO_Error:
Last_SQL_Errno: 0
Last_SQL_Error:
Replicate_Ignore_Server_Ids:
Master_Server_Id: 2153306
Master_UUID: 613743f5-8b1c-11ec-9922-00155dcff911
Master_Info_File: mysql.slave_master_info
SQL_Delay: 0
SQL_Remaining_Delay: NULL
Slave_SQL_Running_State: Slave has read all relay log; waiting for more updates
Master_Retry_Count: 86400
Master_Bind:
Last_IO_Error_Timestamp:
Last_SQL_Error_Timestamp:
Master_SSL_Crl:
Master_SSL_Crlpath:
Retrieved_Gtid_Set: 613743f5-8b1c-11ec-9922-00155dcff911:1-10
Executed_Gtid_Set: 613743f5-8b1c-11ec-9922-00155dcff911:1-10,
652ade08-8b1c-11ec-9f62-00155dcff90a:1-2
Auto_Position: 1
Replicate_Rewrite_DB:
Channel_Name:
Master_TLS_Version:
Master_public_key_path:
Get_master_public_key: 0
Network_Namespace:
1 row in set, 1 warning (0.01 sec)
ERROR:
No query specified
GTID相关键参数说明

整个过程如下:
groupadd mysql
useradd -g mysql -s /sbin/nologin -d /usr/local/mysql -MN mysql
cd /opt
unxz mysql-8.0.37-linux-glibc2.17-x86_64.tar.xz
tar -xvf mysql-8.0.37-linux-glibc2.17-x86_64.tar
cd /usr/local
ln -s /opt/mysql-8.0.37-linux-glibc2.17-x86_64 mysql
chown -R mysql:mysql /usr/local/mysql/
mkdir -p /data/mysql/mysql3306/{data,logs,tmp}
mv /opt/my.cnf /data/mysql/mysql3306/my3306.cnf
chown -R mysql:mysql /usr/local/mysql/
chown -R mysql:mysql /data/mysql/mysql3306//usr/local/mysql/bin/mysqld --defaults-file=/data/mysql/mysql3306/my3306.cnf --initialize
/usr/local/mysql/bin/mysqld --defaults-file=/data/mysql/mysql3306/my3306.cnf &/usr/local/mysql/bin/mysql -uroot -p -S /tmp/mysql3306.sock
alter user user() identified by 'mysql';
show databases;
create database test;
use test;
create table test(id int,name char);
insert into test values(1,'a');
create user repl@'%' identified by 'repl';
grant replication slave on *.* to repl@'%';cd /data/
mkdir -p backup/db3306_full/
xtrabackup --defaults-file=/data/mysql/mysql3306/my3306.cnf -S /tmp/mysql3306.sock -uroot -p --backup --target-dir=/data/backup/db3306_full
xtrabackup --prepare --target-dir=/data/backup/db3306_full
mkdir -p /data/mysql/mysql3308/{data,logs,tmp}
cp /data/mysql/mysql3306/my3306.cnf /data/mysql/mysql3308/my3308.cnf
sed -i 's/3306/3308/g' /data/mysql/mysql3308/my3308.cnf
xtrabackup --defaults-file=/data/mysql/mysql3308/my3308.cnf --copy-back --target-dir=/data/backup/db3306_full/
chown -R mysql:mysql /data/mysql/mysql3308//usr/local/mysql/bin/mysqld --defaults-file=/data/mysql/mysql3308/my3308.cnf &
/usr/local/mysql/bin/mysql -uroot -p -S /tmp/mysql3308.sock
/usr/local/mysql/bin/mysql -h 10.1.11.30 -P3306 -urepl -prepl
change master to master_host='10.1.11.30', master_port=3306, master_user='repl', master_password='repl',master_auto_position=1;
start slave;
show slave status\G或者不用登录一次,直接加参数解决:
change master to master_host='10.1.11.30', master_port=3306, master_user='repl', master_password='repl',master_auto_position=1 GET_MASTER_PUBLIC_KEY=1;
相关文章:
xtrabackup搭建MySQL 8.0 主从复制
xtrabackup搭建MySQL 8.0 主从复制 安装MySQL 8.0.37安装xtrabackupGTIDs初始化从库参考:GTID概述GTID相较与传统复制的优势GTID自身存在哪些限制GTID工作原理简单介绍如何开启GTID复制GTID与传统模式建立复制时候语句的不同点传统复制GTID复制 GTID同步状态简单解析…...
Java程序员接单分享
作为一名Java程序员,这阵子通过承接些小型项目,我顺利跨过了月薪破万的门槛。这些项目虽小,却如同磨刀石般,让我在实战中发现了自身技术栈的棱角与不足,尤其是意识到了在Java这一浩瀚技术海洋中的诸多未知领域。我深知…...
【HarmonyOS NEXT星河版开发学习】小型测试案例01-今日头条置顶练习
个人主页→VON 收录专栏→鸿蒙开发小型案例总结 基础语法部分会发布于github 和 gitee上面 前言 本系列可能是博客首发,鸿蒙开发星河版是一个全新的版本,由于参考视频较少鸿蒙开发不被重视导致csdn上面并没有全套的学习路线,…...
C语言----计算开机时间
计算开机时间 实例说明 编程实现计算开机时间,要求在每次开始计算开机时间时都能接着上次记录的结果向下记录。 实现过程: 1. 在TC中创建一个C文件。 2. 引用头文件,代码如下: #include <stdio.h> 3. 定义结构体time,用来…...
批发行业进销存-登录适配 android 横竖屏幕 源码CyberWinApp-SAAS 本地化及未来之窗行业应用跨平台架构
一、横竖屏切换的意义 以下是移动端横屏竖屏可切换在进销存中的一些重要应用: a、数据录入与查看 在录入商品信息、库存数量等大量数据时,横屏模式可以提供更宽阔的输入区域,减少输入错误。例如,在输入长串的商品编码或详细的商…...
js功能(1)
1、readonly 应用于元素:readonly 可以应用于 <input> 和 <textarea> 元素。 用户界面表现:当元素设置为 readonly 时,用户不能更改输入框中的值,但可以选中和复制文本,且表单包含该输入字段的值可以被提交…...
微信小程序乡村医疗系统,源码、部署+讲解
目录 摘 要 Abstract 1 绪论 1.1 研究背景及意义 1.2 研究现状 1.3 研究内容 2 相关技术介绍 2.1 Java 语言 2.2 MySQL 数据库 2.3 Spring Boot 框架 2.4 B/S 结构 2.5 微信小程序 3 系统分析 3.1 可行性分析 3.1.1 经济可行性 3.1.2 技术可行性…...
完美解决pip命令版本冲突导致对应版本模块包无法安装的问题
解决步骤 使用pip更新/降低指定模块包命令格式降低pip自身至指定版本的命令再次换源安装指定模块包 在对 FasterNet 这篇论文源码复现过程中,我们首先需要安装相关依赖文件( path/to/your/requirements.txt) -extra-index-url https://down…...
5.1-软件工程基础知识-软件工程概述
软件工程诞生原因 了解 早期的软件:主要是指采用个体工作方式实现的程序。第一次软件危机:20世纪60年代中期 典型表现有软件质量低下、项目无法如期完成、项目严重超支等因为软件而导致的重大事故时有发生。 软件工程的诞生:1968年在NATO会…...
极简聊天室-websocket版
再写一个极简聊天室的websocket版,在本例中,websocket仅用于服务器向客户端传输信息,客户端向服务器发送信息是传统的http post方式,用axios来实现的,当然websocket本身是支持双向通信,主要是为了方便跟前面…...
QT学生管理系统 开发文档
目录 第一章 UI界面设计与开发 登录界面 主界面 UI美化 第二章 数据库设计与开发 数据库设计 连接数据库 数据库功能设计 sql语句设计 查询所有学生数量 查询第几页学生数据 删除学生 修改学生信息 清空学生表 添加单个用户 删除单个用户 修改用户权限 查询所有用户…...
【五大海内外高校支持】2024年数字经济与计算机科学国际学术会议(DECS2024)
大会官网:www.icdecs.net 大会时间:2024年9月20-22日 大会地点:中国-厦门 截稿日期:详情见官网 支持单位 马来西亚理工大学 北京科技大学经济管理学院 南京信息工程大学 马来西亚敦胡先翁大学 大会嘉宾 大会主席 罗航…...
VS项目打包成lib库并使用
一、新建一个静态库项目 一般要把项目设为Release模式 二、添加文件 将所需要打包的头文件、源文件添加到该静态库项目中 三、生成项目 生成成功后即可在Release文件夹出现找到相应的.lib文件 四、使用静态库 将静态库文件复制到项目文件夹中,然后在项目属性设…...
社交巨头与去中心化:解析Facebook在区块链的角色
区块链技术的兴起为多个行业带来了变革,而社交平台也正在经历这一波技术浪潮。作为全球最大的社交网络之一,Facebook(现名Meta Platforms)在区块链领域的探索展示了其如何应对去中心化趋势的挑战,并利用这一技术推动自…...
MyBatis(学习记录)
一、ORM ORM是“对象关系映射”(Object-Relational Mapping)的缩写。这是一种编程技术,用于将对象模型与关系型数据库系统之间的数据进行转换。在面向对象的编程语言中,数据通常以对象的形式表示;而在关系型数据库中&a…...
QSpinbox
加载图片资源 在项目中,选择新建,QT->Qt Resource File -choose ,命名为 image ,创建完成了,会在目录下生成一个image.qrc。我们资源文件,要放在image.qrc 的同级目录或子目录中。 常用的小功能 在左下方&#x…...
分布式服务架构[原理、设计与实践]学习笔记
地震是由不可抗力导致的,而事故与之不同,任何大的生产事故在发生之前都有迹可循,而且事故的发生并不是偶然的,我们应该善于从现象中总结规律,找到发现、止损和避免的方法 海恩法则 每一起严重事故的背后,必…...
PDF发票解析并将信息回填到前端(1)后端解析PDF
文章目录 参考文章技术栈需求解析发票类型 1. 最终项目结构1.1 说明 2. 相关代码2.1 导入相应的maven依赖2.2 实体类2.3 工具类2.4 三层架构controllerservicemapper 参考文章 参考文章 技术栈 SpringBootVue 需求 本文主要是实现提取发票中的部分内容,并实现自…...
C++练习之插入删除
#include <iostream> #include <ctime> #include <cstring> #include<cstdlib> using namespace std;typedef struct bookInfo {char name[10];float price;int num; }BOOKINFO;// p: 结构体数组首元素地址 // n: 有效图书数量 void Print(const BOOKI…...
【LeetCode】238. 除自身以外数组的乘积
除自身以外数组的乘积 题目描述: 给你一个整数数组 nums,返回 数组 answer ,其中 answer[i] 等于 nums 中除 nums[i] 之外其余各元素的乘积 。 题目数据 保证 数组 nums之中任意元素的全部前缀元素和后缀的乘积都在 32 位 整数范围内。 请…...
conda相比python好处
Conda 作为 Python 的环境和包管理工具,相比原生 Python 生态(如 pip 虚拟环境)有许多独特优势,尤其在多项目管理、依赖处理和跨平台兼容性等方面表现更优。以下是 Conda 的核心好处: 一、一站式环境管理:…...
全球首个30米分辨率湿地数据集(2000—2022)
数据简介 今天我们分享的数据是全球30米分辨率湿地数据集,包含8种湿地亚类,该数据以0.5X0.5的瓦片存储,我们整理了所有属于中国的瓦片名称与其对应省份,方便大家研究使用。 该数据集作为全球首个30米分辨率、覆盖2000–2022年时间…...
Nginx server_name 配置说明
Nginx 是一个高性能的反向代理和负载均衡服务器,其核心配置之一是 server 块中的 server_name 指令。server_name 决定了 Nginx 如何根据客户端请求的 Host 头匹配对应的虚拟主机(Virtual Host)。 1. 简介 Nginx 使用 server_name 指令来确定…...
pikachu靶场通关笔记22-1 SQL注入05-1-insert注入(报错法)
目录 一、SQL注入 二、insert注入 三、报错型注入 四、updatexml函数 五、源码审计 六、insert渗透实战 1、渗透准备 2、获取数据库名database 3、获取表名table 4、获取列名column 5、获取字段 本系列为通过《pikachu靶场通关笔记》的SQL注入关卡(共10关࿰…...
安全突围:重塑内生安全体系:齐向东在2025年BCS大会的演讲
文章目录 前言第一部分:体系力量是突围之钥第一重困境是体系思想落地不畅。第二重困境是大小体系融合瓶颈。第三重困境是“小体系”运营梗阻。 第二部分:体系矛盾是突围之障一是数据孤岛的障碍。二是投入不足的障碍。三是新旧兼容难的障碍。 第三部分&am…...
适应性Java用于现代 API:REST、GraphQL 和事件驱动
在快速发展的软件开发领域,REST、GraphQL 和事件驱动架构等新的 API 标准对于构建可扩展、高效的系统至关重要。Java 在现代 API 方面以其在企业应用中的稳定性而闻名,不断适应这些现代范式的需求。随着不断发展的生态系统,Java 在现代 API 方…...
Ubuntu系统复制(U盘-电脑硬盘)
所需环境 电脑自带硬盘:1块 (1T) U盘1:Ubuntu系统引导盘(用于“U盘2”复制到“电脑自带硬盘”) U盘2:Ubuntu系统盘(1T,用于被复制) !!!建议“电脑…...
使用 uv 工具快速部署并管理 vLLM 推理环境
uv:现代 Python 项目管理的高效助手 uv:Rust 驱动的 Python 包管理新时代 在部署大语言模型(LLM)推理服务时,vLLM 是一个备受关注的方案,具备高吞吐、低延迟和对 OpenAI API 的良好兼容性。为了提高部署效…...
篇章一 论坛系统——前置知识
目录 1.软件开发 1.1 软件的生命周期 1.2 面向对象 1.3 CS、BS架构 1.CS架构编辑 2.BS架构 1.4 软件需求 1.需求分类 2.需求获取 1.5 需求分析 1. 工作内容 1.6 面向对象分析 1.OOA的任务 2.统一建模语言UML 3. 用例模型 3.1 用例图的元素 3.2 建立用例模型 …...
MySQL 数据库深度剖析:事务、SQL 优化、索引与 Buffer Pool
在当今数据驱动的时代,数据库作为数据存储与管理的核心,其性能与可靠性至关重要。MySQL 作为一款广泛使用的开源数据库,在众多应用场景中发挥着关键作用。在这篇博客中,我将围绕 MySQL 数据库的核心知识展开,涵盖事务及…...
