濮阳杆衣贸易有限公司

主頁 > 知識庫 > 詳解MySQL8.0​ 字典表增強

詳解MySQL8.0​ 字典表增強

熱門標(biāo)簽:石家莊400電話辦理公司 新鄉(xiāng)智能外呼系統(tǒng)好處 廣東400企業(yè)電話申請流程 咸陽防封電銷卡 申請400電話電話價格 許昌外呼增值業(yè)務(wù)線路 臨沂做地圖標(biāo)注 地圖標(biāo)注客戶付款 宜賓全自動外呼系統(tǒng)廠家

MySQL中數(shù)據(jù)字典是數(shù)據(jù)庫重要的組成部分之一,INFORMATION_SCHEMA首次引入于MySQL 5.0,作為一種從正在運行的MySQL服務(wù)器檢索元數(shù)據(jù)的標(biāo)準(zhǔn)兼容方式。用于存儲數(shù)據(jù)元數(shù)據(jù)、統(tǒng)計信息、以及有關(guān)MySQL server的訪問信息(例如:數(shù)據(jù)庫名或表名,字段的數(shù)據(jù)類型和訪問權(quán)限等)。

8.0之前:

1、元數(shù)據(jù)來自文件

2、采用MEMORY表引擎

3、frm文件 存放表結(jié)構(gòu)信息

4、opt文件,記錄了每個庫的一些基本信息,包括庫的字符集等信息

5、.TRN,.TRG文件用于存放觸發(fā)器的信息內(nèi)容

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、元數(shù)據(jù)存在表中

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的性能仍然是我們許多用戶的主要痛點。在當(dāng)前INFORMATION_SCHEMA實現(xiàn)方式下產(chǎn)生的性能問題背后的關(guān)鍵原因是,INFORMATION_SCHEMA表的查詢實現(xiàn)方式是在查詢執(zhí)行期間創(chuàng)建臨時表。

如下,當(dāng)我們查詢表碎片時:

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表查詢時對文件打開的優(yōu)化;

  • Skip_open_table:表文件不需要打開。信息已經(jīng)通過掃描數(shù)據(jù)庫目錄在查詢中實現(xiàn)可用。
  • Open_frm_only:只需要打開表的.frm文件。
  • Open_full_table:未優(yōu)化的信息查找。必須打開.frm、.MYD和.MYI文件。
  • Scanned N databases:指在處理information_schema查詢時,有多少目錄需要掃描。

如果一個MySQL實例有上百個庫,每個庫又有上百張表,INFORMATION_SCHEMA查詢最終會從文件系統(tǒng)中讀取每個單獨的frm文件,造成很多I/O讀取。并且最終還會消耗更多的CPU來打開表并準(zhǔn)備相關(guān)的內(nèi)存數(shù)據(jù)結(jié)構(gòu)。它也確實會嘗試使用MySQL server層的表緩存(系統(tǒng)變量table_definition_cache ),但是在大型實例中,很少有一個足夠大的表緩存來容納所有的表。所以內(nèi)存使用量會急劇上升,甚至出現(xiàn)oom。

通常我們習(xí)慣通過以下手段解決此問題:

1、庫表拆分,減少單實例打開文件數(shù)量

2、調(diào)整table_definition_cache和table_open_cache數(shù)量

3、添加物理內(nèi)存

mysql 8.0 問世之后,又提供了一種選擇,由于字典表采用innodb引擎,而且字典表可以使用索引。

下面的圖解釋了MySQL 5.7和8.0設(shè)計上的區(qū)別:

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​ 字典表增強的詳細(xì)內(nèi)容,更多關(guān)于MySQL8.0​ 字典表增強的資料請關(guān)注腳本之家其它相關(guān)文章!

您可能感興趣的文章:
  • Mysql用戶忘記密碼及密碼過期問題的處理方法
  • 詳解MySQL的用戶密碼過期功能
  • mysql密碼過期導(dǎo)致連接不上mysql
  • MySQL8.0中的降序索引
  • Docker 部署 Mysql8.0的方法示例
  • MySQL8.0中binlog的深入講解
  • MySQL8.0 如何快速加列
  • mysql8.0.21安裝教程圖文詳解
  • Windows系統(tǒng)下MySQL8.0.21安裝教程(圖文詳解)
  • MySQL8.0.21.0社區(qū)版安裝教程(圖文詳解)
  • 詳解MySQL8.0 密碼過期策略

標(biāo)簽:阜新 貴州 鷹潭 北京 鎮(zhèn)江 日照 臺灣 合肥

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《詳解MySQL8.0​ 字典表增強》,本文關(guān)鍵詞  詳解,MySQL8.0,amp,#8203,字典,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《詳解MySQL8.0​ 字典表增強》相關(guān)的同類信息!
  • 本頁收集關(guān)于詳解MySQL8.0​ 字典表增強的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    定日县| 鄄城县| 双流县| 泾源县| 宝应县| 通山县| 姜堰市| 喀什市| 邵阳县| 淳化县| 水城县| 始兴县| 时尚| 江川县| 如东县| 滕州市| 福海县| 敦化市| 天门市| 贡觉县| 哈密市| 清苑县| 昌宁县| 揭西县| 尤溪县| 绥江县| 湖州市| 克山县| 太保市| 安徽省| 香港| 荆州市| 根河市| 白水县| 乌拉特后旗| 安达市| 阳西县| 石林| 商洛市| 潼关县| 温泉县|