当前位置: 移动技术网 > IT编程>数据库>Mysql > 详解MySQL8.0​ 字典表增强

详解MySQL8.0​ 字典表增强

2020年08月19日  | 移动技术网IT编程  | 我要评论
mysql中数据字典是数据库重要的组成部分之一,information_schema首次引入于mysql 5.0,作为一种从正在运行的mysql服务器检索元数据的标准兼容方式。用于存储数据元数据、统计

mysql中数据字典是数据库重要的组成部分之一,information_schema首次引入于mysql 5.0,作为一种从正在运行的mysql服务器检索元数据的标准兼容方式。用于存储数据元数据、统计信息、以及有关mysql server的访问信息(例如:数据库名或表名,字段的数据类型和访问权限等)。

8.0之前:

1、元数据来自文件

2、采用memory表引擎

3、frm文件 存放表结构信息

4、opt文件,记录了每个库的一些基本信息,包括库的字符集等信息

5、.trn,.trg文件用于存放触发器的信息内容

5.6> select table_schema ,engine ,count(*) from information_schema.tables where table_schema in ('information_schema' ,'mysql','performance_schema', 'sys') group by table_schema ,engine;
+--------------------+--------------------+----------+
| table_schema    | engine       | count(*) |
+--------------------+--------------------+----------+
| information_schema | memory       |    49 |
| information_schema | myisam       |    10 |
| mysql       | csv        |    2 |
| mysql       | innodb       |    6 |
| mysql       | myisam       |    21 |
| performance_schema | performance_schema |    52 |
+--------------------+--------------------+----------+
5.7> select table_schema ,engine ,count(*) from information_schema.tables where table_schema in ('information_schema' ,'mysql','performance_schema', 'sys') group by table_schema ,engine;
+--------------------+--------------------+----------+
| table_schema    | engine       | count(*) |
+--------------------+--------------------+----------+
| information_schema | innodb       |    10 |
| information_schema | memory       |    51 |
| mysql       | csv        |    2 |
| mysql       | innodb       |    19 |
| mysql       | myisam       |    10 |
| performance_schema | performance_schema |    87 |
| sys        | null        |   100 |
| sys        | innodb       |    1 |
+--------------------+--------------------+----------+

8.0之后:

1、元数据存在表中

2、全部迁到mysql库下,改为innodb表引擎,且被隐藏

3、information_schema下只能通过view查看

4、null的全部为view

5、存储在单独的表空间mysql.ibd

8.0> select table_schema,engine,count(*) from tables where table_schema in ('information_schema','mysql','performance_schema','sys') group by table_schema,engine;
+--------------------+--------------------+----------+
| table_schema    | engine       | count(*) |
+--------------------+--------------------+----------+
| information_schema | null        |    65 |
| mysql       | innodb       |    31 |
| mysql       | csv        |    2 |
| performance_schema | performance_schema |   102 |
| sys        | null        |   100 |
| sys        | innodb       |    1 |
+--------------------+--------------------+----------+

尽管5.7有了一些改进,但information_schema的性能仍然是我们许多用户的主要痛点。在当前information_schema实现方式下产生的性能问题背后的关键原因是,information_schema表的查询实现方式是在查询执行期间创建临时表。

如下,当我们查询表碎片时:

5.7> explain select round(data_free/1024/1024) as data_free from information_schema.tables where data_free/1024/1024 > 1024 and table_schema not in ('information_schema', 'mysql', 'performance_schema', 'sys');
+----+-------------+--------+------+---------------+------+---------+------+------+-----------------------------------------------------+
| id | select_type | table | type | possible_keys | key | key_len | ref | rows | extra                        |
+----+-------------+--------+------+---------------+------+---------+------+------+-----------------------------------------------------+
| 1 | simple   | tables | all | null     | null | null  | null | null | using where; open_full_table; scanned all databases |
+----+-------------+--------+------+---------------+------+---------+------+------+-----------------------------------------------------+

extra信息会有open_full_table; scanned all databases 。
skip_open_table,open_frm_only,open_full_table这些值表示适用于information_schema表查询时对文件打开的优化;

  • skip_open_table:表文件不需要打开。信息已经通过扫描数据库目录在查询中实现可用。
  • open_frm_only:只需要打开表的.frm文件。
  • open_full_table:未优化的信息查找。必须打开.frm、.myd和.myi文件。
  • scanned n databases:指在处理information_schema查询时,有多少目录需要扫描。

如果一个mysql实例有上百个库,每个库又有上百张表,information_schema查询最终会从文件系统中读取每个单独的frm文件,造成很多i/o读取。并且最终还会消耗更多的cpu来打开表并准备相关的内存数据结构。它也确实会尝试使用mysql server层的表缓存(系统变量table_definition_cache ),但是在大型实例中,很少有一个足够大的表缓存来容纳所有的表。所以内存使用量会急剧上升,甚至出现oom。

通常我们习惯通过以下手段解决此问题:

1、库表拆分,减少单实例打开文件数量

2、调整table_definition_cache和table_open_cache数量

3、添加物理内存

