MySQL 8 InnoDB架构(Part2)

InnoDB In-Memory 架构

Buffer Pool

系统变量:innodb_buffer_pool_size

Change Buffer

表:information_schema.innodb_metrics 

表:information_schema.innodb_buffer_pages 

系统变量:innodb_change_buffering

系统变量:innodb_change_buffer_max_size

Adaptive Hash Index

系统变量:innodb_adaptive_hash_index

系统变量:innodb_adaptive_hash_index_parts 

Log Bugger

系统变量:innodb_log_buffer_size

系统变量:innodb_flush_log_at_timeout

系统变量:innodb_flush_log_at_trx_commit

InnoDB On-Disk 架构

Tables

InnoDB 表可以添加到file-per-table表空间、系统表空间、General 表空间。

内部:InnoDB为每张表添加一条entry到数据字典中。

系统变量:innodb_default_row_format

查看InnoDB表属性:

show table status from test like 't1'\G

select * from information_schema.innodb_tables where name='test/t1'\G

在数据目录外创建表

方法1、CREATE TABLE ... DATA DIRECTORY

注意:加入到innodb_directories,这样如果表需要恢复,MySQL知道表的数据文件在哪。

方法2、看起来像是多此一举:CREATE TABLE ... TABLESPACE=innodb_file_per_table DATA DIRECTORY '/exteranl/directory';

方法3、利用外部通用表空间,创建数据目录外的表,比如:

create tablespace ext_gen_tbs add datafile '/exteral/directory/tbs.ibd';

create table t5(col1 int) tablespace=ext_gen_tbs;

利用可传输表空间迁移数据

涉及SQL语句:

目标端:create table ...、alter table ... discard tablespace; alter table ... import tablespace;

源端:flush tables ... for export;

移动或者拷贝InnoDB表

可选方案:

传输表空间、MySQL企业备份(可以用Percona Xtrabackup 替代)、拷贝数据文件、逻辑备份(mysqldump工具)

关于冷备份:

假设服务器硬件出故障:拷贝文件也是可以恢复数据的:

InnoDB系统表空间、InnoDB 日志文件、 MySQL 数据字典、系统表文件、各种系统数据库、业务数据库。

InnoDB处理 Auto-Increment

系统变量:innodb_autoinc_lock_mode 这个系统变量在MySQL 5.7的时候默认值是:1。MySQL 8.0 默认值是2

现在复制更多是基于行的复制模式,innodb_autoinc_lock_mode=2,虽然在自增值上可能出现GAP,但是RBR模式下,主从节点数据一致性可以保证。只有SBR模式下才会考虑innodb_autoinc_lock_mode=1

注:innodb_autoinc_lock_mode=2模式下,table-level AUTO-INC lock不会在Insert-like 语句中添加,增加对表的并发写入。

索引

clustered index 和 secondary index

clustered index 生成方式:如果表中定义了主键,主键就是clustered index。如果表中没有定义主键,第一个unique index 作为clustered index。如果前两者都不满足,InnoDB使用包含行ID的列作为clustered index。这样表数据的排列顺序依赖 row id。而row id是根据行的插入顺序单调递增的。所以表数据排列顺序也是依赖表行的写入顺序。

猜你喜欢

转载自www.cnblogs.com/xinzhizhu/p/12359591.html