{"id":75656,"date":"2024-10-16T00:07:26","date_gmt":"2024-10-15T16:07:26","guid":{"rendered":"https:\/\/server.hk\/cnblog\/75656\/"},"modified":"2024-10-16T00:07:27","modified_gmt":"2024-10-15T16:07:27","slug":"mysql-%e4%b8%ad%e5%a6%82%e4%bd%95%e5%ae%9a%e4%bd%8dddl%e8%a2%ab%e9%98%bb%e5%a1%9e%e7%9a%84%e5%95%8f%e9%a1%8c","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/75656\/","title":{"rendered":"MySQL \u4e2d\u5982\u4f55\u5b9a\u4f4dDDL\u88ab\u963b\u585e\u7684\u554f\u984c"},"content":{"rendered":"<h1 id=\"mysql-%e4%b8%ad%e5%a6%82%e4%bd%95%e5%ae%9a%e4%bd%8d-ddl-%e8%a2%ab%e9%98%bb%e5%a1%9e%e7%9a%84%e5%95%8f%e9%a1%8c-VpKXgExwOw\">MySQL \u4e2d\u5982\u4f55\u5b9a\u4f4d DDL \u88ab\u963b\u585e\u7684\u554f\u984c<\/h1>\n<p>\u5728\u4f7f\u7528 MySQL \u6578\u64da\u5eab\u6642\uff0c\u6578\u64da\u5b9a\u7fa9\u8a9e\u8a00\uff08DDL\uff09\u64cd\u4f5c\u5982\u5275\u5efa\u3001\u4fee\u6539\u6216\u522a\u9664\u8868\u683c\u7b49\uff0c\u53ef\u80fd\u6703\u56e0\u70ba\u9396\u5b9a\u554f\u984c\u800c\u88ab\u963b\u585e\u3002\u9019\u4e0d\u50c5\u5f71\u97ff\u4e86\u6578\u64da\u5eab\u7684\u6027\u80fd\uff0c\u9084\u53ef\u80fd\u5c0e\u81f4\u61c9\u7528\u7a0b\u5e8f\u7684\u5ef6\u9072\u3002\u672c\u6587\u5c07\u63a2\u8a0e\u5982\u4f55\u5b9a\u4f4d MySQL \u4e2d DDL \u88ab\u963b\u585e\u7684\u554f\u984c\uff0c\u4e26\u63d0\u4f9b\u4e00\u4e9b\u89e3\u6c7a\u65b9\u6848\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%af-ddl-%e8%a2%ab%e9%98%bb%e5%a1%9e%ef%bc%9f-VpKXgExwOw\">\u4ec0\u9ebc\u662f DDL \u88ab\u963b\u585e\uff1f<\/h2>\n<p>DDL \u88ab\u963b\u585e\u662f\u6307\u5728\u57f7\u884c DDL \u64cd\u4f5c\u6642\uff0c\u8a72\u64cd\u4f5c\u56e0\u70ba\u5176\u4ed6\u4e8b\u52d9\u6301\u6709\u7684\u9396\u800c\u7121\u6cd5\u5b8c\u6210\u3002\u9019\u7a2e\u60c5\u6cc1\u901a\u5e38\u767c\u751f\u5728\u4ee5\u4e0b\u5e7e\u7a2e\u60c5\u6cc1\u4e0b\uff1a<\/p>\n<ul>\n<li>\u9577\u6642\u9593\u904b\u884c\u7684\u4e8b\u52d9\u6301\u6709\u9396\u3002<\/li>\n<li>\u591a\u500b\u4e8b\u52d9\u540c\u6642\u5617\u8a66\u4fee\u6539\u540c\u4e00\u8cc7\u6e90\u3002<\/li>\n<li>\u4e0d\u7576\u7684\u7d22\u5f15\u6216\u8868\u8a2d\u8a08\u5c0e\u81f4\u7684\u6027\u80fd\u74f6\u9838\u3002<\/li>\n<\/ul>\n<h2 id=\"%e5%a6%82%e4%bd%95%e5%ae%9a%e4%bd%8d-ddl-%e8%a2%ab%e9%98%bb%e5%a1%9e%e7%9a%84%e5%95%8f%e9%a1%8c-VpKXgExwOw\">\u5982\u4f55\u5b9a\u4f4d DDL \u88ab\u963b\u585e\u7684\u554f\u984c<\/h2>\n<p>\u5b9a\u4f4d DDL \u88ab\u963b\u585e\u7684\u554f\u984c\u9700\u8981\u4f7f\u7528 MySQL \u63d0\u4f9b\u7684\u5de5\u5177\u548c\u547d\u4ee4\u3002\u4ee5\u4e0b\u662f\u4e00\u4e9b\u5e38\u7528\u7684\u65b9\u6cd5\uff1a<\/p>\n<h3 id=\"1-%e4%bd%bf%e7%94%a8-show-processlist-VpKXgExwOw\">1. \u4f7f\u7528 SHOW PROCESSLIST<\/h3>\n<p>\u9996\u5148\uff0c\u53ef\u4ee5\u4f7f\u7528 <code>SHOW PROCESSLIST<\/code> \u547d\u4ee4\u4f86\u67e5\u770b\u7576\u524d\u6b63\u5728\u57f7\u884c\u7684\u6240\u6709\u9032\u7a0b\u3002\u9019\u500b\u547d\u4ee4\u6703\u986f\u793a\u6bcf\u500b\u9032\u7a0b\u7684 ID\u3001\u7528\u6236\u3001\u4e3b\u6a5f\u3001\u6578\u64da\u5eab\u3001\u547d\u4ee4\u3001\u6642\u9593\u548c\u72c0\u614b\u7b49\u4fe1\u606f\u3002<\/p>\n<pre><code>SHOW PROCESSLIST;<\/code><\/pre>\n<p>\u5728\u7d50\u679c\u4e2d\uff0c\u67e5\u627e\u72c0\u614b\u70ba <code>Locked<\/code> \u7684\u9032\u7a0b\uff0c\u9019\u4e9b\u9032\u7a0b\u53ef\u80fd\u662f\u5c0e\u81f4 DDL \u88ab\u963b\u585e\u7684\u539f\u56e0\u3002<\/p>\n<h3 id=\"2-%e4%bd%bf%e7%94%a8-information_schema-VpKXgExwOw\">2. \u4f7f\u7528 INFORMATION_SCHEMA<\/h3>\n<p>MySQL \u7684 <code>INFORMATION_SCHEMA<\/code> \u6578\u64da\u5eab\u63d0\u4f9b\u4e86\u8a31\u591a\u6709\u7528\u7684\u8868\u683c\uff0c\u53ef\u4ee5\u7528\u4f86\u67e5\u8a62\u9396\u5b9a\u4fe1\u606f\u3002\u7279\u5225\u662f <code>INNODB_LOCKS<\/code> \u548c <code>INNODB_LOCK_WAITS<\/code> \u8868\u683c\uff0c\u53ef\u4ee5\u5e6b\u52a9\u6211\u5011\u4e86\u89e3\u7576\u524d\u7684\u9396\u5b9a\u60c5\u6cc1\u3002<\/p>\n<pre><code>SELECT * FROM INFORMATION_SCHEMA.INNODB_LOCKS;<\/code><\/pre>\n<pre><code>SELECT * FROM INFORMATION_SCHEMA.INNODB_LOCK_WAITS;<\/code><\/pre>\n<p>\u9019\u4e9b\u67e5\u8a62\u5c07\u986f\u793a\u7576\u524d\u7684\u9396\u5b9a\u548c\u7b49\u5f85\u60c5\u6cc1\uff0c\u5e6b\u52a9\u6211\u5011\u8b58\u5225\u51fa\u54ea\u4e9b\u4e8b\u52d9\u6b63\u5728\u963b\u585e DDL \u64cd\u4f5c\u3002<\/p>\n<h3 id=\"3-%e4%bd%bf%e7%94%a8-performance-schema-VpKXgExwOw\">3. \u4f7f\u7528 Performance Schema<\/h3>\n<p>Performance Schema \u662f MySQL \u63d0\u4f9b\u7684\u4e00\u500b\u5f37\u5927\u5de5\u5177\uff0c\u53ef\u4ee5\u7528\u4f86\u76e3\u63a7\u6578\u64da\u5eab\u7684\u6027\u80fd\u3002\u901a\u904e\u67e5\u8a62 <code>events_waits_current<\/code> \u8868\uff0c\u53ef\u4ee5\u7372\u53d6\u7576\u524d\u7684\u7b49\u5f85\u4e8b\u4ef6\u4fe1\u606f\u3002<\/p>\n<pre><code>SELECT * FROM performance_schema.events_waits_current WHERE EVENT_NAME LIKE 'wait\/%';<\/code><\/pre>\n<p>\u9019\u5c07\u986f\u793a\u6240\u6709\u7576\u524d\u7684\u7b49\u5f85\u4e8b\u4ef6\uff0c\u5305\u62ec\u9396\u5b9a\u7b49\u5f85\uff0c\u5e6b\u52a9\u6211\u5011\u9032\u4e00\u6b65\u5206\u6790\u554f\u984c\u3002<\/p>\n<h2 id=\"%e8%a7%a3%e6%b1%ba-ddl-%e8%a2%ab%e9%98%bb%e5%a1%9e%e7%9a%84%e5%95%8f%e9%a1%8c-VpKXgExwOw\">\u89e3\u6c7a DDL \u88ab\u963b\u585e\u7684\u554f\u984c<\/h2>\n<p>\u4e00\u65e6\u5b9a\u4f4d\u5230 DDL \u88ab\u963b\u585e\u7684\u539f\u56e0\uff0c\u53ef\u4ee5\u8003\u616e\u4ee5\u4e0b\u5e7e\u7a2e\u89e3\u6c7a\u65b9\u6848\uff1a<\/p>\n<ul>\n<li>\u512a\u5316\u9577\u6642\u9593\u904b\u884c\u7684\u4e8b\u52d9\uff0c\u6e1b\u5c11\u9396\u5b9a\u7684\u6301\u6709\u6642\u9593\u3002<\/li>\n<li>\u8abf\u6574\u61c9\u7528\u7a0b\u5e8f\u7684\u6578\u64da\u5eab\u8a2a\u554f\u6a21\u5f0f\uff0c\u907f\u514d\u540c\u6642\u5c0d\u540c\u4e00\u8cc7\u6e90\u9032\u884c DDL \u64cd\u4f5c\u3002<\/li>\n<li>\u8003\u616e\u4f7f\u7528\u975e\u9396\u5b9a\u7684 DDL \u64cd\u4f5c\uff0c\u4f8b\u5982\u4f7f\u7528 <code>ALGORITHM=INPLACE<\/code> \u4f86\u9032\u884c\u8868\u7d50\u69cb\u7684\u4fee\u6539\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b8%bd%e7%b5%90-VpKXgExwOw\">\u7e3d\u7d50<\/h2>\n<p>\u5b9a\u4f4d MySQL \u4e2d DDL \u88ab\u963b\u585e\u7684\u554f\u984c\u9700\u8981\u4f7f\u7528\u591a\u7a2e\u5de5\u5177\u548c\u65b9\u6cd5\uff0c\u5305\u62ec <code>SHOW PROCESSLIST<\/code>\u3001<code>INFORMATION_SCHEMA<\/code> \u548c <code>Performance Schema<\/code>\u3002\u901a\u904e\u9019\u4e9b\u65b9\u6cd5\uff0c\u6211\u5011\u53ef\u4ee5\u6709\u6548\u5730\u8b58\u5225\u51fa\u963b\u585e\u7684\u539f\u56e0\uff0c\u4e26\u63a1\u53d6\u76f8\u61c9\u7684\u63aa\u65bd\u4f86\u89e3\u6c7a\u554f\u984c\u3002\u5c0d\u65bc\u9700\u8981\u9ad8\u6548\u6578\u64da\u5eab\u64cd\u4f5c\u7684\u7528\u6236\uff0c\u9078\u64c7\u5408\u9069\u7684 <a href=\"https:\/\/server.hk\">\u9999\u6e2f VPS<\/a> \u670d\u52d9\u53ef\u4ee5\u63d0\u4f9b\u66f4\u597d\u7684\u6027\u80fd\u548c\u7a69\u5b9a\u6027\uff0c\u5f9e\u800c\u6e1b\u5c11\u6b64\u985e\u554f\u984c\u7684\u767c\u751f\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e86\u89e3\u5982\u4f55\u5728 MySQL \u4e2d\u5b9a\u4f4d DDL \u88ab\u963b\u585e\u7684\u554f\u984c\uff0c\u5feb\u901f\u6392\u67e5\u548c\u89e3\u6c7a\u6578\u64da\u5eab\u64cd\u4f5c\u4e2d\u7684\u6027\u80fd\u74f6\u9838\u3002<\/p>\n","protected":false},"author":0,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[101],"tags":[],"class_list":["post-75656","post","type-post","status-publish","format-standard","hentry","category-database"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/75656","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=75656"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/75656\/revisions"}],"predecessor-version":[{"id":75657,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/75656\/revisions\/75657"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=75656"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=75656"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=75656"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}