{"id":3828,"date":"2025-07-06T14:31:31","date_gmt":"2025-07-06T06:31:31","guid":{"rendered":"https:\/\/www.laixuexila.com\/?p=3828"},"modified":"2025-07-06T14:31:31","modified_gmt":"2025-07-06T06:31:31","slug":"%e5%9c%a8-mysql%ef%bc%885-6-8-0%ef%bc%89%e4%b8%ad%e8%ae%a1%e7%ae%97%e6%95%b0%e6%8d%ae%e5%ba%93%e4%b8%8e%e6%95%b0%e6%8d%ae%e8%a1%a8%e7%89%a9%e7%90%86%e5%b0%ba%e5%af%b8","status":"publish","type":"post","link":"https:\/\/www.laixuexila.com\/index.php\/2025\/07\/06\/%e5%9c%a8-mysql%ef%bc%885-6-8-0%ef%bc%89%e4%b8%ad%e8%ae%a1%e7%ae%97%e6%95%b0%e6%8d%ae%e5%ba%93%e4%b8%8e%e6%95%b0%e6%8d%ae%e8%a1%a8%e7%89%a9%e7%90%86%e5%b0%ba%e5%af%b8\/","title":{"rendered":"\u5728 MySQL\uff085.6\u00a0~\u00a08.0\uff09\u4e2d\u8ba1\u7b97\u6570\u636e\u5e93\u4e0e\u6570\u636e\u8868\u201c\u7269\u7406\u5c3a\u5bf8\u201d\u4e0e\u201c\u903b\u8f91\u5c3a\u5bf8\u201d**\u7684\u5e38\u7528\u65b9\u6cd5"},"content":{"rendered":"\n<p>\u4e0b\u9762\u6f14\u793a**\u5728 MySQL\uff085.6\u00a0~\u00a08.0\uff09\u4e2d\u8ba1\u7b97\u6570\u636e\u5e93\u4e0e\u6570\u636e\u8868\u201c\u7269\u7406\u5c3a\u5bf8\u201d\u4e0e\u201c\u903b\u8f91\u5c3a\u5bf8\u201d**\u7684\u5e38\u7528\u65b9\u6cd5\uff0c\u5747\u57fa\u4e8e\u5b98\u65b9 <code>information_schema<\/code> &amp; <code>performance_schema<\/code> \u89c6\u56fe\uff0c\u4e0d\u4f9d\u8d56\u7b2c\u4e09\u65b9\u63d2\u4ef6\u3002\u6240\u6709\u793a\u4f8b\u53ef\u76f4\u63a5\u5728 MySQL Shell \/\u202fCLI\u00a0(<code>mysql<\/code>) \u4e2d\u6267\u884c\uff1b\u82e5\u7528 MariaDB \u540c\u6837\u9002\u7528\uff08\u5217\u540d\u76f8\u540c\uff09\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">1.\u57fa\u7840\u6982\u5ff5<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u5217<\/th><th>\u8bf4\u660e<\/th><\/tr><\/thead><tbody><tr><td><code>DATA_LENGTH<\/code><\/td><td>\u8868\u6570\u636e\u6587\u4ef6\u5927\u5c0f\uff08\u5b57\u8282\uff09<\/td><\/tr><tr><td><code>INDEX_LENGTH<\/code><\/td><td>\u7d22\u5f15\u5360\u7528\u5927\u5c0f\uff08\u5b57\u8282\uff09<\/td><\/tr><tr><td><code>DATA_FREE<\/code><\/td><td>\u5df2\u5206\u914d\u4f46\u672a\u4f7f\u7528\u7684\u7a7a\u95f4\uff08\u5b57\u8282\uff0cInnoDB \u201c\u788e\u7247\u201d\uff09<\/td><\/tr><tr><td><strong>\u603b\u5927\u5c0f<\/strong><\/td><td><code>DATA_LENGTH&amp;nbsp;+&amp;nbsp;INDEX_LENGTH<\/code><\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>\u6e90\u81ea <code>information_schema.TABLES<\/code> \u89c6\u56fe\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">2.\u8ba1\u7b97 <strong>\u5355\u5f20\u8868<\/strong> \u5927\u5c0f<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT  \n  table_schema                                          AS db,\n  table_name,\n  ROUND(data_length\/1024\/1024, 2)  AS data_mb,\n  ROUND(index_length\/1024\/1024, 2) AS index_mb,\n  ROUND((data_length+index_length)\/1024\/1024, 2) AS total_mb\nFROM information_schema.tables\nWHERE table_schema = 'your_db' AND table_name = 'your_table';<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">3.\u8ba1\u7b97 <strong>\u6574\u4e2a\u6570\u636e\u5e93<\/strong>\uff08Schema\uff09\u5927\u5c0f<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT  \n  table_schema                                          AS db,\n  ROUND(SUM(data_length)\/1024\/1024, 2)  AS data_mb,\n  ROUND(SUM(index_length)\/1024\/1024, 2) AS index_mb,\n  ROUND(SUM(data_length+index_length)\/1024\/1024, 2) AS total_mb\nFROM information_schema.tables\nWHERE table_schema = 'your_db'\nGROUP BY table_schema;<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">4.\u4e00\u6b21\u5217\u51fa <strong>\u6240\u6709\u6570\u636e\u5e93<\/strong> \u5927\u5c0f<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT\n  table_schema                                          AS db,\n  ROUND(SUM(data_length)\/1024\/1024, 2)  AS data_mb,\n  ROUND(SUM(index_length)\/1024\/1024, 2) AS index_mb,\n  ROUND(SUM(data_length+index_length)\/1024\/1024, 2) AS total_mb\nFROM information_schema.tables\nGROUP BY table_schema\nORDER BY total_mb DESC;<\/code><\/pre>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\">\n<p>\u8df3\u8fc7\u7cfb\u7edf\u5e93\uff1a<br><code>\u2026 WHERE table_schema NOT IN ('mysql','sys','performance_schema','information_schema') \u2026<\/code><\/p>\n<\/blockquote>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">5.\u5efa\u7acb <strong>\u89c6\u56fe<\/strong> \u4fbf\u4e8e\u65e5\u5e38\u67e5\u8be2<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>CREATE OR REPLACE VIEW v_db_size AS\nSELECT\n  table_schema,\n  ROUND(SUM(data_length+index_length)\/1024\/1024,2) AS total_mb\nFROM information_schema.tables\nGROUP BY table_schema;<\/code><\/pre>\n\n\n\n<p>\u4ee5\u540e\u76f4\u63a5\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT * FROM v_db_size ORDER BY total_mb DESC;<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">6.\u67e5\u8be2 <strong>\u5206\u533a\u8868<\/strong> \u5404\u5206\u533a\u5927\u5c0f\uff088.0+\uff09<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT\n  table_schema,\n  table_name,\n  partition_name,\n  ROUND(data_length\/1024\/1024,2) AS data_mb,\n  ROUND(index_length\/1024\/1024,2) AS index_mb\nFROM information_schema.partitions\nWHERE table_schema = 'your_db' AND table_name = 'your_partitioned_tbl';<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">7.\u4f7f\u7528 <code>performance_schema<\/code>\uff088.0\u00a0\u63a8\u8350\uff09<\/h2>\n\n\n\n<p><code>file_summary_by_event_name<\/code> \u7edf\u8ba1\u7269\u7406\u6587\u4ef6\u8bfb\u5199\u3001\u5b57\u8282\u6570\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>SELECT\n  SUBSTRING_INDEX(event_name,'\/',-1) AS file,\n  ROUND(SUM(number_of_bytes_read+number_of_bytes_write)\/1024\/1024,2) AS io_mb\nFROM performance_schema.file_summary_by_event_name\nWHERE event_name LIKE 'wait\/io\/file\/innodb\/%'\nGROUP BY file\nORDER BY io_mb DESC;<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">8.CLI \u5feb\u6377\u547d\u4ee4<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>\u67e5\u770b\u8868\u72b6\u6001\uff1a<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>  mysql -e \"USE your_db; SHOW TABLE STATUS\\G\"<\/code><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li>MySQL \u81ea\u5e26\u5de5\u5177\uff1a<\/li>\n<\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>  mysqlshow --status your_db        # \u6c47\u603b\n  mysqlshow --status your_db your_table<\/code><\/pre>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">9.\u811a\u672c\u5316\u76d1\u63a7\u793a\u4f8b\uff08Bash\uff09<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>#!\/usr\/bin\/env bash\nmysql -Nse \"\n  SELECT table_schema, ROUND(SUM(data_length+index_length)\/1024\/1024,2) AS MB\n  FROM information_schema.tables\n  WHERE table_schema NOT IN ('mysql','sys','performance_schema','information_schema')\n  GROUP BY table_schema;\n\"<\/code><\/pre>\n\n\n\n<p>\u53ef\u5c06\u8f93\u51fa\u63a8\u9001\u5230 Prometheus Pushgateway\u3001Zabbix Sender \u6216\u8bb0\u5f55\u65e5\u5fd7\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">10.\u6ce8\u610f\u4e8b\u9879 &amp; \u6700\u4f73\u5b9e\u8df5<\/h2>\n\n\n\n<figure class=\"wp-block-table\"><table class=\"has-fixed-layout\"><thead><tr><th>\u9879<\/th><th>\u5efa\u8bae<\/th><\/tr><\/thead><tbody><tr><td>InnoDB <code>innodb_file_per_table=ON<\/code><\/td><td>\u4fbf\u4e8e\u5355\u8868\u67e5\u770b\/\u6536\u7f29<\/td><\/tr><tr><td>\u957f\u671f\u788e\u7247\u56de\u6536<\/td><td><code>OPTIMIZE TABLE<\/code> \u6216 <code>ALTER TABLE \u2026 ENGINE=InnoDB;<\/code><\/td><\/tr><tr><td>\u76d1\u63a7\u9608\u503c\u544a\u8b66<\/td><td>\u5bf9\u6570\u636e\u5e93\u6216\u78c1\u76d8\u5206\u533a\u8bbe\u7f6e\u4f7f\u7528\u7387\u544a\u8b66<\/td><\/tr><tr><td>\u5907\u4efd &amp; \u6e05\u7406<\/td><td>\u5927\u4f53\u91cf\u8868\u5206\u533a\u5f52\u6863\uff0c\u8bfb\u5199\u5206\u79bb<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\ud83d\udcda \u5b98\u65b9\u53c2\u8003<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>MySQL\u00a0Ref\u00a0Manual \u2013 <em>The <code>information_schema<\/code>\u00a0Tables<\/em><br><a href=\"https:\/\/dev.mysql.com\/doc\/refman\/8.0\/en\/information-schema.html\">https:\/\/dev.mysql.com\/doc\/refman\/8.0\/en\/information-schema.html<\/a><\/li>\n\n\n\n<li>MySQL\u00a0Ref\u00a0Manual \u2013 <em>SHOW TABLE STATUS<\/em><br><a href=\"https:\/\/dev.mysql.com\/doc\/refman\/8.0\/en\/show-table-status.html\">https:\/\/dev.mysql.com\/doc\/refman\/8.0\/en\/show-table-status.html<\/a><\/li>\n\n\n\n<li>MySQL\u00a0Ref\u00a0Manual \u2013 <em>performance_schema File Summary Tables<\/em><br><a href=\"https:\/\/dev.mysql.com\/doc\/refman\/8.0\/en\/performance-schema-file-summary-tables.html\">https:\/\/dev.mysql.com\/doc\/refman\/8.0\/en\/performance-schema-file-summary-tables.html<\/a><\/li>\n<\/ul>\n\n\n\n<hr class=\"wp-block-separator has-alpha-channel-opacity\"\/>\n\n\n\n<p>\u66f4\u591a\u8be6\u7ec6\u5185\u5bb9\u8bf7\u5173\u6ce8\u5176\u4ed6\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e0b\u9762\u6f14\u793a**\u5728 MySQL\uff085.6\u00a0~\u00a08.0\uff09\u4e2d\u8ba1\u7b97\u6570\u636e\u5e93\u4e0e\u6570\u636e\u8868\u201c\u7269\u7406\u5c3a\u5bf8\u201d\u4e0e\u201c\u903b\u8f91\u5c3a\u5bf8\u201d**\u7684\u5e38\u7528\u65b9\u6cd5\uff0c [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":3829,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[34],"tags":[],"class_list":["post-3828","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-34"],"_links":{"self":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/3828","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/comments?post=3828"}],"version-history":[{"count":1,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/3828\/revisions"}],"predecessor-version":[{"id":3830,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/posts\/3828\/revisions\/3830"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/media\/3829"}],"wp:attachment":[{"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/media?parent=3828"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/categories?post=3828"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.laixuexila.com\/index.php\/wp-json\/wp\/v2\/tags?post=3828"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}