• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

详解MySQL8.0​ 字典表增强

mysql 搞代码 4年前 (2022-01-09) 25次浏览 已收录 0个评论

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 |
+--------------------+------------------<span style="color:transparent">本文来源gaodai#ma#com搞*!代#%^码网%</span>--+----------+
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 |
+----+-------------+--------+------+---------------+------+---------+------+------+-----------------------------------------------------+

搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:详解MySQL8.0​ 字典表增强

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址