{"id":5369,"date":"2020-07-29T23:51:14","date_gmt":"2020-07-29T15:51:14","guid":{"rendered":"http:\/\/39.97.231.10\/?p=5369"},"modified":"2020-07-29T23:51:14","modified_gmt":"2020-07-29T15:51:14","slug":"mysql-8-0-online-ddl-%e5%9c%a8%e7%ba%bf%e8%a1%a8%e5%8f%98%e6%9b%b4","status":"publish","type":"post","link":"http:\/\/www.weijing.co\/?p=5369","title":{"rendered":"MySQL 8.0 Online DDL \u5728\u7ebf\u8868\u53d8\u66f4"},"content":{"rendered":"<div class=\\\"blog_content\\\">\n<div class=\\\"blog_detail\\\">\n<div>\nMySQL InnoDB Online DDL \u63d0\u4f9b\u4e86\u5728\u7ebf\u8868\u53d8\u66f4\u7684\u80fd\u529b\uff0c\u5728\u8fdb\u884cDDL\u64cd\u4f5c\u7684\u540c\u65f6\uff0c\u4e0d\u5f71\u54cd\u6216\u8005\u5c3d\u53ef\u80fd\u5c0f\u7684\u5f71\u54cdDML\u64cd\u4f5c\uff0c\u76f8\u6bd4\u4e8e\u4f20\u7edf\u7684\u8868\u53d8\u66f4\u9501\u8868\uff0c\u4e0d\u5141\u8bb8\u5199\u5165\uff0cOnline DDL\u6700\u5927\u7a0b\u5ea6\u5730\u51cf\u5c11\u4e86\u5bf9\u4e1a\u52a1\u7684\u5f71\u54cd\u3002\u8be5\u529f\u80fd\u57285.6\u7248\u672c\u5f15\u5165\uff0c\u57285.7\uff0c8.0\u7248\u672c\u5f97\u5230\u6301\u7eed\u52a0\u5f3a\uff0c\u5c24\u51768.0\u7248\u672c\u5b9e\u73b0\u7684\u5feb\u901f\u8868\u53d8\u66f4\uff0c\u53ea\u9700\u8981\u4fee\u6539\u5143\u6570\u636e\uff0c\u5c31\u80fd\u5b8c\u6210\u8868\u53d8\u66f4\u64cd\u4f5c\uff0c\u6bd4\u5982\u6dfb\u52a0\u5b57\u6bb5\uff0c\u79d2\u7ea7\u5b8c\u6210\uff0c\u6781\u5927\u5730\u89e3\u51b3\u4e86\u5927\u8868\u52a0\u5b57\u6bb5\u8017\u65f6\u957f\u7684\u95ee\u9898\u3002<\/p>\n<h4>\u4e00\u3001Online DDL\u4f18\u52bf<\/h4>\n<ol>\n<li>\u5927\u591a\u6570DDL\u64cd\u4f5c\u671f\u95f4\uff0c\u4e0d\u963b\u585eDML\u7684\u6267\u884c\uff0c\u51cf\u5c11\u5bf9\u8d44\u6e90\u7684\u9501\u5b9a\u548c\u7b49\u5f85\u65f6\u95f4\uff0c\u63d0\u9ad8\u4e86DDL\u8fc7\u7a0b\u4e2d\u8868\u7684\u53ef\u7528\u6027\uff0c\u51cf\u5c11\u5bf9\u4e1a\u52a1\u7684\u5f71\u54cd\u3002<\/li>\n<li>\u4e00\u4e9b\u652f\u6301\u5feb\u901f\u8868\u53d8\u66f4\u7684\u64cd\u4f5c\uff0c\u53ea\u9700\u8981\u4fee\u6539\u6570\u636e\u5b57\u5178\u4e2d\u7684\u5143\u6570\u636e\uff0c\u4e0d\u4f1a\u5728\u8868\u4e0a\u957f\u65f6\u95f4\u5360\u7528\u5143\u6570\u636e\u9501\uff0c\u4e0d\u4f1a\u5f71\u54cd\u8868\u6570\u636e\uff0c\u64cd\u4f5c\u5feb\u901f\u5b8c\u6210\uff0c\u4e0d\u5f71\u54cdDML\u3002<\/li>\n<li>\u76f8\u5bf9\u4e8e\u4f20\u7edftable-copy\u65b9\u5f0f\u4fee\u6539\u8868\u7ed3\u6784\uff0cOnline DDL\u80fd\u591f\u51cf\u5c11CPU\u548cIO\u8d1f\u8f7d\uff0c\u4e0d\u4f1a\u5bf9\u6574\u4f53\u6570\u636e\u5e93\u6027\u80fd\u9020\u6210\u5927\u7684\u5f71\u54cd\u3002<\/li>\n<li>Online DDL\u64cd\u4f5c\u80fd\u591f\u66f4\u5c11\u7684\u8bfb\u53d6\u6570\u636e\u5230buffer pool\uff0c\u51cf\u5c11\u5185\u5b58\u9875\u6362\u51fa\uff0c\u907f\u514dDDL\u5b8c\u6210\u540e\uff0c\u7531\u4e8e\u9891\u7e41\u9875\u6362\u51fa\u5bfc\u81f4\u7684\u6027\u80fd\u4e0b\u964d\u3002<\/li>\n<\/ol>\n<h4>\u4e8c\u3001Online DDL\u8bed\u6cd5<\/h4>\n<p>\u76f8\u5bf9\u4e8e\u4f20\u7edfALTER\u8bed\u53e5\u6539\u8868\uff0cOnline DDL\u65b0\u589e\u4e86ALGORITHM\u5b50\u53e5\u548cLOCK\u5b50\u53e5\uff0c\u4e00\u4e2a\u5178\u578b\u7684Online DDL\u8bed\u6cd5\u5982\u4e0b\uff1a<br \/>\nALTER TABLE t1 ADD COLUMN x INT, ALGORITHM=INPLACE, LOCK=NONE;<br \/>\n<strong>ALGORITHM \u5b50\u53e5\uff1a<\/strong><br \/>\nALGORITHM \u5b50\u53e5\u652f\u6301 INSTANT\uff0cINPLACE\u548cCOPY\u4e09\u79cd\u65b9\u5f0f\u3002<\/p>\n<ul>\n<li>INSTANT\uff1a\u5feb\u901f\u6539\u8868<\/li>\n<li>INPLACE\uff1a\u539f\u5730\u6539\u8868<\/li>\n<li>COPY\uff1a\u62f7\u8d1d\u65b9\u5f0f\u6539\u8868<\/li>\n<\/ul>\n<p>\u7b97\u6cd5\u6027\u80fd\uff1aINSTANT &gt; INPLACE &gt; COPY<br \/>\nALGORITHM=INSTANT\uff0c\u5feb\u901f\u8868\u53d8\u66f4\uff0c\u652f\u6301\u5feb\u901f\u6dfb\u52a0\u5b57\u6bb5\u7b49\u64cd\u4f5c\uff0c\u8be5\u7279\u6027\u5728 8.0.12 \u7248\u672c\u52a0\u5165\u3002<br \/>\n<strong>LOCK \u5b50\u53e5\uff1a<\/strong><br \/>\n\u9ed8\u8ba4\u6761\u4ef6\u4e0b\uff0cOnline DDL\u5728\u4e00\u6b21\u6539\u8868\u8fc7\u7a0b\u4e2d\uff0c\u5c3d\u53ef\u80fd\u5c11\u7684\u4f7f\u7528\u9501\uff0c\u5728inplace\u548ccopy\u65b9\u5f0f\u4e0b\uff0c\u5982\u679c\u9700\u8981\u9501\uff0c\u53ef\u4ee5\u6307\u5b9alock\u5b50\u53e5\uff0c\u4ee5\u6267\u884c\u66f4\u4e25\u683c\u7684\u9501\u3002\u5982\u679clock\u6307\u5b9a\u7684\u9501\u7ea7\u522b\u65e0\u6cd5\u6ee1\u8db3DDL\u64cd\u4f5c\uff0c\u6539\u8868\u8bed\u53e5\u5c06\u4f1a\u62a5\u9519\u3002<br \/>\n\u9501\u7ea7\u522b\u4ece\u4f4e\u5230\u9ad8\uff0c\u4f9d\u6b21\u5982\u4e0b\uff1a<\/p>\n<ul>\n<li>LOCK=NONE\uff0c\u5141\u8bb8DML<\/li>\n<li>LOCK=SHARED\uff0c\u5141\u8bb8\u8bfb\uff0c\u7981\u6b62DML<\/li>\n<li>LOCK=DEFAULT\uff0c\u9ed8\u8ba4\u9501\u6a21\u5f0f\uff0c\u5728\u6ee1\u8db3DDL\u64cd\u4f5c\u524d\u63d0\u4e0b\uff0c\u8bbe\u7f6e\u9501\u6a21\u5f0f\u5c06\u5141\u8bb8\u5c3d\u53ef\u80fd\u591a\u7684\u8bfb\u548cDML\u3002<\/li>\n<li>LOCK=EXCLUSIVE\uff0c\u963b\u585e\u8bfb\u548cDML<\/li>\n<\/ul>\n<p>Online DDL \u8bed\u6cd5\u5e76\u4e0d\u9700\u8981\u663e\u5f0f\u5730\u6307\u5b9aALGORITHM\u548cLOCK\uff0c\u901a\u5e38\u4e0d\u9700\u8981\u505a\u4efb\u4f55\u914d\u7f6e\u5c31\u53ef\u4ee5\u4f7f\u7528Online DDL\u3002\u5f53\u7136\u4e5f\u53ef\u4ee5\u5728ALTER\u8bed\u53e5\u4e2d\u663e\u5f0f\u5730\u4f7f\u7528 ALGORITHM\uff0cLOCK\u5b50\u53e5\u6765\u63a7\u5236Online DDL\u5177\u4f53\u4f7f\u7528\u7684\u7b97\u6cd5\u4ee5\u53ca\u52a0\u9501\u7c7b\u578b\u3002<\/p>\n<h4>\u4e09\u3001Online DDL\u652f\u6301\u7684\u64cd\u4f5c<\/h4>\n<h5>3.1 \u7d22\u5f15\u64cd\u4f5c<\/h5>\n<table>\n<thead>\n<tr>\n<th>\u64cd\u4f5c\u7c7b\u578b<\/th>\n<th>\u652f\u6301\u5feb\u901f\u5b8c\u6210<\/th>\n<th>\u539f\u5730\u6539\u8868<\/th>\n<th>\u91cd\u5efa\u8868<\/th>\n<th>\u5141\u8bb8DML<\/th>\n<th>\u53ea\u4fee\u6539\u5143\u6570\u636e<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u521b\u5efa\u3001\u6dfb\u52a0\u4e8c\u7ea7\u7d22\u5f15<\/td>\n<td>no<\/td>\n<td>yes<\/td>\n<td>no<\/td>\n<td>yes<\/td>\n<td>no<\/td>\n<\/tr>\n<tr>\n<td>\u5220\u9664\u7d22\u5f15<\/td>\n<td>no<\/td>\n<td>yes<\/td>\n<td>no<\/td>\n<td>yes<\/td>\n<td>yes<\/td>\n<\/tr>\n<tr>\n<td>\u91cd\u547d\u540d\u7d22\u5f15<\/td>\n<td>no<\/td>\n<td>yes<\/td>\n<td>no<\/td>\n<td>yes<\/td>\n<td>yes<\/td>\n<\/tr>\n<tr>\n<td>\u6dfb\u52a0\u5168\u6587\u7d22\u5f15<\/td>\n<td>no<\/td>\n<td>yes*<\/td>\n<td>no*<\/td>\n<td>no<\/td>\n<td>no<\/td>\n<\/tr>\n<tr>\n<td>\u6dfb\u52a0\u7a7a\u95f4\u7d22\u5f15<\/td>\n<td>no<\/td>\n<td>yes<\/td>\n<td>no<\/td>\n<td>no<\/td>\n<td>no<\/td>\n<\/tr>\n<tr>\n<td>\u4fee\u6539\u7d22\u5f15\u7c7b\u578b<\/td>\n<td>yes<\/td>\n<td>yes<\/td>\n<td>no<\/td>\n<td>yes<\/td>\n<td>yes<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u521b\u5efa\u5168\u6587\u7d22\u5f15\u65f6\uff0c\u5982\u679c\u6ca1\u6709\u7528\u6237\u5b9a\u4e49\u7684FTS_DOC_ID\u5b57\u6bb5\uff0c\u5c06\u4f1a\u91cd\u5efa\u8868\u3002<br \/>\n\u521b\u5efa\u6216\u8005\u6dfb\u52a0\u4e8c\u7ea7\u7d22\u5f15\uff0c\u5728\u7d22\u5f15\u521b\u5efa\u7684\u8fc7\u7a0b\u4e2d\uff0c\u8868\u4ecd\u7136\u53ef\u4ee5\u8bfb\u5199\u3002\u5728Online DDL\u521b\u5efa\u7d22\u5f15\u7684\u6700\u540e\u9636\u6bb5\uff0c\u53ea\u6709\u5728\u8bbf\u95ee\u8868\u7684\u6240\u6709\u4e8b\u52a1\u5b8c\u6210\u4e4b\u540e\u624d\u80fd\u7ed3\u675f\uff0c\u4ee5\u4fbf\u7d22\u5f15\u80fd\u591f\u53cd\u6620\u6700\u65b0\u7684\u8868\u5185\u5bb9\u3002<br \/>\n<strong>\u793a\u4f8b\uff1a<\/strong><br \/>\n\uff081\uff09\u521b\u5efa\u7d22\u5f15\uff1a<br \/>\nCREATE INDEX name ON table (col_list);<br \/>\nALTER TABLE tbl_name ADD INDEX name (col_list);<br \/>\n\uff082\uff09\u5220\u9664\u7d22\u5f15\uff1a<br \/>\nDROP INDEX name ON table;<br \/>\nALTER TABLE tbl_name DROP INDEX name;<br \/>\n\uff083\uff09\u91cd\u547d\u540d\u7d22\u5f15\uff1a<br \/>\nALTER TABLE tbl_name RENAME INDEX old_index_name TO new_index_name, ALGORITHM=INPLACE, LOCK=NONE;<br \/>\n\uff084\uff09\u521b\u5efa\u5168\u6587\u7d22\u5f15\uff1a<br \/>\nCREATE FULLTEXT INDEX name ON table(column);<br \/>\n\uff085\uff09\u521b\u5efa\u7a7a\u95f4\u7d22\u5f15\uff1a<br \/>\nCREATE TABLE geom (g GEOMETRY NOT NULL);<br \/>\nALTER TABLE geom ADD SPATIAL INDEX(g), ALGORITHM=INPLACE, LOCK=SHARED;<br \/>\n\uff086\uff09\u6539\u53d8\u7d22\u5f15\u7c7b\u578b\uff08USING {BTREE | HASH}\uff09\uff1a<br \/>\nALTER TABLE tbl_name DROP INDEX i1, ADD INDEX i1(key_part,&#8230;) USING BTREE, ALGORITHM=INSTANT;<\/p>\n<h5>3.2 \u4e3b\u952e\u64cd\u4f5c<\/h5>\n<table>\n<thead>\n<tr>\n<th>\u64cd\u4f5c\u7c7b\u578b<\/th>\n<th>\u652f\u6301\u5feb\u901f\u5b8c\u6210<\/th>\n<th>\u539f\u5730\u6539\u8868<\/th>\n<th>\u91cd\u5efa\u8868(\u4e34\u65f6\u8868\uff09<\/th>\n<th>\u5141\u8bb8DML<\/th>\n<th>\u53ea\u4fee\u6539\u5143\u6570\u636e<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u6dfb\u52a0\u4e3b\u952e<\/td>\n<td>no<\/td>\n<td>yes*<\/td>\n<td>yes*<\/td>\n<td>yes<\/td>\n<td>no<\/td>\n<\/tr>\n<tr>\n<td>\u5220\u9664\u4e3b\u952e<\/td>\n<td>no<\/td>\n<td>no<\/td>\n<td>yes<\/td>\n<td>no<\/td>\n<td>no<\/td>\n<\/tr>\n<tr>\n<td>\u5220\u9664\u4e3b\u952e\u5e76\u6dfb\u52a0\u65b0\u7684\u4e3b\u952e<\/td>\n<td>no<\/td>\n<td>yes<\/td>\n<td>yes<\/td>\n<td>yes<\/td>\n<td>no<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><br \/>\n\uff081\uff09\u6dfb\u52a0\u4e3b\u952e<br \/>\nALTER TABLE tbl_name ADD PRIMARY KEY (column), ALGORITHM=INPLACE, LOCK=NONE;<br \/>\n\uff082\uff09\u5220\u9664\u4e3b\u952e\uff1a<br \/>\nALTER TABLE tbl_name DROP PRIMARY KEY, ALGORITHM=COPY;<br \/>\n\uff083\uff09\u5220\u9664\u4e3b\u952e\uff0c\u7136\u540e\u6dfb\u52a0\u65b0\u7684\u4e3b\u952e\uff1a<br \/>\nALTER TABLE tbl_name DROP PRIMARY KEY, ADD PRIMARY KEY (column), ALGORITHM=INPLACE, LOCK=NONE;<\/p>\n<h5>3.3 \u5b57\u6bb5\u64cd\u4f5c<\/h5>\n<table>\n<thead>\n<tr>\n<th>\u64cd\u4f5c\u7c7b\u578b<\/th>\n<th>\u652f\u6301\u5feb\u901f\u5b8c\u6210<\/th>\n<th>\u539f\u5730\u6539\u8868<\/th>\n<th>\u91cd\u5efa\u8868(\u4e34\u65f6\u8868\uff09<\/th>\n<th>\u5141\u8bb8DML<\/th>\n<th>\u53ea\u4fee\u6539\u5143\u6570\u636e<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u6dfb\u52a0\u5b57\u6bb5<\/td>\n<td>yes*<\/td>\n<td>yes<\/td>\n<td>no*<\/td>\n<td>yes*<\/td>\n<td>no<\/td>\n<\/tr>\n<tr>\n<td>\u5220\u9664\u5b57\u6bb5<\/td>\n<td>no<\/td>\n<td>yes<\/td>\n<td>yes<\/td>\n<td>yes<\/td>\n<td>no<\/td>\n<\/tr>\n<tr>\n<td>\u91cd\u547d\u540d\u5b57\u6bb5<\/td>\n<td>no<\/td>\n<td>yes<\/td>\n<td>no<\/td>\n<td>yes*<\/td>\n<td>yes<\/td>\n<\/tr>\n<tr>\n<td>\u5b57\u6bb5\u987a\u5e8f\u53d8\u66f4<\/td>\n<td>no<\/td>\n<td>yes<\/td>\n<td>yes<\/td>\n<td>yes<\/td>\n<td>no<\/td>\n<\/tr>\n<tr>\n<td>\u5b57\u6bb5\u8bbe\u7f6e\u9ed8\u8ba4\u503c<\/td>\n<td>yes<\/td>\n<td>yes<\/td>\n<td>no<\/td>\n<td>yes<\/td>\n<td>yes<\/td>\n<\/tr>\n<tr>\n<td>\u4fee\u6539\u5b57\u6bb5\u6570\u636e\u7c7b\u578b<\/td>\n<td>no<\/td>\n<td>no<\/td>\n<td>yes<\/td>\n<td>no<\/td>\n<td>no<\/td>\n<\/tr>\n<tr>\n<td>\u4fee\u6539varchar\u5b57\u6bb5\u5927\u5c0f<\/td>\n<td>no<\/td>\n<td>yes<\/td>\n<td>no<\/td>\n<td>yes<\/td>\n<td>yes<\/td>\n<\/tr>\n<tr>\n<td>\u5220\u9664\u5b57\u6bb5\u9ed8\u8ba4\u503c<\/td>\n<td>yes<\/td>\n<td>yes<\/td>\n<td>no<\/td>\n<td>yes<\/td>\n<td>yes<\/td>\n<\/tr>\n<tr>\n<td>\u4fee\u6539auto-increment\u503c<\/td>\n<td>no<\/td>\n<td>yes<\/td>\n<td>no<\/td>\n<td>yes<\/td>\n<td>no*<\/td>\n<\/tr>\n<tr>\n<td>\u4fee\u6539\u5b57\u6bb5\u53ef\u4ee5\u4e3aNULL<\/td>\n<td>no<\/td>\n<td>yes<\/td>\n<td>yes*<\/td>\n<td>yes<\/td>\n<td>no<\/td>\n<\/tr>\n<tr>\n<td>\u4fee\u6539\u5b57\u6bb5\u4e0d\u53ef\u4ee5\u4e3aNULL<\/td>\n<td>no<\/td>\n<td>yes*<\/td>\n<td>yes*<\/td>\n<td>yes<\/td>\n<td>no<\/td>\n<\/tr>\n<tr>\n<td>\u4fee\u6539enum,set\u5b9a\u4e49<\/td>\n<td>yes<\/td>\n<td>yes<\/td>\n<td>no<\/td>\n<td>yes<\/td>\n<td>yes<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><br \/>\n\uff081\uff09\u6dfb\u52a0\u5b57\u6bb5\uff1a<br \/>\nALTER TABLE tbl_name ADD COLUMN column_name column_definition, ALGORITHM=INSTANT;<br \/>\n\uff082\uff09\u6dfb\u52a0\u591a\u4e2a\u5b57\u6bb5\uff1a<br \/>\nALTER TABLE t1 ADD COLUMN c2 INT, ADD COLUMN c3 INT, ALGORITHM=INSTANT;<br \/>\n\u6dfb\u52a0\u5b57\u6bb5\u7684INSTANT\u7b97\u6cd5\u6709\u5982\u4e0b\u9650\u5236\uff1a<\/p>\n<ol>\n<li>\u5982\u679c\u4e00\u4e2aALTER\u8bed\u53e5\u5305\u542b\u591a\u5904\u8868\u4fee\u6539\uff0c\u5176\u4ed6\u7684\u4fee\u6539\u4e0d\u652f\u6301INSTANT\u7b97\u6cd5\u65f6\uff0c\u6dfb\u52a0\u5b57\u6bb5\u4e5f\u4e0d\u80fd\u4f7f\u7528INSTANT\u7b97\u6cd5\u3002<\/li>\n<li>\u53ea\u80fd\u5728\u8868\u7684\u6700\u540e\u4e00\u4e2a\u5b57\u6bb5\u4e4b\u540e\u6dfb\u52a0\u65b0\u7684\u5b57\u6bb5\uff0c\u5426\u5219\u65e0\u6cd5\u4f7f\u7528INSTANT\u7b97\u6cd5\u3002<\/li>\n<li>\u4f7f\u7528\u884c\u683c\u5f0f\u538b\u7f29ROW_FORMAT=COMPRESSED\u65f6\uff0c\u65e0\u6cd5\u4f7f\u7528INSTANT\u7b97\u6cd5\u6dfb\u52a0\u5b57\u6bb5\u3002<\/li>\n<li>\u8868\u4e2d\u5b58\u5728\u5168\u6587\u7d22\u5f15\u65f6\uff0c\u65e0\u6cd5\u4f7f\u7528INSTANT\u7b97\u6cd5\u6dfb\u52a0\u5b57\u6bb5\u3002<\/li>\n<li>\u4e0d\u80fd\u4f7f\u7528INSTANT\u7b97\u6cd5\u7ed9\u4e34\u65f6\u8868\u6dfb\u52a0\u5b57\u6bb5\uff0c\u4e34\u65f6\u8868\u53ea\u652f\u6301COPY\u7b97\u6cd5\u3002<\/li>\n<li>\u4e0d\u80fd\u4f7f\u7528INSTANT\u7b97\u6cd5\u7ed9\u6570\u636e\u5b57\u5178\u8868\u7a7a\u95f4\u4e2d\u7684\u8868\u6dfb\u52a0\u5b57\u6bb5\u3002<\/li>\n<li>\u6dfb\u52a0\u5b57\u6bb5\u65f6\uff0c\u4e0d\u4f1a\u68c0\u67e5\u884c\u5c3a\u5bf8\u5927\u5c0f\u9650\u5236\uff0c\u4f46\u662fDML\u64cd\u4f5c\uff0c\u63d2\u5165\u6216\u8005\u66f4\u65b0\u6570\u636e\u65f6\uff0c\u4f1a\u8fdb\u884c\u68c0\u67e5\u3002<\/li>\n<\/ol>\n<p>\uff083\uff09\u5220\u9664\u5b57\u6bb5\uff1a<br \/>\nALTER TABLE tbl_name DROP COLUMN column_name, ALGORITHM=INPLACE, LOCK=NONE;<br \/>\n\uff084\uff09\u91cd\u547d\u540d\u5b57\u6bb5\uff1a<br \/>\nALTER TABLE tbl CHANGE old_col_name new_col_name data_type, ALGORITHM=INPLACE, LOCK=NONE;<br \/>\n\u5b57\u6bb5\u6570\u636e\u7c7b\u578b\u4e0d\u6539\u53d8\uff0c\u53ea\u4fee\u6539\u540d\u79f0\uff0c\u4e0d\u5f71\u54cdDML\u3002<br \/>\n\uff085\uff09\u4fee\u6539\u5b57\u6bb5\u987a\u5e8f\uff1a<br \/>\nALTER TABLE tbl_name MODIFY COLUMN col_name column_definition FIRST, ALGORITHM=INPLACE, LOCK=NONE;<br \/>\n\uff086\uff09\u4fee\u6539\u5b57\u6bb5\u6570\u636e\u7c7b\u578b\uff1a<br \/>\nALTER TABLE tbl_name CHANGE c1 c1 BIGINT, ALGORITHM=COPY;<br \/>\n\u4fee\u6539\u5b57\u6bb5\u6570\u636e\u7c7b\u578b\uff0c\u53ea\u652f\u6301COPY\u7b97\u6cd5\u3002<br \/>\n\uff087\uff09\u4fee\u6539varchar\u7c7b\u578b\u5927\u5c0f\uff1a<br \/>\nALTER TABLE tbl_name CHANGE COLUMN c1 c1 VARCHAR(255), ALGORITHM=INPLACE, LOCK=NONE;<br \/>\nvarchar\u5c0f\u4e8e256\u65f6\uff0c\u4f7f\u75281\u4e2a\u5b57\u8282\u5b58\u50a8\u5927\u5c0f\uff0c\u5927\u4e8e\u7b49\u4e8e256\u65f6\u4f7f\u75282\u4e2a\u5b57\u8282\u5b58\u50a8\u5927\u5c0f\u3002\u5728\u957f\u5ea6\u5b58\u50a8\u6ca1\u6709\u6539\u53d8\u65f6\uff0c\u6bd4\u5982varhcar size \u4ece 10 \u53d8\u4e3a 20\uff0c\u53ef\u4ee5\u4f7f\u7528inplace \u65b9\u5f0f\u4fee\u6539\u3002\u5982\u679c\u957f\u5ea6\u5b58\u50a8\u53d1\u751f\u6539\u53d8\uff0c\u6bd4\u5982varchar size \u4ece 10 \u53d8\u4e3a 1000\uff0c\u90a3\u4e48\u53ea\u80fd\u4f7f\u7528copy\u65b9\u5f0f\u4fee\u6539\u3002\u5426\u5219\u4f1a\u62a5\u9519\uff0c\u5982\u4e0b\uff1a<br \/>\nALTER TABLE tbl_name ALGORITHM=INPLACE, CHANGE COLUMN c1 c1 VARCHAR(256); ERROR 0A000: ALGORITHM=INPLACE is not supported. Reason: Cannot change column type INPLACE. Try ALGORITHM=COPY.<br \/>\n\u51cf\u5c11varchar size\uff0c\u53ea\u80fd\u4f7f\u7528copy\u7b97\u6cd5\u3002<br \/>\n\uff088\uff09\u5b57\u6bb5\u8bbe\u7f6e\u9ed8\u8ba4\u503c\uff1a<br \/>\nALTER TABLE tbl_name ALTER COLUMN col SET DEFAULT literal, ALGORITHM=INSTANT;<br \/>\n\u53ea\u4fee\u6539\u5143\u6570\u636e\uff0c\u9ed8\u8ba4\u503c\u5b58\u50a8\u5728\u6570\u636e\u5b57\u5178\u91cc\u3002<br \/>\n\uff089\uff09\u5220\u9664\u5b57\u6bb5\u9ed8\u8ba4\u503c\uff1a<br \/>\nALTER TABLE tbl ALTER COLUMN col DROP DEFAULT, ALGORITHM=INSTANT;<br \/>\n\uff0810\uff09\u4fee\u6539\u8868\u7684auto-increment\u503c\uff1a<br \/>\nALTER TABLE table AUTO_INCREMENT=next_value, ALGORITHM=INPLACE, LOCK=NONE;<br \/>\n\uff0811\uff09\u4fee\u6539\u5b57\u6bb5\u53ef\u4ee5\u4e3aNULL\uff1a<br \/>\nALTER TABLE tbl_name MODIFY COLUMN column_name data_type NULL, ALGORITHM=INPLACE, LOCK=NONE;<br \/>\n\uff0812\uff09\u4fee\u6539\u5b57\u6bb5\u4e3aNOT NULL\uff1a<br \/>\nALTER TABLE tbl_name MODIFY COLUMN column_name data_type NOT NULL, ALGORITHM=INPLACE, LOCK=NONE;<br \/>\n\uff0813\uff09\u4fee\u6539enum,set\u7c7b\u578b\u7684\u5b9a\u4e49\uff1a<br \/>\nCREATE TABLE t1 (c1 ENUM(\\&#8217;a\\&#8217;, \\&#8217;b\\&#8217;, \\&#8217;c\\&#8217;));<br \/>\nALTER TABLE t1 MODIFY COLUMN c1 ENUM(\\&#8217;a\\&#8217;, \\&#8217;b\\&#8217;, \\&#8217;c\\&#8217;, \\&#8217;d\\&#8217;), ALGORITHM=INSTANT;<\/p>\n<h5>3.4 \u8868\u64cd\u4f5c<\/h5>\n<table>\n<thead>\n<tr>\n<th>\u64cd\u4f5c\u7c7b\u578b<\/th>\n<th>\u652f\u6301\u5feb\u901f\u5b8c\u6210<\/th>\n<th>\u539f\u5730\u6539\u8868<\/th>\n<th>\u91cd\u5efa\u8868(\u4e34\u65f6\u8868\uff09<\/th>\n<th>\u5141\u8bb8DML<\/th>\n<th>\u53ea\u4fee\u6539\u5143\u6570\u636e<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>\u4fee\u6539ROW_FORMAT<\/td>\n<td>no<\/td>\n<td>yes<\/td>\n<td>yes<\/td>\n<td>yes<\/td>\n<td>no<\/td>\n<\/tr>\n<tr>\n<td>\u4fee\u6539KEY_BLOCK_SIZE<\/td>\n<td>no<\/td>\n<td>yes<\/td>\n<td>yes<\/td>\n<td>yes<\/td>\n<td>no<\/td>\n<\/tr>\n<tr>\n<td>\u8bbe\u7f6e\u8868\u7edf\u8ba1\u4fe1\u606f\u6301\u4e45\u5316<\/td>\n<td>no<\/td>\n<td>yes<\/td>\n<td>no<\/td>\n<td>yes<\/td>\n<td>yes<\/td>\n<\/tr>\n<tr>\n<td>\u6307\u5b9a\u5b57\u7b26\u96c6<\/td>\n<td>no<\/td>\n<td>yes<\/td>\n<td>yes*<\/td>\n<td>no<\/td>\n<td>no<\/td>\n<\/tr>\n<tr>\n<td>\u8f6c\u6362\u5b57\u7b26\u96c6<\/td>\n<td>no<\/td>\n<td>no<\/td>\n<td>yes*<\/td>\n<td>no<\/td>\n<td>no<\/td>\n<\/tr>\n<tr>\n<td>Optimizing table<\/td>\n<td>no<\/td>\n<td>yes*<\/td>\n<td>yes<\/td>\n<td>yes<\/td>\n<td>no<\/td>\n<\/tr>\n<tr>\n<td>\u5f3a\u5236\u6a21\u5f0f\u91cd\u5efa\u8868<\/td>\n<td>no<\/td>\n<td>yes*<\/td>\n<td>yes<\/td>\n<td>yes<\/td>\n<td>no<\/td>\n<\/tr>\n<tr>\n<td>\u91cd\u5efa\u8868<\/td>\n<td>no<\/td>\n<td>yes*<\/td>\n<td>yes<\/td>\n<td>yes<\/td>\n<td>no<\/td>\n<\/tr>\n<tr>\n<td>\u91cd\u547d\u540d\u8868<\/td>\n<td>yes<\/td>\n<td>yes<\/td>\n<td>no<\/td>\n<td>yes<\/td>\n<td>yes<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><br \/>\n\uff081\uff09\u4fee\u6539\u884c\u683c\u5f0fROW_FORMAT\uff1a<br \/>\nALTER TABLE tbl_name ROW_FORMAT = row_format, ALGORITHM=INPLACE, LOCK=NONE;<br \/>\n\uff082\uff09\u4fee\u6539KEY_BLOCK_SIZE\uff1a<br \/>\nALTER TABLE tbl_name KEY_BLOCK_SIZE = value, ALGORITHM=INPLACE, LOCK=NONE;<br \/>\n\uff083\uff09\u8bbe\u7f6e\u8868\u7edf\u8ba1\u4fe1\u606f\u6301\u4e45\u5316\u9009\u9879\uff1a<br \/>\nALTER TABLE tbl_name STATS_PERSISTENT=0, STATS_SAMPLE_PAGES=20, STATS_AUTO_RECALC=1, ALGORITHM=INPLACE, LOCK=NONE;<br \/>\n\uff084\uff09\u6307\u5b9a\u5b57\u7b26\u96c6\uff1a<br \/>\nALTER TABLE tbl_name CHARACTER SET = charset_name, ALGORITHM=INPLACE, LOCK=NONE;<br \/>\n\u5982\u679c\u6307\u5b9a\u7684\u5b57\u7b26\u96c6\u4e0e\u8868\u5f53\u524d\u7684\u5b57\u7b26\u96c6\u4e0d\u540c\uff0c\u5219\u9700\u8981\u91cd\u5efa\u8868\u3002<br \/>\n\uff085\uff09\u8f6c\u6362\u5b57\u7b26\u96c6\uff1a<br \/>\nALTER TABLE tbl_name CONVERT TO CHARACTER SET charset_name, ALGORITHM=COPY;<br \/>\n\u5982\u679c\u6307\u5b9a\u7684\u5b57\u7b26\u96c6\u4e0e\u8868\u5f53\u524d\u7684\u5b57\u7b26\u96c6\u4e0d\u540c\uff0c\u5219\u9700\u8981\u91cd\u5efa\u8868\u3002<br \/>\n\uff086\uff09Optimizing table\uff1a<br \/>\nOPTIMIZE TABLE tbl_name;<br \/>\n\u8868\u4e2d\u6709\u5168\u6587\u7d22\u5f15\uff0c\u4e0d\u652f\u6301inplace\u65b9\u5f0f\u3002<br \/>\n\uff087\uff09\u5e26\u6709FORCE\u9009\u9879\u7684\u91cd\u5efa\u8868\uff1a<br \/>\nALTER TABLE tbl_name FORCE, ALGORITHM=INPLACE, LOCK=NONE;<br \/>\n\u8868\u4e2d\u5305\u542b\u5168\u6587\u7d22\u5f15\uff0c\u4e0d\u652f\u6301Inplace\u65b9\u5f0f\u3002<br \/>\n\uff088\uff09\u91cd\u5efa\u8868\uff1a<br \/>\nALTER TABLE tbl_name ENGINE=InnoDB, ALGORITHM=INPLACE, LOCK=NONE;<br \/>\n\u8868\u4e2d\u5305\u542b\u5168\u6587\u7d22\u5f15\uff0c\u4e0d\u652f\u6301Inplace\u65b9\u5f0f\u3002<br \/>\n\uff089\uff09\u91cd\u547d\u540d\u8868\uff1a<br \/>\nALTER TABLE old_tbl_name RENAME TO new_tbl_name, ALGORITHM=INSTANT;<\/p>\n<h5>3.6 \u5176\u4ed6\u6539\u8868\u64cd\u4f5c<\/h5>\n<p>Online DDL\u8fd8\u652f\u6301\u5176\u4ed6\u6539\u8868\u64cd\u4f5c\uff0c\u4e0d\u518d\u8d58\u8ff0\uff0c\u8be6\u60c5\u53ef\u53c2\u8003\u5b98\u65b9\u6587\u6863\u3002<\/p>\n<ul>\n<li>Generated Column Operations<\/li>\n<li>Foreign Key Operations<\/li>\n<li>Tablespace Operations<\/li>\n<li>Partitioning Operations<\/li>\n<\/ul>\n<h4>\u56db\u3001Online DDL \u78c1\u76d8\u7a7a\u95f4\u8981\u6c42<\/h4>\n<p>\u4ee5\u4e0b\u5217\u51fa\u7684\u78c1\u76d8\u7a7a\u95f4\u8981\u6c42\u4ec5\u9488\u5bf9in-place\u65b9\u5f0f\u7684\u5728\u7ebf\u6539\u8868\uff0c\u4e0d\u9002\u7528instant\u548ccopy\u65b9\u5f0f\u3002<\/p>\n<ol>\n<li>\u4e34\u65f6\u65e5\u5fd7\u6587\u4ef6\u7684\u7a7a\u95f4\u3002\u4e34\u65f6\u65e5\u5fd7\u6587\u4ef6\u7528\u4e8e\u8bb0\u5f55\u6539\u8868\u671f\u95f4\u4ea7\u751f\u7684dml\u64cd\u4f5c\uff0c\u5982\u679c\u4e34\u65f6\u65e5\u5fd7\u6587\u4ef6\u8d85\u8fc7\u6700\u5927\u503c(innodb_online_alter_log_max_size)\uff0cDDL\u64cd\u4f5c\u5c06\u4f1a\u5931\u8d25\uff0c\u672a\u63d0\u4ea4\u7684DML\u64cd\u4f5c\uff0c\u5c06\u4f1a\u56de\u6eda\u3002\u8c03\u9ad8\u4e34\u65f6\u65e5\u5fd7\u6587\u4ef6\u7684\u6700\u5927\u503c\uff0c\u5728DDL\u671f\u95f4\uff0c\u5c06\u5141\u8bb8\u66f4\u591a\u7684DML\u64cd\u4f5c\uff0c\u4f46\u662f\u4e5f\u4f1a\u5bfc\u81f4DDL\u7ed3\u675f\u9636\u6bb5\u5e94\u7528DML\u65e5\u5fd7\u65f6\uff0c\u82b1\u8d39\u66f4\u591a\u7684\u65f6\u95f4\uff0c\u8868\u4e5f\u540c\u65f6\u88ab\u9501\u66f4\u591a\u7684\u65f6\u95f4\u3002<\/li>\n<li>\u4e34\u65f6\u6392\u5e8f\u6587\u4ef6\u7684\u7a7a\u95f4\u3002online ddl\u64cd\u4f5c\uff0c\u521b\u5efa\u7d22\u5f15\u91cd\u5efa\u8868\u65f6\uff0c\u5c06\u4f1a\u5728\u4e34\u65f6\u76ee\u5f55(tmpdir)\u5199\u5165\u4e34\u65f6\u6392\u5e8f\u6587\u4ef6\u3002\u4e34\u65f6\u6392\u5e8f\u6587\u4ef6\u4e0d\u80fd\u521b\u5efa\u5728\u5305\u542b\u539f\u59cb\u8868\u7684\u76ee\u5f55\u91cc\uff0c\u6bcf\u4e2a\u4e34\u65f6\u6392\u5e8f\u6587\u4ef6\u5fc5\u987b\u80fd\u591f\u5b58\u50a8\u5b8c\u6574\u7684\u4e00\u4e2a\u5b57\u6bb5\u7684\u6570\u636e\uff0c\u5728\u8fd9\u4e9b\u6570\u636e\u88ab\u5408\u5e76\u5230\u6700\u7ec8\u7684\u8868\u6216\u8005\u7d22\u5f15\u4e2d\u4e4b\u540e\uff0c\u8fd9\u4e9b\u4e34\u65f6\u6392\u5e8f\u6587\u4ef6\u5c06\u88ab\u5220\u9664\u3002\u6d89\u53ca\u4e34\u65f6\u6392\u5e8f\u6587\u4ef6\u65f6\uff0c\u9700\u8981\u7684\u7a7a\u95f4\u5927\u81f4\u4e3a\u8868\u7684\u6570\u636e\u91cf\u52a0\u4e0a\u7d22\u5f15\u7684\u6570\u636e\u91cf\u3002<\/li>\n<li>\u4e2d\u95f4\u8868\u6587\u4ef6\u7684\u7a7a\u95f4\u3002\u6709\u4e00\u4e9bddl\u64cd\u4f5c\u5728\u91cd\u5efa\u8868\u65f6\uff0c\u9700\u8981\u5728\u539f\u59cb\u8868\u6240\u5728\u76ee\u5f55\u4e2d\u521b\u5efa\u4e2d\u95f4\u8868\u6587\u4ef6\uff0c\u901a\u5e38\u4e00\u4e2a\u4e2d\u95f4\u8868\u6587\u4ef6\u9700\u8981\u4e0e\u539f\u8868\u6587\u4ef6\u76f8\u540c\u5927\u5c0f\u7684\u78c1\u76d8\u7a7a\u95f4\uff0c\u6587\u4ef6\u540d\u4ee5#sql-ib\u5f00\u5934\uff0c\u5728online ddl\u8fc7\u7a0b\u4e2d\u77ed\u6682\u5730\u5b58\u5728\u3002<\/li>\n<\/ol>\n<h4>\u4e94\u3001Online DDL\uff0c\u5408\u5e76\u591a\u4e2a\u8868\u53d8\u66f4\u5230\u4e00\u4e2aSQL\u8bed\u53e5<\/h4>\n<p>\u5728\u5f15\u5165online ddl\u4e4b\u524d\uff0c\u901a\u5e38\u5efa\u8bae\u5c06\u540c\u4e00\u4e2a\u8868\u7684\u591a\u4e2a\u53d8\u66f4\u5408\u5e76\u5230\u4e00\u4e2aalter\u8bed\u53e5\u4e2d\u6267\u884c\uff0c\u591a\u4e2a\u53d8\u66f4\uff0c\u8868\u53ea\u9700\u8981\u91cd\u5efa\u4e00\u6b21\uff0c\u80fd\u6709\u6548\u63d0\u9ad8\u8868\u53d8\u66f4\u7684\u6548\u7387\u3002<br \/>\n\u5bf9\u4e8eonline ddl\u573a\u666f\uff0c\u53ef\u4ee5\u5c06\u591a\u4e2a\u4e0d\u540c\u7684\u8868\u53d8\u66f4\uff0c\u5206\u4e3a\u51e0\u4e2a\u76f8\u5bf9\u72ec\u7acb\u7684alter\u8bed\u53e5\uff0c\u4ee5\u4fbf\u4e8e\u66f4\u597d\u7684\u7ba1\u7406\u548c\u7ef4\u62a4\uff0c\u540c\u65f6\u4e0d\u4f1a\u727a\u7272\u6267\u884c\u6548\u7387\u3002<br \/>\n\u6bd4\u5982\uff1a<br \/>\nALTER TABLE t1 ADD INDEX i1(c1), ADD UNIQUE INDEX i2(c2), CHANGE c4_old_name c4_new_name INTEGER UNSIGNED;<br \/>\n\u53ef\u4ee5\u62c6\u5206\u4e3a\uff1a<br \/>\nALTER TABLE t1 ADD INDEX i1(c1);<br \/>\nALTER TABLE t1 ADD UNIQUE INDEX i2(c2);<br \/>\nALTER TABLE t1 CHANGE c4_old_name c4_new_name INTEGER UNSIGNED NOT NULL;<br \/>\n\u5728\u6709\u4e00\u4e9b\u573a\u666f\uff0c\u4ecd\u7136\u53ef\u4ee5\u5c06\u591a\u4e2a\u8868\u53d8\u66f4\u5199\u6210\u4e00\u4e2aalter\u8bed\u53e5\uff1a<\/p>\n<ol>\n<li>ddl \u5fc5\u987b\u6309\u987a\u5e8f\u6267\u884c\uff0c\u6bd4\u5982\u521b\u5efa\u4e00\u4e2a\u7d22\u5f15\uff0c\u7d27\u63a5\u7740\u4e00\u4e2a\u5916\u952e\u7ea6\u675f\u8981\u4f7f\u7528\u8fd9\u4e2a\u7d22\u5f15\u3002<\/li>\n<li>ddl \u64cd\u4f5c\u4f7f\u7528\u540c\u6837\u7684\u9501\u6a21\u5f0f\uff0c\u4ed6\u4eec\u7ec4\u6210\u4e00\u4e2a\u7ec4\uff0c\u8981\u4e48\u90fd\u6210\u529f\uff0c\u8981\u4e48\u90fd\u5931\u8d25\u3002<\/li>\n<li>ddl \u64cd\u4f5c\u65e0\u6cd5\u4f7f\u7528online\u65b9\u5f0f\uff0c\u53ea\u80fd\u4f7f\u7528\u8868\u62f7\u8d1d\uff08table-copy\uff09\u3002<\/li>\n<li>online ddl \u6307\u5b9a ALGORITHM=COPY \u6216\u8005 old_alter_table=1\uff0c\u5f3a\u5236\u8868\u62f7\u8d1d\uff0c\u4ee5\u4fbf\u4e8e\u5728\u67d0\u4e9b\u573a\u666f\u4e2d\uff0c\u53ef\u4ee5\u5411\u540e\u517c\u5bb9\u3002<\/li>\n<\/ol>\n<h4>\u516d\u3001Online DDL \u53ef\u80fd\u5931\u8d25\u7684\u573a\u666f<\/h4>\n<p>\u6709\u4e00\u4e9b\u5178\u578b\u7684\u573a\u666f\uff0c\u4f1a\u5bfc\u81f4online ddl\u6267\u884c\u5931\u8d25\uff0c\u6c47\u603b\u5982\u4e0b\uff1a<\/p>\n<ol>\n<li>\u6307\u5b9a\u7684algorithm\u4e0eddl\u64cd\u4f5c\u9700\u8981\u7684\u7c7b\u578b\u4e0d\u517c\u5bb9\uff0c\u6bd4\u5982ddl\u64cd\u4f5c\u9700\u8981\u91cd\u5efa\u8868\uff0c\u800c\u6307\u5b9a\u7684algorithm\u662fINSTANT\uff0c\u4f1a\u5bfc\u81f4online ddl\u6267\u884c\u5931\u8d25\u3002<\/li>\n<li>\u6307\u5b9a\u7684\u9501\u7b49\u7ea7\u4e0eddl\u64cd\u4f5c\u9700\u8981\u7684\u9501\u7b49\u7ea7\u4e0d\u517c\u5bb9\uff0c\u6bd4\u5982lock\u5b50\u53e5\u6307\u5b9a SHARED\u00a0\u6216\u8005\u00a0NONE\uff0c\u5b9e\u9645\u9700\u8981EXCLUSIVE\u3002<\/li>\n<li>online ddl \u7684\u5f00\u59cb\u548c\u7ed3\u675f\u9636\u6bb5\uff0c\u9700\u8981\u77ed\u6682\u5730\u83b7\u53d6\u8868\u7684\u6392\u4ed6\u9501\uff0c\u5982\u679c\u83b7\u53d6\u9501\u8d85\u65f6\uff0c\u4e5f\u4f1a\u5bfc\u81f4online ddl\u6267\u884c\u5931\u8d25\u3002<\/li>\n<li>tmpdir\u548cinnodb_tmpdir\u6ca1\u6709\u8db3\u591f\u7684\u78c1\u76d8\u7a7a\u95f4\uff0conline ddl \u5728\u67d0\u4e2a\u573a\u666f\uff0c\u6bd4\u5982\u521b\u5efa\u7d22\u5f15\uff0c\u9700\u8981\u5728\u4e34\u65f6\u76ee\u5f55\u5199\u5165\u4e34\u65f6\u7684\u6392\u5e8f\u6587\u4ef6\uff0c\u5982\u679c\u78c1\u76d8\u7a7a\u95f4\u4e0d\u8db3\uff0c\u5219\u4f1a\u5bfc\u81f4online ddl \u5931\u8d25\u3002<\/li>\n<li>online ddl \u6267\u884c\u65f6\u95f4\u5f88\u957f\uff0c\u5728\u6b64\u8fc7\u7a0b\u4e2d\uff0cdml\u4ea7\u751f\u7684\u4e34\u65f6\u5728\u7ebf\u65e5\u5fd7\u8d85\u8fc7\u4e86\u914d\u7f6einnodb_online_alter_log_max_size\uff0c\u5c06\u5bfc\u81f4online ddl\u5931\u8d25\u3002<\/li>\n<li>\u5728online ddl\u671f\u95f4\uff0cdml\u8bed\u53e5\u4f7f\u7528\u539f\u8868\u7684\u5b9a\u4e49\u8fdb\u884c\u64cd\u4f5c\uff0c\u800c\u4e0d\u517c\u5bb9\u65b0\u7684\u8868\u7ed3\u6784\uff0c\u5f53online ddl \u6267\u884c\u5230\u6700\u540e\u9636\u6bb5\uff0c\u5e94\u7528dml\u5728\u7ebf\u65e5\u5fd7\u65f6\uff0c\u53d1\u751f\u9519\u8bef\u3002\u6bd4\u5982dml\u8bed\u53e5\u63d2\u5165\u4e86\u76f8\u540c\u7684\u503c\uff0c\u800cddl\u6b63\u662f\u5bf9\u8be5\u5b57\u6bb5\u52a0\u4e86\u552f\u4e00\u7d22\u5f15\uff0c\u6b64\u65f6online ddl \u5c06\u4f1a\u5931\u8d25\u56de\u6eda\u3002<\/li>\n<\/ol>\n<h4>\u4e03\u3001Online DDL\u4f7f\u7528\u9650\u5236<\/h4>\n<ol>\n<li>\u4e34\u65f6\u8868\u521b\u5efa\u7d22\u5f15\uff0c\u4f7f\u7528copy\u65b9\u5f0f<\/li>\n<li>\u5982\u679c\u8868\u4e0a\u6709\u7ea6\u675f\u6761\u4ef6ON&#8230;CASCADE\u00a0\u6216\u8005\u00a0ON&#8230;SET NULL\uff0cOnline DDL\u7684LOCK=NONE \u5b50\u53e5\u4e0d\u5141\u8bb8\u4f7f\u7528<\/li>\n<li>in-place\u65b9\u5f0f\u5728\u7ebf\u6539\u8868\uff0c\u5728\u7ed3\u675f\u4e4b\u524d\uff0c\u5fc5\u987b\u7b49\u5f85\u6301\u6709\u5143\u6570\u636e\u9501\u7684\u4e8b\u52a1\u63d0\u4ea4\u6216\u8005\u56de\u6eda\u3002\u4e00\u4e2aonline ddl\u64cd\u4f5c\uff0c\u5728\u5b83\u6267\u884c\u9636\u6bb5\uff0c\u53ef\u80fd\u4f1a\u77ed\u6682\u5730\u8bf7\u6c42\u4e00\u4e2a\u6392\u4ed6\u7684\u5143\u6570\u636e\u9501\uff0c\u800c\u5728\u6700\u540e\u66f4\u65b0\u8868\u7ed3\u6784\u9636\u6bb5\uff0c\u5b83\u603b\u662f\u4f1a\u8bf7\u6c42\u6392\u4ed6\u7684\u5143\u6570\u636e\u9501\u3002\u56e0\u6b64\uff0c\u5982\u679c\u4e00\u4e2a\u4e8b\u52a1\u6301\u6709\u5143\u6570\u636e\u9501\uff0c\u5c06\u4f1a\u5bfc\u81f4online ddl\u88ab\u963b\u585e\uff0c\u4e8b\u52a1\u53ef\u80fd\u5728online ddl\u4e4b\u524d\u6216\u8005\u6267\u884c\u8fc7\u7a0b\u4e2d\u6301\u6709\u5143\u6570\u636e\u9501\uff0c\u4e00\u4e2a\u957f\u4e8b\u52a1\uff0c\u4e0d\u7ba1\u5176\u662f\u6b63\u5728\u8fd0\u884c\uff0c\u8fd8\u662f\u4f11\u7720\u4e8b\u52a1\uff0c\u90fd\u6709\u53ef\u80fd\u5bfc\u81f4online ddl\u64cd\u4f5c\u8d85\u65f6\u3002<\/li>\n<li>\u5f53\u6267\u884c\u4e00\u4e2ain-place\u65b9\u5f0f\u7684online ddl\uff0c\u6267\u884conline ddl\u7684\u7ebf\u7a0b\u4f1a\u5e94\u7528\u5176\u4ed6dml\u7ebf\u7a0b\u4ea7\u751f\u7684\u5728\u7ebfdml\u65e5\u5fd7\uff0c\u5f53dml\u64cd\u4f5c\u88ab\u5e94\u7528\u540e\uff0c\u6709\u53ef\u80fd\u4f1a\u51fa\u73b0\u952e\u51b2\u7a81\uff0c\u5373\u4f7f\u8fd9\u4e2a\u51b2\u7a81\u662f\u4e34\u65f6\u7684\uff0c\u53ef\u80fd\u5728\u540e\u9762\u88ab\u4fee\u590d\uff0c\u4f46\u4e5f\u4f1a\u5bfc\u81f4ddl\u5931\u8d25\u3002<\/li>\n<li>optimize table \u547d\u4ee4\u5bf9\u4e8eInnoDB\u8868\uff0c\u76f8\u5f53\u4e8e\u6267\u884c\u4e86\u4e00\u4e2aalter\u8bed\u53e5\u91cd\u5efa\u8868\uff0c\u66f4\u65b0\u7d22\u5f15\u7edf\u8ba1\u4fe1\u606f\uff0c\u91ca\u653e\u805a\u7c07\u7d22\u5f15\u4e2d\u4e0d\u4f7f\u7528\u7684\u7a7a\u95f4\u3002\u4e8c\u7ea7\u7d22\u5f15\u7684\u521b\u5efa\u6548\u7387\u4e0d\u9ad8\uff0c\u56e0\u4e3a\u952e\u662f\u6309\u5b83\u4eec\u5728\u4e3b\u952e\u4e2d\u51fa\u73b0\u7684\u987a\u5e8f\u63d2\u5165\u7684<\/li>\n<li>MySQL 5.6 \u4e4b\u524d\u521b\u5efa\u7684\u8868\uff0c\u5305\u542b\u65f6\u95f4\u5b57\u6bb5\uff08DATE,\u00a0DATETIME\u00a0or\u00a0TIMESTAMP\uff09\uff0c\u5e76\u4e14\u6ca1\u6709\u4f7f\u7528copy\u65b9\u5f0f\u91cd\u5efa\uff0c\u8fd9\u6837\u7684\u8868\u4e0d\u652f\u6301in-place\u65b9\u5f0f\u3002<\/li>\n<li>\u5927\u8868online ddl\uff0c\u9700\u8981\u91cd\u5efa\u8868\u65f6\uff0c\u6709\u4ee5\u4e0b\u9650\u5236\uff1a\n<ul>\n<li>\u5728online ddl\u64cd\u4f5c\u8fc7\u7a0b\u4e2d\uff0c\u6ca1\u6709\u529e\u6cd5\u6682\u505c\uff0c\u4e5f\u4e0d\u80fd\u9650\u5236cpu\/io\u7684\u4f7f\u7528\u3002<\/li>\n<li>\u5982\u679conline ddl\u5931\u8d25\uff0c\u56de\u6eda\u64cd\u4f5c\u5f00\u9500\u5f88\u5927\u3002<\/li>\n<li>\u5982\u679conline ddl\u6267\u884c\u65f6\u95f4\u5f88\u957f\uff0c\u5c06\u4f1a\u5bfc\u81f4\u590d\u5236\u5ef6\u8fdf\u3002online ddl\u5fc5\u987b\u5728\u4e3b\u5e93\u6267\u884c\u5b8c\u6210\u4e4b\u540e\uff0c\u624d\u80fd\u5230\u4ece\u5e93\u6267\u884c\uff0c\u540c\u6837\u5730\uff0c\u5728\u4e3b\u5e93\u4e0a\u6267\u884c\u7684DML\uff0c\u5fc5\u987b\u7b49\u4ece\u5e93DDL\u6267\u884c\u5b8c\u6210\u540e\uff0c\u624d\u80fd\u5728\u4ece\u5e93\u5e94\u7528DML\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ol>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>MySQL InnoDB Online DDL \u63d0\u4f9b\u4e86\u5728\u7ebf\u8868\u53d8\u66f4\u7684\u80fd\u529b\uff0c\u5728\u8fdb\u884cDDL\u64cd\u4f5c\u7684\u540c\u65f6\uff0c\u4e0d\u5f71\u54cd\u6216\u8005\u5c3d\u53ef &hellip;<\/p>\n<p class=\"read-more\"> <a class=\"\" href=\"http:\/\/www.weijing.co\/?p=5369\"> <span class=\"screen-reader-text\">MySQL 8.0 Online DDL \u5728\u7ebf\u8868\u53d8\u66f4<\/span> \u67e5\u770b\u5168\u6587 &raquo;<\/a><\/p>\n","protected":false},"author":4,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"default","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","theme-transparent-header-meta":"default","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":""},"categories":[90,88],"tags":[],"uagb_featured_image_src":{"full":false,"thumbnail":false,"medium":false,"medium_large":false,"large":false,"1536x1536":false,"2048x2048":false,"mailpoet_newsletter_max":false,"woocommerce_thumbnail":false,"woocommerce_single":false,"woocommerce_gallery_thumbnail":false,"shop_catalog":false,"shop_single":false,"shop_thumbnail":false},"uagb_author_info":{"display_name":"weijing","author_link":"http:\/\/www.weijing.co\/?author=4"},"uagb_comment_info":0,"uagb_excerpt":"MySQL InnoDB Online DDL \u63d0\u4f9b\u4e86\u5728\u7ebf\u8868\u53d8\u66f4\u7684\u80fd\u529b\uff0c\u5728\u8fdb\u884cDDL\u64cd\u4f5c\u7684\u540c\u65f6\uff0c\u4e0d\u5f71\u54cd\u6216\u8005\u5c3d\u53ef&hellip;","_links":{"self":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts\/5369"}],"collection":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5369"}],"version-history":[{"count":0,"href":"http:\/\/www.weijing.co\/index.php?rest_route=\/wp\/v2\/posts\/5369\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5369"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5369"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.weijing.co\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5369"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}