mysql 8.0 问世之后,又提供了一种选择,由于字典表采用innodb引擎,而且字典表可以使用索引。

下面的图解释了mysql 5.7和8.0设计上的区别:

8.0> explain select table_name,table_rows,concat(round(data_length/1024/1024, 2), 'mb') as size,concat(round(index_length/1024/1024, 2), 'mb') as index_size,data_free/1024/1024 as data_free_mb from information_schema.tables where table_schema not in ('information_schema','performance_schema','test') order by data_free_mb desc limit 10;
+----+-------------+-------+------------+--------+--------------------+------------+---------+-------------------------------+------+----------+----------------------------------------------+
| id | select_type | table | partitions | type  | possible_keys   | key    | key_len | ref              | rows | filtered | extra                    |
+----+-------------+-------+------------+--------+--------------------+------------+---------+-------------------------------+------+----------+----------------------------------------------+
| 1 | simple   | cat  | null    | index | primary      | name    | 194   | null             |  1 |  100.00 | using index; using temporary; using filesort |
| 1 | simple   | sch  | null    | ref  | primary,catalog_id | catalog_id | 8    | mysql.cat.id         |  6 |  50.00 | using where; using index           |
| 1 | simple   | tbl  | null    | ref  | schema_id     | schema_id | 8    | mysql.sch.id         |  52 |  100.00 | using where                 |
| 1 | simple   | ts  | null    | eq_ref | primary      | primary  | 8    | mysql.tbl.tablespace_id    |  1 |  100.00 | null                     |
| 1 | simple   | stat | null    | eq_ref | primary      | primary  | 388   | mysql.sch.name,mysql.tbl.name |  1 |  100.00 | null                     |
| 1 | simple   | col  | null    | eq_ref | primary      | primary  | 8    | mysql.tbl.collation_id    |  1 |  100.00 | using index                 |
+----+-------------+-------+------------+--------+--------------------+------------+---------+-------------------------------+------+----------+----------------------------------------------+

以上就是详解mysql8.0​ 字典表增强的详细内容,更多关于mysql8.0​ 字典表增强的资料请关注移动技术网其它相关文章!

如您对本文有疑问或者有任何想说的,请 点击进行留言回复,万千网友为您解惑!

相关文章:

  • Ubuntu上Vim安装NERDTree插件的详细操作步骤

    Ubuntu上Vim安装NERDTree插件的详细操作步骤

    nerdtree是vim的文件系统浏览器,使用此插件,用户可以直观地浏览复杂的目录层次结构,快速打开文件以进行读取或编辑,以及执行基本的文件系统操作。nerdt... [阅读全文]
  • MySQL 4种常用的主从复制架构

    MySQL 4种常用的主从复制架构

    一主多从复制架构在主库读取请求压力非常大的场景下,可以通过配置一主多从复制架构实现读写分离,把大量的对实时性要求不是特别高的读请求通过负载均衡分部到多个从库上(... [阅读全文]
  • 浅析MySQL 备份与恢复

    1、简介数据无价,mysql作为一个数据库系统,其备份自然也是非常重要且有必要去做。备份的理由千千万,预防故障,安全需求,回滚,审计,删了又改的需求等等,备份的... [阅读全文]
  • 保障MySQL数据安全的一些建议

    数据是企业核心资产,数据对企业而言是最重要的工作之一。稍有不慎,极有可能发生数据无意泄露,甚至被黑客恶意窃取的风险。每年业界都会传出几起大事件,某知名或不知名的... [阅读全文]
  • MySQL如何快速修改表的表结构

    快速修改mysql某张表的表结构--摘录自《mysql管理之道》alter table 表名 modify 列名 数据类型; 这个命令可以修改表结构此外,也可以... [阅读全文]
  • MySQL 行锁和表锁的含义及区别详解

    一、前言对于行锁和表锁的含义区别,在面试中应该是高频出现的,我们应该对mysql中的锁有一个系统的认识,更详细的需要自行查阅资料,本篇为概括性的总结回答。mys... [阅读全文]
  • MySQL 如何查询当前最新事务ID

    写在前面:在个别时候可能需要查看当前最新的事务 id,以便做一些业务逻辑上的判断(例如利用事务 id 变化以及前后时差,统计每次事务的响应时长等用途)。通常地,... [阅读全文]
  • 如何优雅、安全的关闭MySQL进程

    前言本文分析了 mysqld 进程关闭的过程,以及如何安全、缓和地关闭 mysql 实例,对这个过程不甚清楚的同学可以参考下。关闭过程1、发起 shutdown... [阅读全文]
  • 详解MySQL8.0​ 字典表增强

    详解MySQL8.0​ 字典表增强

    mysql中数据字典是数据库重要的组成部分之一,information_schema首次引入于mysql 5.0,作为一种从正在运行的mysql服务器检索元数据... [阅读全文]
  • 简述MySQL InnoDB存储引擎

    前言:存储引擎是数据库的核心,对于 mysql 来说,存储引擎是以插件的形式运行的。虽然 mysql 支持种类繁多的存储引擎,但最常用的当属 innodb 了,... [阅读全文]
验证码:
移动技术网