{"id":1912,"date":"2010-05-06T21:07:34","date_gmt":"2010-05-06T13:07:34","guid":{"rendered":"http:\/\/www.orczhou.com\/?p=1912"},"modified":"2010-05-06T21:07:34","modified_gmt":"2010-05-06T13:07:34","slug":"mysql-optimize-table","status":"publish","type":"post","link":"https:\/\/www.orczhou.com\/index.php\/2010\/05\/mysql-optimize-table\/","title":{"rendered":"MySQL Optimize Table"},"content":{"rendered":"<p><a href=\"http:\/\/www.xaprb.com\/blog\/2010\/02\/07\/how-often-should-you-use-optimize-table\/\">\u5f88\u96be\u8bf4<\/a>Optimize Table\u5230\u5e95\u80fd\u4e0d\u80fd\u63d0\u9ad8\u7cfb\u7edf\u8fd0\u884c\u6548\u7387\uff0c\u4f46\u662f\u6709\u4e00\u70b9\u662f\u80af\u5b9a\u7684\uff1a\u5b83\u80fd\u591f\u5e2e\u6211\u4eec\u56de\u6536\u66f4\u591a\u7684\u7a7a\u95f4\u3001<a href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.1\/en\/optimize-table.html\">\u51cf\u5c11\u201c\u788e\u7247\u201d\uff08defragment\uff09<\/a>\u3002<\/p>\n<p><font color=\"red\">1. \u56de\u6536\u7a7a\u95f4 Defragment<\/font><\/p>\n<p>\u5728InnoDB\u7684\u7ef4\u62a4\u8fc7\u7a0b\u4e2d\uff0c\u6211\u4eec\u603b\u4f1a\u9047\u5230\u78c1\u76d8\u8017\u5c3d\u3001\u6216\u8005<a href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.0\/en\/multiple-tablespaces.html\">InnoDB Tablespaces<\/a>\u7528\u5b8c\u7684\u60c5\u51b5\u3002\u8fd9\u65f6\u5019\uff0c\u5728\u8003\u8651\u6269\u5bb9\u7b49\u65b9\u6848\u4e4b\u524d\uff0c\u6700\u597d\u5148\u4f7f\u7528Optimize Table\u8bd5\u8bd5\u3002\u5982\u679c\u4f60\u7684\u8868\u5927\u5b57\u6bb5\uff08Text Blob Varchar\uff09\uff0c\u5e76\u4e14\u66f4\u65b0\u3001\u5220\u9664\u8f83\u9891\u7e41\u7684\u8bdd\uff0cOptimize\u4e4b\u540e\u53ef\u80fd\u4f1a\u817e\u51fa\u5927\u91cf\u7684\u7a7a\u95f4\u3002<!--more--><\/p>\n<pre><div class=\"mycode\">#ls -lah users_0.ibd \r\n-rwxr-xr-x  1 mysql dba 736M May  6 09:50 users_0.ibd\r\n\r\nroot@test 10:10:53>optimize table users_0;\r\n+---------------------+----------+----------+----------+\r\n| Table               | Op       | Msg_type | Msg_text |\r\n+---------------------+----------+----------+----------+\r\n|     test.users_0    | optimize | status   | OK       | \r\n+---------------------+----------+----------+----------+\r\n\r\n#ls -lah users_0.ibd \r\n-rw-rw----  1 mysql dba 644M May  6 10:09 users_0.ibd<\/div><\/pre>\n<p>\u53ef\u4ee5\u770b\u5230\u8fd9\u91cc\u7684ibd\u6587\u4ef6\u5927\u5c0f\u91ca\u653e\u4e86\u7ea6100M\u3002<\/p>\n<p><font color=\"red\">2. InnoDB \u548c MyISAM<\/font><\/p>\n<p>\u76ee\u524d\u652f\u6301optimize\u547d\u4ee4\u7684\u5f15\u64ce\u6709 <a href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.1\/en\/optimize-table.html\">MyISAM, InnoDB, and ARCHIVE<\/a>\uff0c\u5bf9\u4e8eInnoDB\uff0c\u4f1a\u5c06optimize\u547d\u4ee4\u6620\u5c04\u4e3aALTER TABLE\u547d\u4ee4\uff0c\u8be5\u547d\u4ee4\u4f1a\u91cd\u5efa\u6570\u636e\u8868\uff0c\u66f4\u65b0\u7d22\u5f15\u7edf\u8ba1\u4fe1\u606f\u3001\u56de\u6536\u4e3b\u952e\u7d22\u5f15\u4e2d\u7a7a\u95f4\u3002<\/p>\n<p><font color=\"red\">3. InnoDB \u548c MyISAM<\/font><\/p>\n<p>\u5982\u679c\u4f60\u7684MySQL\u662f\u6709\u5907\u5e93\u7684\uff0c\u5982\u679c\u4f60\u53ea\u5e0c\u671b\u5728\u4e3b\u5e93\u4e0a\u6267\u884c\u7684\u8bdd\uff0c\u90a3\u4e48\u53ef\u4ee5\u52a0\u4e0a\u5173\u952e\u5b57NO_WRITE_TO_BINLOG\uff08\u6216\u8005LOCAL\uff0c\u610f\u601d\u5b8c\u5168\u76f8\u540c\uff09\u3002<\/p>\n<div class=\"mycode\">OPTIMIZE [NO_WRITE_TO_BINLOG | LOCAL] TABLE<\/div>\n<p>\u8fd9\u5bf9\u4e8e<strong>MM\u7ed3\u6784\u7684MySQL\u6570\u636e\u5e93\u5c24\u4e3a\u91cd\u8981<\/strong>\uff0c\u56e0\u4e3a\u5f88\u591a\u65f6\u5019\uff0c\u4f60\u53ea\u662f\u60f3\u5728\u5907\u5e93\u4e0a\u6267\u884c\uff0c\u800c\u4e0d\u5e0c\u671b\u5f71\u54cd\u4e3b\u5e93\u3002<\/p>\n<p>\u53c2\u8003\u6587\u732e<\/p>\n<p>[1]. <a href=\"http:\/\/dev.mysql.com\/doc\/refman\/5.1\/en\/optimize-table.html\">MySQL Manual OPTIMIZE TABLE Syntax<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f88\u96be\u8bf4Optimize Table\u5230\u5e95\u80fd\u4e0d\u80fd\u63d0\u9ad8\u7cfb\u7edf\u8fd0\u884c\u6548\u7387\uff0c\u4f46\u662f\u6709\u4e00\u70b9\u662f\u80af\u5b9a\u7684\uff1a\u5b83\u80fd\u591f\u5e2e\u6211\u4eec\u56de\u6536\u66f4\u591a\u7684\u7a7a\u95f4\u3001\u51cf\u5c11\u201c\u788e\u7247\u201d\uff08defragment\uff09\u3002 1. \u56de\u6536\u7a7a\u95f4 Defragment \u5728InnoDB\u7684\u7ef4\u62a4\u8fc7\u7a0b\u4e2d\uff0c\u6211\u4eec\u603b\u4f1a\u9047\u5230\u78c1\u76d8\u8017\u5c3d\u3001\u6216\u8005InnoDB Tablespaces\u7528\u5b8c\u7684\u60c5\u51b5\u3002\u8fd9\u65f6\u5019\uff0c\u5728\u8003\u8651\u6269\u5bb9\u7b49\u65b9\u6848\u4e4b\u524d\uff0c\u6700\u597d\u5148\u4f7f\u7528Optimize Table\u8bd5\u8bd5\u3002\u5982\u679c\u4f60\u7684\u8868\u5927\u5b57\u6bb5\uff08Text Blob Varchar\uff09\uff0c\u5e76\u4e14\u66f4\u65b0\u3001\u5220\u9664\u8f83\u9891\u7e41\u7684\u8bdd\uff0cOptimize\u4e4b\u540e\u53ef\u80fd\u4f1a\u817e\u51fa\u5927\u91cf\u7684\u7a7a\u95f4\u3002<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_eb_attr":"","inline_featured_image":false,"_tocer_settings":[],"footnotes":""},"categories":[6],"tags":[120,118],"class_list":["post-1912","post","type-post","status-publish","format-standard","hentry","category-mysql","tag-innodb","tag-mysql"],"_links":{"self":[{"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/posts\/1912","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/comments?post=1912"}],"version-history":[{"count":15,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/posts\/1912\/revisions"}],"predecessor-version":[{"id":1934,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/posts\/1912\/revisions\/1934"}],"wp:attachment":[{"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/media?parent=1912"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/categories?post=1912"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.orczhou.com\/index.php\/wp-json\/wp\/v2\/tags?post=1912"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}