{"id":92476,"date":"2026-08-10T12:40:48","date_gmt":"2026-08-10T04:40:48","guid":{"rendered":"https:\/\/www.wsisp.com\/helps\/92476.html"},"modified":"2026-08-10T12:40:48","modified_gmt":"2026-08-10T04:40:48","slug":"%e5%9b%9b%e3%80%81mysql%e7%ba%a6%e6%9d%9f","status":"publish","type":"post","link":"https:\/\/www.wsisp.com\/helps\/92476.html","title":{"rendered":"\u56db\u3001MySQL\u7ea6\u675f"},"content":{"rendered":"<h2>\u200b\u4e00\u3001\u57fa\u672c\u6982\u5ff5<\/h2>\n<h4>\u5b9a\u4e49<\/h4>\n<p>\u7ea6\u675f\u662f\u6570\u636e\u5e93\u4e2d\u7528\u4e8e\u9650\u5236\u8868\u6570\u636e\u7684\u89c4\u5219&#xff0c;\u901a\u8fc7\u7ea6\u675f\u53ef\u4ee5\u5f3a\u5236\u4fdd\u8bc1\u6570\u636e\u7684\u6b63\u786e\u6027\u3001\u6709\u6548\u6027\u548c\u5b8c\u6574\u6027&#xff0c;\u9632\u6b62\u975e\u6cd5\u6570\u636e\u8fdb\u5165\u6570\u636e\u5e93\u3002<\/p>\n<h4>\u4f5c\u7528<\/h4>\n<p>\u4fdd\u8bc1\u6570\u636e\u5b8c\u6574\u6027&#xff1a;\u786e\u4fdd\u6570\u636e\u7b26\u5408\u4e1a\u52a1\u903b\u8f91&#xff08;\u5982\u4e3b\u952e\u552f\u4e00\u6807\u8bc6\u3001\u5916\u952e\u5173\u8054\u4e00\u81f4\u6027&#xff09;&#xff1b;<br \/>\n\u9632\u6b62\u9519\u8bef\u6570\u636e&#xff1a;\u9650\u5236\u5b57\u6bb5\u503c\u8303\u56f4&#xff08;\u5982\u975e\u7a7a\u3001\u552f\u4e00\u3001\u68c0\u67e5\u7ea6\u675f&#xff09;&#xff0c;\u907f\u514d\u65e0\u6548\u6570\u636e&#xff08;\u5982\u7a7a\u503c\u3001\u91cd\u590d\u503c&#xff09;&#xff1b;<br \/>\n\u7ef4\u62a4\u6570\u636e\u4e00\u81f4\u6027&#xff1a;\u901a\u8fc7\u5916\u952e\u7ea6\u675f\u4fdd\u8bc1\u8868\u4e0e\u8868\u4e4b\u95f4\u7684\u5173\u8054\u5173\u7cfb&#xff08;\u5982\u5b50\u8868\u7684\u5916\u952e\u5fc5\u987b\u5bf9\u5e94\u7236\u8868\u7684\u4e3b\u952e&#xff09;\u3002<\/p>\n<h2>\u4e8c\u3001\u7ea6\u675f\u7684\u5206\u7c7b<\/h2>\n<p>\u6839\u636e\u7ea6\u675f\u7684\u529f\u80fd&#xff0c;\u53ef\u5206\u4e3a6\u7c7b&#xff0c;\u5bf9\u5e94\u4e0d\u540c\u7684\u5173\u952e\u5b57&#xff1a;<\/p>\n<table>\n<tr>\u7ea6\u675f\u7c7b\u578b\u63cf\u8ff0\u5173\u952e\u5b57<\/tr>\n<tbody>\n<tr>\n<td align=\"left\">\u975e\u7a7a\u7ea6\u675f<\/td>\n<td align=\"left\">\u9650\u5236\u5b57\u6bb5\u6570\u636e\u4e0d\u80fd\u4e3anull&#xff08;\u5fc5\u987b\u63d0\u4f9b\u503c&#xff09;\u3002<\/td>\n<td align=\"left\">NOT NULL<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">\u552f\u4e00\u7ea6\u675f<\/td>\n<td align=\"left\">\u4fdd\u8bc1\u5b57\u6bb5\u6240\u6709\u6570\u636e\u552f\u4e00\u3001\u4e0d\u91cd\u590d&#xff08;\u5141\u8bb8\u4e00\u4e2anull&#xff0c;\u4f46null\u4e0d\u89c6\u4e3a\u91cd\u590d&#xff09;\u3002<\/td>\n<td align=\"left\">UNIQUE<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">\u4e3b\u952e\u7ea6\u675f<\/td>\n<td align=\"left\">\u4e00\u884c\u6570\u636e\u7684\u552f\u4e00\u6807\u8bc6&#xff0c;\u8981\u6c42\u975e\u7a7a\u4e14\u552f\u4e00&#xff08;\u4e00\u4e2a\u8868\u53ea\u80fd\u6709\u4e00\u4e2a\u4e3b\u952e&#xff09;\u3002<\/td>\n<td align=\"left\">PRIMARY KEY<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">\u9ed8\u8ba4\u7ea6\u675f<\/td>\n<td align=\"left\">\u4fdd\u5b58\u6570\u636e\u65f6&#xff0c;\u82e5\u672a\u6307\u5b9a\u5b57\u6bb5\u503c&#xff0c;\u5219\u91c7\u7528\u9ed8\u8ba4\u503c&#xff08;\u5982DEFAULT 0&#xff09;\u3002<\/td>\n<td align=\"left\">DEFAULT<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">\u68c0\u67e5\u7ea6\u675f&#xff08;MySQL 8.0.16&#043;&#xff09;<\/td>\n<td align=\"left\">\u4fdd\u8bc1\u5b57\u6bb5\u503c\u6ee1\u8db3\u7279\u5b9a\u6761\u4ef6&#xff08;\u5982CHECK (age &gt; 0)&#xff09;\u3002<\/td>\n<td align=\"left\">CHECK<\/td>\n<\/tr>\n<tr>\n<td align=\"left\">\u5916\u952e\u7ea6\u675f<\/td>\n<td align=\"left\">\u8ba9\u4e24\u5f20\u8868\u5efa\u7acb\u8fde\u63a5&#xff0c;\u4fdd\u8bc1\u6570\u636e\u4e00\u81f4\u6027\u548c\u5b8c\u6574\u6027&#xff08;\u5b50\u8868\u7684\u5916\u952e\u5bf9\u5e94\u7236\u8868\u7684\u4e3b\u952e&#xff09;\u3002<\/td>\n<td align=\"left\">FOREIGN KEY<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>\u4e09\u3001\u5916\u952e\u7ea6\u675f\u7684\u5220\u9664\u66f4\u65b0\u884c\u4e3a<\/h2>\n<p>\u5916\u952e\u7ea6\u675f\u7684\u5220\u9664\/\u66f4\u65b0\u884c\u4e3a&#xff08;ON DELETE\/ON UPDATE&#xff09;\u7528\u4e8e\u5b9a\u4e49\u7236\u8868\u8bb0\u5f55\u53d8\u66f4\u65f6&#xff0c;\u5b50\u8868\u5bf9\u5e94\u5916\u952e\u8bb0\u5f55\u7684\u5904\u7406\u65b9\u5f0f\u3002\u5e38\u89c1\u884c\u4e3a\u5982\u4e0b&#xff1a;<\/p>\n<h4>1\u3001NO ACTION&#xff08;\u6216RESTRICT&#xff09;<\/h4>\n<p>\u8bf4\u660e&#xff1a;\u5f53\u7236\u8868\u5220\u9664\/\u66f4\u65b0\u8bb0\u5f55\u65f6&#xff0c;\u5148\u68c0\u67e5\u5b50\u8868\u662f\u5426\u6709\u5bf9\u5e94\u5916\u952e\u3002\u82e5\u6709&#xff0c;\u5219\u4e0d\u5141\u8bb8\u5220\u9664\/\u66f4\u65b0\u7236\u8868\u8bb0\u5f55&#xff08;\u963b\u6b62\u64cd\u4f5c&#xff09;\u3002<br \/>\n\u533a\u522b&#xff1a;NO ACTION\u662fSQL\u6807\u51c6\u884c\u4e3a&#xff0c;RESTRICT\u662fMySQL\u7684\u522b\u540d&#xff0c;\u4e24\u8005\u5b8c\u5168\u4e00\u81f4&#xff08;MySQL\u4e2d\u65e0\u5b9e\u9645\u533a\u522b&#xff09;\u3002<\/p>\n<h4>2\u3001CASCADE&#xff08;\u7ea7\u8054&#xff09;<\/h4>\n<p>\u8bf4\u660e&#xff1a;\u5f53\u7236\u8868\u5220\u9664\/\u66f4\u65b0\u8bb0\u5f55\u65f6&#xff0c;\u81ea\u52a8\u5220\u9664\/\u66f4\u65b0\u5b50\u8868\u4e2d\u5bf9\u5e94\u7684\u5916\u952e\u8bb0\u5f55\u3002<br \/>\n\u793a\u4f8b&#xff1a;\u7236\u8868parent\u7684\u4e3b\u952eid&#061;1\u88ab\u5220\u9664&#xff0c;\u5b50\u8868child\u4e2d\u5916\u952eparent_id&#061;1\u7684\u8bb0\u5f55\u4f1a\u88ab\u81ea\u52a8\u5220\u9664&#xff1b;\u82e5\u7236\u8868id&#061;1\u66f4\u65b0\u4e3aid&#061;2&#xff0c;\u5b50\u8868parent_id&#061;1\u4f1a\u88ab\u81ea\u52a8\u66f4\u65b0\u4e3a2\u3002<\/p>\n<h4>3\u3001SET NULL&#xff08;\u8bbe\u4e3a\u7a7a&#xff09;<\/h4>\n<p>\u8bf4\u660e&#xff1a;\u5f53\u7236\u8868\u5220\u9664\u8bb0\u5f55\u65f6&#xff0c;\u81ea\u52a8\u5c06\u5b50\u8868\u4e2d\u5bf9\u5e94\u7684\u5916\u952e\u503c\u8bbe\u4e3anull&#xff08;\u8981\u6c42\u5916\u952e\u5b57\u6bb5\u5141\u8bb8null&#xff0c;\u5426\u5219\u62a5\u9519&#xff09;\u3002<br \/>\n\u6ce8\u610f&#xff1a;SET NULL\u4ec5\u9002\u7528\u4e8e\u5220\u9664\u64cd\u4f5c&#xff08;\u66f4\u65b0\u64cd\u4f5c\u4e0d\u652f\u6301&#xff0c;\u56e0\u4e3a\u66f4\u65b0\u7236\u8868\u4e3b\u952e\u65f6&#xff0c;\u5b50\u8868\u5916\u952e\u5e94\u6539\u4e3a\u65b0\u503c&#xff0c;\u800c\u975enull&#xff09;\u3002<\/p>\n<h4>4\u3001SET DEFAULT&#xff08;\u8bbe\u4e3a\u9ed8\u8ba4\u503c&#xff09;<\/h4>\n<p>\u8bf4\u660e&#xff1a;\u5f53\u7236\u8868\u53d8\u66f4\u65f6&#xff0c;\u5b50\u8868\u5916\u952e\u5217\u8bbe\u4e3a\u9ed8\u8ba4\u503c&#xff08;\u5982DEFAULT 0&#xff09;\u3002<br \/>\n\u9650\u5236&#xff1a;MySQL\u7684InnoDB\u5f15\u64ce\u4e0d\u652f\u6301\u6b64\u884c\u4e3a&#xff08;\u4ec5MyISAM\u652f\u6301&#xff0c;\u4f46MyISAM\u65e0\u5916\u952e\u7ea6\u675f&#xff0c;\u6545\u5b9e\u9645\u65e0\u610f\u4e49&#xff09;\u3002<\/p>\n<h2>\u56db\u3001\u7ea6\u675f\u7ba1\u7406<\/h2>\n<h4>1\u3001\u67e5\u770b\u73b0\u6709\u7ea6\u675f<\/h4>\n<p>\u5728\u4fee\u6539\u4e4b\u524d&#xff0c;\u4f60\u5fc5\u987b\u5148\u77e5\u9053\u8868\u91cc\u6709\u4ec0\u4e48\u7ea6\u675f&#xff0c;\u4ee5\u53ca\u5b83\u4eec\u53eb\u4ec0\u4e48\u540d\u5b57&#xff08;\u7279\u522b\u662f\u5916\u952e\u548c\u7d22\u5f15\u540d&#xff09;\u3002<br \/>\n\u547d\u4ee4&#xff1a; SHOW CREATE TABLE \u8868\u540d;<br \/>\n\u573a\u666f&#xff1a; \u4f60\u63a5\u624b\u4e86\u4e00\u4e2a\u8001\u9879\u76ee&#xff0c;\u60f3\u77e5\u9053 orders \u8868\u91cc\u7684\u5916\u952e\u5230\u5e95\u53eb\u4ec0\u4e48\u540d\u5b57&#xff0c;\u6216\u8005\u60f3\u786e\u8ba4\u67d0\u4e2a\u5b57\u6bb5\u6709\u6ca1\u6709\u52a0\u552f\u4e00\u7d22\u5f15\u3002<\/p>\n<p><span class=\"token comment\">&#8212; \u67e5\u770b orders \u8868\u7684\u5b8c\u6574\u5efa\u8868\u8bed\u53e5&#xff0c;\u5305\u542b\u6240\u6709\u7ea6\u675f\u5b9a\u4e49<\/span><br \/>\n<span class=\"token keyword\">SHOW<\/span> <span class=\"token keyword\">CREATE<\/span> <span class=\"token keyword\">TABLE<\/span> orders<span class=\"token punctuation\">;<\/span><\/p>\n<p>\u8f93\u51fa\u7ed3\u679c\u4e2d&#xff0c;CONSTRAINT fk_xxx FOREIGN KEY&#8230; \u8fd9\u4e00\u884c\u91cc\u7684 fk_xxx \u5c31\u662f\u5916\u952e\u7684\u903b\u8f91\u540d\u79f0&#xff0c;\u5220\u9664\u65f6\u5fc5\u987b\u7528\u5b83\u3002\u800c UNIQUE KEY uk_xxx \u91cc\u7684 uk_xxx \u662f\u552f\u4e00\u7d22\u5f15\u7684\u540d\u79f0\u3002<\/p>\n<h4>2\u3001\u6dfb\u52a0\u65b0\u7ea6\u675f<\/h4>\n<p>\u5f53\u4e1a\u52a1\u89c4\u5219\u53d8\u4e25\u683c\u65f6&#xff08;\u4f8b\u5982&#xff1a;\u4ee5\u524d\u5141\u8bb8\u90ae\u7bb1\u4e3a\u7a7a&#xff0c;\u73b0\u5728\u5fc5\u987b\u5fc5\u586b\u4e14\u552f\u4e00&#xff09;&#xff0c;\u6211\u4eec\u9700\u8981\u6dfb\u52a0\u7ea6\u675f\u3002<br \/>\n\u6dfb\u52a0\u975e\u7a7a\/\u9ed8\u8ba4\/\u68c0\u67e5\u7ea6\u675f<br \/>\n\u8fd9\u7c7b\u7ea6\u675f\u76f4\u63a5\u4f9d\u9644\u4e8e\u5b57\u6bb5&#xff0c;\u4f7f\u7528 MODIFY \u4fee\u6539\u5b57\u6bb5\u5b9a\u4e49\u5373\u53ef\u3002<\/p>\n<p><span class=\"token comment\">&#8212; \u7ed9 email \u5b57\u6bb5\u6dfb\u52a0\u975e\u7a7a\u7ea6\u675f\u548c\u9ed8\u8ba4\u503c<\/span><br \/>\n<span class=\"token keyword\">ALTER<\/span> <span class=\"token keyword\">TABLE<\/span> users<br \/>\n<span class=\"token keyword\">MODIFY<\/span> <span class=\"token keyword\">COLUMN<\/span> email <span class=\"token keyword\">VARCHAR<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">100<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">NOT<\/span> <span class=\"token boolean\">NULL<\/span> <span class=\"token keyword\">DEFAULT<\/span> <span class=\"token string\">&#039;unknown&#064;example.com&#039;<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u6dfb\u52a0\u4e3b\u952e\u3001\u552f\u4e00\u3001\u5916\u952e\u7ea6\u675f<br \/>\n\u8fd9\u7c7b\u7ea6\u675f\u901a\u5e38\u4f5c\u4e3a\u8868\u7ea7\u5bf9\u8c61\u5b58\u5728\u3002<\/p>\n<p><span class=\"token comment\">&#8212; 1. \u6dfb\u52a0\u552f\u4e00\u7ea6\u675f (\u5047\u8bbe\u4e4b\u524d\u6ca1\u52a0)<\/span><br \/>\n<span class=\"token keyword\">ALTER<\/span> <span class=\"token keyword\">TABLE<\/span> users <span class=\"token keyword\">ADD<\/span> <span class=\"token keyword\">UNIQUE<\/span> <span class=\"token punctuation\">(<\/span>phone_number<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\">&#8212; 2. \u6dfb\u52a0\u5916\u952e\u7ea6\u675f (\u6700\u5e38\u7528)<\/span><br \/>\n<span class=\"token keyword\">ALTER<\/span> <span class=\"token keyword\">TABLE<\/span> orders<br \/>\n<span class=\"token keyword\">ADD<\/span> <span class=\"token keyword\">CONSTRAINT<\/span> fk_order_user<br \/>\n<span class=\"token keyword\">FOREIGN<\/span> <span class=\"token keyword\">KEY<\/span> <span class=\"token punctuation\">(<\/span>user_id<span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">REFERENCES<\/span> users<span class=\"token punctuation\">(<\/span>id<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>ADD CONSTRAINT \u540e\u9762\u7684\u540d\u5b57&#xff08;\u5982 fk_order_user&#xff09;\u662f\u4f60\u81ea\u5df1\u8d77\u7684&#xff0c;\u5efa\u8bae\u9075\u5faa fk_\u5b50\u8868_\u7236\u8868 \u7684\u547d\u540d\u89c4\u8303&#xff0c;\u65b9\u4fbf\u65e5\u540e\u7ef4\u62a4\u3002<\/p>\n<h4>3\u3001\u79fb\u9664\u7ea6\u675f<\/h4>\n<p>\u5f53\u4e1a\u52a1\u903b\u8f91\u53d8\u66f4&#xff0c;\u6216\u8005\u4e3a\u4e86\u4f18\u5316\u5199\u5165\u6027\u80fd&#xff08;\u9ad8\u5e76\u53d1\u7cfb\u7edf\u5e38\u53bb\u6389\u6570\u636e\u5e93\u5916\u952e&#xff09;&#xff0c;\u9700\u8981\u79fb\u9664\u7ea6\u675f\u3002<br \/>\n\u5220\u9664\u975e\u7a7a\/\u9ed8\u8ba4\u7ea6\u675f<br \/>\n\u540c\u6837\u901a\u8fc7 MODIFY \u5b57\u6bb5\u5b9a\u4e49\u6765\u201c\u8986\u76d6\u201d\u65e7\u89c4\u5219\u3002<\/p>\n<p><span class=\"token comment\">&#8212; \u53bb\u6389 status \u5b57\u6bb5\u7684\u975e\u7a7a\u7ea6\u675f&#xff08;\u5141\u8bb8\u4e3a\u7a7a&#xff09;<\/span><br \/>\n<span class=\"token keyword\">ALTER<\/span> <span class=\"token keyword\">TABLE<\/span> users<br \/>\n<span class=\"token keyword\">MODIFY<\/span> <span class=\"token keyword\">COLUMN<\/span> <span class=\"token keyword\">status<\/span> <span class=\"token keyword\">TINYINT<\/span> <span class=\"token boolean\">NULL<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u5220\u9664\u4e3b\u952e\u3001\u552f\u4e00\u3001\u5916\u952e\u7ea6\u675f<br \/>\n\u8fd9\u91cc\u8981\u6ce8\u610f\u8bed\u6cd5\u7684\u533a\u522b&#xff1a;<br \/>\n\u5220\u9664\u4e3b\u952e&#xff1a; \u4e00\u4e2a\u8868\u53ea\u6709\u4e00\u4e2a\u4e3b\u952e&#xff0c;\u4e0d\u9700\u8981\u540d\u5b57\u3002<\/p>\n<p><span class=\"token keyword\">ALTER<\/span> <span class=\"token keyword\">TABLE<\/span> users <span class=\"token keyword\">DROP<\/span> <span class=\"token keyword\">PRIMARY<\/span> <span class=\"token keyword\">KEY<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u5220\u9664\u552f\u4e00\u7ea6\u675f&#xff1a; \u5b9e\u9645\u4e0a\u5220\u7684\u662f\u5bf9\u5e94\u7684\u7d22\u5f15\u3002<\/p>\n<p><span class=\"token comment\">&#8212; \u8fd9\u91cc\u7684 uk_phone \u662f\u7d22\u5f15\u540d&#xff0c;\u4e0d\u662f\u5b57\u6bb5\u540d<\/span><br \/>\n<span class=\"token keyword\">ALTER<\/span> <span class=\"token keyword\">TABLE<\/span> users <span class=\"token keyword\">DROP<\/span> <span class=\"token keyword\">INDEX<\/span> uk_phone<span class=\"token punctuation\">;<\/span><\/p>\n<p>\u5220\u9664\u5916\u952e\u7ea6\u675f&#xff1a; \u5fc5\u987b\u6307\u5b9a\u5916\u952e\u540d\u79f0\u3002<\/p>\n<p><span class=\"token keyword\">ALTER<\/span> <span class=\"token keyword\">TABLE<\/span> orders <span class=\"token keyword\">DROP<\/span> <span class=\"token keyword\">FOREIGN<\/span> <span class=\"token keyword\">KEY<\/span> fk_order_user<span class=\"token punctuation\">;<\/span><\/p>\n<p>\u5220\u9664\u5916\u952e\u540e&#xff0c;\u5982\u679c\u8be5\u5916\u952e\u5b57\u6bb5\u4e0a\u81ea\u52a8\u751f\u6210\u7684\u7d22\u5f15\u4e5f\u4e0d\u518d\u9700\u8981&#xff0c;\u8bb0\u5f97\u624b\u52a8 DROP INDEX \u628a\u5b83\u4e5f\u5220\u6389&#xff0c;\u5426\u5219\u5b83\u4f1a\u7ee7\u7eed\u5360\u7528\u7a7a\u95f4\u5e76\u5f71\u54cd\u5199\u5165\u901f\u5ea6\u3002<\/p>\n<h4>4\u3001\u4fee\u6539\u7ea6\u675f<\/h4>\n<p>MySQL \u6ca1\u6709 ALTER CONSTRAINT \u8bed\u6cd5\u3002\u201c\u6539\u201d &#061; \u201c\u5148\u5220\u540e\u52a0\u201d\u3002<br \/>\n\u573a\u666f\u4e3e\u4f8b&#xff1a;<br \/>\n\u539f\u672c\u8ba2\u5355\u8868\u7684\u5916\u952e\u7b56\u7565\u662f\u201c\u7981\u6b62\u5220\u9664\u7528\u6237&#xff08;RESTRICT&#xff09;\u201d&#xff0c;\u73b0\u5728\u4e1a\u52a1\u53d8\u66f4\u4e3a\u201c\u5220\u9664\u7528\u6237\u65f6&#xff0c;\u5c06\u5176\u8ba2\u5355\u5f52\u5c5e\u7f6e\u7a7a&#xff08;SET NULL&#xff09;\u201d\u3002<\/p>\n<p><span class=\"token comment\">&#8212; \u7b2c\u4e00\u6b65&#xff1a;\u67e5\u540d\u5b57&#xff08;\u5982\u679c\u4e0d\u786e\u5b9a&#xff09;<\/span><br \/>\n<span class=\"token keyword\">SHOW<\/span> <span class=\"token keyword\">CREATE<\/span> <span class=\"token keyword\">TABLE<\/span> orders<span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token comment\">&#8212; \u5047\u8bbe\u67e5\u5230\u5916\u952e\u540d\u53eb fk_order_user<\/span><\/p>\n<p><span class=\"token comment\">&#8212; \u7b2c\u4e8c\u6b65&#xff1a;\u5220\u6389\u65e7\u7684\u5916\u952e\u7ea6\u675f<\/span><br \/>\n<span class=\"token keyword\">ALTER<\/span> <span class=\"token keyword\">TABLE<\/span> orders <span class=\"token keyword\">DROP<\/span> <span class=\"token keyword\">FOREIGN<\/span> <span class=\"token keyword\">KEY<\/span> fk_order_user<span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\">&#8212; \u7b2c\u4e09\u6b65&#xff1a;\u52a0\u4e0a\u65b0\u7684\u5916\u952e\u7ea6\u675f&#xff08;\u5e26\u65b0\u7684\u7ea7\u8054\u7b56\u7565&#xff09;<\/span><br \/>\n<span class=\"token keyword\">ALTER<\/span> <span class=\"token keyword\">TABLE<\/span> orders<br \/>\n<span class=\"token keyword\">ADD<\/span> <span class=\"token keyword\">CONSTRAINT<\/span> fk_order_user_new  <span class=\"token comment\">&#8212; \u5efa\u8bae\u6362\u4e2a\u65b0\u540d\u5b57&#xff0c;\u6216\u8005\u6cbf\u7528\u65e7\u540d<\/span><br \/>\n<span class=\"token keyword\">FOREIGN<\/span> <span class=\"token keyword\">KEY<\/span> <span class=\"token punctuation\">(<\/span>user_id<span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">REFERENCES<\/span> users<span class=\"token punctuation\">(<\/span>id<span class=\"token punctuation\">)<\/span><br \/>\n<span class=\"token keyword\">ON<\/span> <span class=\"token keyword\">DELETE<\/span> <span class=\"token keyword\">SET<\/span> <span class=\"token boolean\">NULL<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<h2>\u4e94\u3001\u7ea6\u675f\u8bbe\u8ba1\u6700\u4f73\u5b9e\u8df5<\/h2>\n<ul>\n<li>\u4e3b\u952e\u9009\u62e9&#xff1a;\u4f18\u5148\u4f7f\u7528\u65e0\u4e1a\u52a1\u542b\u4e49\u7684\u81ea\u589e\u6574\u6570&#xff08;\u5982 AUTO_INCREMENT&#xff09;&#xff0c;\u907f\u514d\u56e0\u4e1a\u52a1\u53d8\u5316\u800c\u4fee\u6539\u4e3b\u952e\u3002<\/li>\n<li>\u5916\u952e\u547d\u540d&#xff1a;\u4f7f\u7528 fk_\u5b50\u8868_\u7236\u8868 \u7684\u547d\u540d\u89c4\u8303&#xff0c;\u4fbf\u4e8e\u7406\u89e3\u548c\u7ef4\u62a4\u3002<\/li>\n<li>\u68c0\u67e5\u7ea6\u675f&#xff1a;\u5728 MySQL 8.0.16 \u53ca\u4ee5\u4e0a\u7248\u672c\u4e2d\u79ef\u6781\u4f7f\u7528&#xff0c;\u5c06\u6570\u636e\u9a8c\u8bc1\u903b\u8f91\u4e0b\u6c89\u5230\u6570\u636e\u5e93\u5c42\u3002<\/li>\n<li>\u6027\u80fd\u8003\u91cf&#xff1a;\u5916\u952e\u7ea6\u675f\u4f1a\u5e26\u6765\u4e00\u5b9a\u7684\u6027\u80fd\u5f00\u9500&#xff0c;\u5728\u5199\u5165\u9891\u7e41\u7684\u8d85\u5927\u578b\u8868\u4e2d\u9700\u8c28\u614e\u8bc4\u4f30\u3002\u4f46\u901a\u5e38\u5176\u5e26\u6765\u7684\u6570\u636e\u4e00\u81f4\u6027\u4fdd\u969c\u8fdc\u5927\u4e8e\u6027\u80fd\u635f\u5931\u3002<\/li>\n<li>\u4e1a\u52a1\u5339\u914d&#xff1a;\u6839\u636e\u4e1a\u52a1\u903b\u8f91\u4ed4\u7ec6\u9009\u62e9 ON DELETE \u548c ON UPDATE \u884c\u4e3a&#xff0c;\u4f8b\u5982&#xff1a;\n<ul>\n<li>\u6838\u5fc3\u4e1a\u52a1\u6570\u636e\u5173\u8054&#xff08;\u5982\u8ba2\u5355-\u7528\u6237&#xff09;\u4f7f\u7528 RESTRICT \u6216 CASCADE\u3002<\/li>\n<li>\u65e5\u5fd7\u3001\u5386\u53f2\u8bb0\u5f55\u7b49\u53ef\u72ec\u7acb\u5b58\u5728\u7684\u6570\u636e\u5173\u8054\u53ef\u4f7f\u7528 SET NULL\u3002<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<h2>\u516d\u3001\u7efc\u5408\u793a\u4f8b<\/h2>\n<p>\u573a\u666f\u80cc\u666f&#xff1a;\u7535\u5546\u7cfb\u7edf\u7684\u201c\u7528\u6237\u201d\u4e0e\u201c\u8ba2\u5355\u201d<br \/>\n\u5047\u8bbe\u6211\u4eec\u6b63\u5728\u4e3a\u4e00\u4e2a\u7535\u5546\u5e73\u53f0\u8bbe\u8ba1\u6570\u636e\u5e93\u3002\u8fd9\u91cc\u6709\u4e24\u4e2a\u6838\u5fc3\u89d2\u8272&#xff1a;<br \/>\n\u7528\u6237\u8868 (users)&#xff1a;\u4e5f\u5c31\u662f\u201c\u7236\u8868\u201d\u3002<br \/>\n\u8ba2\u5355\u8868 (orders)&#xff1a;\u4e5f\u5c31\u662f\u201c\u5b50\u8868\u201d\u3002<br \/>\n\u4e1a\u52a1\u903b\u8f91\u662f&#xff1a;\u4e00\u4e2a\u7528\u6237\u53ef\u4ee5\u4e0b\u591a\u4e2a\u8ba2\u5355&#xff0c;\u4f46\u4e00\u4e2a\u8ba2\u5355\u5fc5\u987b\u5c5e\u4e8e\u67d0\u4e00\u4e2a\u7528\u6237\u3002\u5982\u679c\u7528\u6237\u6ce8\u9500\u4e86&#xff0c;\u4ed6\u7684\u8ba2\u5355\u8be5\u600e\u4e48\u5904\u7406&#xff1f;\u8fd9\u5c31\u662f\u6211\u4eec\u8981\u901a\u8fc7\u7ea6\u675f\u6765\u89e3\u51b3\u7684\u95ee\u9898\u3002<\/p>\n<h4>1\u3001\u5efa\u8868\u5b9e\u6218&#xff08;\u7efc\u5408\u5e94\u7528\u7ea6\u675f&#xff09;<\/h4>\n<p>\u8bf7\u770b\u4e0b\u9762\u7684 SQL \u4ee3\u7801&#xff0c;\u6211\u4f1a\u5728\u4ee3\u7801\u6ce8\u91ca\u4e2d\u4e3a\u4f60\u62c6\u89e3\u6bcf\u4e00\u4e2a\u7ea6\u675f\u7684\u4f5c\u7528&#xff1a;<\/p>\n<p><span class=\"token comment\">&#8212; 1. \u521b\u5efa\u7236\u8868&#xff1a;\u7528\u6237\u8868<\/span><br \/>\n<span class=\"token keyword\">CREATE<\/span> <span class=\"token keyword\">TABLE<\/span> users <span class=\"token punctuation\">(<\/span><br \/>\n    user_id <span class=\"token keyword\">INT<\/span> <span class=\"token keyword\">PRIMARY<\/span> <span class=\"token keyword\">KEY<\/span><span class=\"token punctuation\">,<\/span>          <span class=\"token comment\">&#8212; \u3010\u4e3b\u952e\u7ea6\u675f\u3011&#xff1a;\u7528\u6237\u7684\u552f\u4e00\u8eab\u4efd\u8bc1&#xff0c;\u975e\u7a7a\u4e14\u552f\u4e00<\/span><br \/>\n    username <span class=\"token keyword\">VARCHAR<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">50<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token operator\">NOT<\/span> <span class=\"token boolean\">NULL<\/span><span class=\"token punctuation\">,<\/span>    <span class=\"token comment\">&#8212; \u3010\u975e\u7a7a\u7ea6\u675f\u3011&#xff1a;\u6ce8\u518c\u65f6\u5fc5\u987b\u586b\u540d\u5b57&#xff0c;\u4e0d\u80fd\u7559\u7a7a<\/span><br \/>\n    email <span class=\"token keyword\">VARCHAR<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">100<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">UNIQUE<\/span><span class=\"token punctuation\">,<\/span>        <span class=\"token comment\">&#8212; \u3010\u552f\u4e00\u7ea6\u675f\u3011&#xff1a;\u90ae\u7bb1\u4e0d\u80fd\u91cd\u590d&#xff0c;\u9632\u6b62\u4e24\u4eba\u7528\u540c\u4e00\u4e2a\u90ae\u7bb1\u6ce8\u518c<\/span><br \/>\n    <span class=\"token keyword\">status<\/span> <span class=\"token keyword\">TINYINT<\/span> <span class=\"token keyword\">DEFAULT<\/span> <span class=\"token number\">1<\/span>          <span class=\"token comment\">&#8212; \u3010\u9ed8\u8ba4\u7ea6\u675f\u3011&#xff1a;\u5982\u679c\u4e0d\u586b\u72b6\u6001&#xff0c;\u9ed8\u8ba4\u4e3a1&#xff08;\u4ee3\u8868\u201c\u6b63\u5e38\u201d&#xff09;<\/span><br \/>\n<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\">&#8212; 2. \u521b\u5efa\u5b50\u8868&#xff1a;\u8ba2\u5355\u8868<\/span><br \/>\n<span class=\"token keyword\">CREATE<\/span> <span class=\"token keyword\">TABLE<\/span> orders <span class=\"token punctuation\">(<\/span><br \/>\n    order_id <span class=\"token keyword\">INT<\/span> <span class=\"token keyword\">PRIMARY<\/span> <span class=\"token keyword\">KEY<\/span><span class=\"token punctuation\">,<\/span>         <span class=\"token comment\">&#8212; \u3010\u4e3b\u952e\u7ea6\u675f\u3011&#xff1a;\u8ba2\u5355\u53f7\u552f\u4e00<\/span><br \/>\n    user_id <span class=\"token keyword\">INT<\/span><span class=\"token punctuation\">,<\/span>                      <span class=\"token comment\">&#8212; \u8fd9\u662f\u4e00\u4e2a\u666e\u901a\u5b57\u6bb5&#xff0c;\u51c6\u5907\u7528\u6765\u505a\u5916\u952e<\/span><br \/>\n    amount <span class=\"token keyword\">DECIMAL<\/span><span class=\"token punctuation\">(<\/span><span class=\"token number\">10<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">2<\/span><span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">CHECK<\/span> <span class=\"token punctuation\">(<\/span>amount <span class=\"token operator\">&gt;<\/span> <span class=\"token number\">0<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token comment\">&#8212; \u3010\u68c0\u67e5\u7ea6\u675f\u3011&#xff1a;\u8ba2\u5355\u91d1\u989d\u5fc5\u987b\u5927\u4e8e0&#xff0c;\u9632\u6b62\u5f55\u5165\u8d1f\u6570\u91d1\u989d<\/span><br \/>\n    create_time <span class=\"token keyword\">DATETIME<\/span><span class=\"token punctuation\">,<\/span><\/p>\n<p>    <span class=\"token comment\">&#8212; \u3010\u5916\u952e\u7ea6\u675f\u3011\u6838\u5fc3\u767b\u573a&#xff01;<\/span><br \/>\n    <span class=\"token keyword\">CONSTRAINT<\/span> fk_user_order          <span class=\"token comment\">&#8212; \u7ed9\u8fd9\u4e2a\u5916\u952e\u5173\u7cfb\u8d77\u4e2a\u540d\u5b57&#xff0c;\u65b9\u4fbf\u7ba1\u7406<\/span><br \/>\n    <span class=\"token keyword\">FOREIGN<\/span> <span class=\"token keyword\">KEY<\/span> <span class=\"token punctuation\">(<\/span>user_id<span class=\"token punctuation\">)<\/span>             <span class=\"token comment\">&#8212; \u5b50\u8868\u7684\u54ea\u4e2a\u5b57\u6bb5\u662f\u5916\u952e&#xff1f;\u662f user_id<\/span><br \/>\n    <span class=\"token keyword\">REFERENCES<\/span> users<span class=\"token punctuation\">(<\/span>user_id<span class=\"token punctuation\">)<\/span>         <span class=\"token comment\">&#8212; \u5b83\u5173\u8054\u7684\u662f\u7236\u8868(users)\u7684\u54ea\u4e2a\u5b57\u6bb5&#xff1f;\u662f user_id<\/span><br \/>\n    <span class=\"token keyword\">ON<\/span> <span class=\"token keyword\">DELETE<\/span> <span class=\"token keyword\">CASCADE<\/span>                 <span class=\"token comment\">&#8212; \u3010\u5220\u9664\u884c\u4e3a\u3011&#xff1a;\u7236\u8868\u5220\u4eba&#xff0c;\u5b50\u8868\u8ba2\u5355\u8ddf\u7740\u5220&#xff08;\u7ea7\u8054\u5220\u9664&#xff09;<\/span><br \/>\n    <span class=\"token keyword\">ON<\/span> <span class=\"token keyword\">UPDATE<\/span> <span class=\"token keyword\">CASCADE<\/span>                 <span class=\"token comment\">&#8212; \u3010\u66f4\u65b0\u884c\u4e3a\u3011&#xff1a;\u7236\u8868\u6539ID&#xff0c;\u5b50\u8868\u8ba2\u5355\u8ddf\u7740\u6539&#xff08;\u7ea7\u8054\u66f4\u65b0&#xff09;<\/span><br \/>\n<span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<h4>2\u3001\u6df1\u5ea6\u89e3\u6790&#xff1a;\u5916\u952e\u7684\u5220\u9664\u4e0e\u66f4\u65b0\u884c\u4e3a<\/h4>\n<p>\u5728\u8fd9\u4e2a\u4f8b\u5b50\u4e2d&#xff0c;\u6211\u4eec\u5728 orders \u8868\u8bbe\u7f6e\u4e86 ON DELETE CASCADE \u548c ON UPDATE CASCADE\u3002\u8ba9\u6211\u4eec\u770b\u770b\u5728\u5b9e\u9645\u64cd\u4f5c\u4e2d\u4f1a\u53d1\u751f\u4ec0\u4e48\u795e\u5947\u7684\u4e8b\u60c5\u3002<\/p>\n<p>\u573a\u666f A&#xff1a;\u6b63\u5e38\u7684\u63d2\u5165&#xff08;\u68c0\u67e5\u7ea6\u675f\u4e0e\u975e\u7a7a\u7ea6\u675f&#xff09;<\/p>\n<p><span class=\"token comment\">&#8212; \u63d2\u5165\u4e00\u4e2a\u6b63\u5e38\u7528\u6237<\/span><br \/>\n<span class=\"token keyword\">INSERT<\/span> <span class=\"token keyword\">INTO<\/span> users <span class=\"token punctuation\">(<\/span>user_id<span class=\"token punctuation\">,<\/span> username<span class=\"token punctuation\">,<\/span> email<span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">VALUES<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token number\">1<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#039;\u5f20\u4e09&#039;<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token string\">&#039;zhang&#064;test.com&#039;<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p><span class=\"token comment\">&#8212; \u63d2\u5165\u4e00\u4e2a\u8ba2\u5355&#xff0c;\u91d1\u989d\u4e3a 100<\/span><br \/>\n<span class=\"token keyword\">INSERT<\/span> <span class=\"token keyword\">INTO<\/span> orders <span class=\"token punctuation\">(<\/span>order_id<span class=\"token punctuation\">,<\/span> user_id<span class=\"token punctuation\">,<\/span> amount<span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">VALUES<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token number\">1001<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">100.00<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token comment\">&#8212; \u6210\u529f&#xff01;\u56e0\u4e3a\u7528\u62371\u5b58\u5728&#xff0c;\u4e14\u91d1\u989d\u5927\u4e8e0\u3002<\/span><\/p>\n<p><span class=\"token comment\">&#8212; \u5c1d\u8bd5\u63d2\u5165\u4e00\u4e2a\u91d1\u989d\u4e3a -50 \u7684\u8ba2\u5355<\/span><br \/>\n<span class=\"token keyword\">INSERT<\/span> <span class=\"token keyword\">INTO<\/span> orders <span class=\"token punctuation\">(<\/span>order_id<span class=\"token punctuation\">,<\/span> user_id<span class=\"token punctuation\">,<\/span> amount<span class=\"token punctuation\">)<\/span> <span class=\"token keyword\">VALUES<\/span> <span class=\"token punctuation\">(<\/span><span class=\"token number\">1002<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">,<\/span> <span class=\"token operator\">&#8211;<\/span><span class=\"token number\">50.00<\/span><span class=\"token punctuation\">)<\/span><span class=\"token punctuation\">;<\/span><br \/>\n<span class=\"token comment\">&#8212; \u62a5\u9519&#xff01;\u8fdd\u53cd\u4e86 CHECK (amount &gt; 0) \u68c0\u67e5\u7ea6\u675f\u3002<\/span><\/p>\n<p>\u573a\u666f B&#xff1a;\u5916\u952e\u7684\u201c\u8fde\u5750\u201d\u673a\u5236&#xff08;CASCADE&#xff09;<\/p>\n<p>\u8fd9\u662f\u5916\u952e\u6700\u5f3a\u5927\u7684\u5730\u65b9\u3002\u6ce8\u610f\u770b\u6211\u4eec\u8bbe\u7f6e\u7684 ON DELETE CASCADE&#xff08;\u7ea7\u8054\u5220\u9664&#xff09;\u3002<br \/>\n\u64cd\u4f5c&#xff1a; \u7ba1\u7406\u5458\u51b3\u5b9a\u5c01\u7981\u5e76\u5220\u9664\u201c\u5f20\u4e09\u201d\u8fd9\u4e2a\u7528\u6237\u3002<\/p>\n<p><span class=\"token keyword\">DELETE<\/span> <span class=\"token keyword\">FROM<\/span> users <span class=\"token keyword\">WHERE<\/span> user_id <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u7ed3\u679c&#xff1a;<\/p>\n<ul>\n<li>users \u8868\u4e2d user_id &#061; 1 \u7684\u8bb0\u5f55\u88ab\u5220\u9664\u4e86\u3002<\/li>\n<li>\u5173\u952e\u70b9\u6765\u4e86&#xff1a;MySQL \u4f1a\u81ea\u52a8\u53bb orders \u8868\u91cc\u627e&#xff0c;\u53d1\u73b0\u8ba2\u5355 1001 \u662f\u5c5e\u4e8e\u7528\u6237 1 \u7684\u3002<\/li>\n<li>\u56e0\u4e3a\u8bbe\u7f6e\u4e86 CASCADE&#xff0c;\u8ba2\u5355 1001 \u4e5f\u4f1a\u88ab\u81ea\u52a8\u5220\u9664&#xff01;<\/li>\n<\/ul>\n<p>\u573a\u666f C&#xff1a;\u5982\u679c\u60f3\u4fdd\u7559\u8ba2\u5355\u600e\u4e48\u529e&#xff1f;&#xff08;SET NULL&#xff09;<\/p>\n<p>\u5982\u679c\u5728\u5b9e\u9645\u4e1a\u52a1\u4e2d&#xff0c;\u5373\u4fbf\u7528\u6237\u6ce8\u9500\u4e86&#xff0c;\u6211\u4eec\u4e5f\u60f3\u4fdd\u7559\u4ed6\u7684\u8ba2\u5355\u8bb0\u5f55\u7528\u4e8e\u8d22\u52a1\u5ba1\u8ba1&#xff0c;\u6211\u4eec\u5c31\u4e0d\u80fd\u7528 CASCADE \u4e86&#xff0c;\u800c\u5e94\u8be5\u5728\u5efa\u8868\u65f6\u4f7f\u7528 ON DELETE SET NULL\u3002<br \/>\n\u5047\u8bbe\u6211\u4eec\u4fee\u6539\u4e86\u5916\u952e\u7b56\u7565\u4e3a SET NULL&#xff1a;<br \/>\n\u64cd\u4f5c&#xff1a; \u518d\u6b21\u5220\u9664\u7528\u6237 1\u3002<\/p>\n<p><span class=\"token keyword\">DELETE<\/span> <span class=\"token keyword\">FROM<\/span> users <span class=\"token keyword\">WHERE<\/span> user_id <span class=\"token operator\">&#061;<\/span> <span class=\"token number\">1<\/span><span class=\"token punctuation\">;<\/span><\/p>\n<p>\u7ed3\u679c&#xff1a;<\/p>\n<ul>\n<li>users \u8868\u4e2d\u7528\u6237 1 \u6ca1\u4e86\u3002<\/li>\n<li>orders \u8868\u4e2d&#xff0c;\u8ba2\u5355 1001 \u4f9d\u7136\u5b58\u5728&#xff01;<\/li>\n<li>\u4f46\u662f&#xff0c;\u8ba2\u5355 1001 \u7684 user_id \u5b57\u6bb5\u53d8\u6210\u4e86 NULL\u3002<\/li>\n<li>\u6ce8\u610f&#xff1a;\u5982\u679c\u8981\u4f7f\u7528 SET NULL&#xff0c;\u4f60\u7684\u5b50\u8868\u5916\u952e\u5b57\u6bb5&#xff08;user_id&#xff09;\u5fc5\u987b\u5141\u8bb8\u4e3a NULL&#xff08;\u5373\u5efa\u8868\u65f6\u4e0d\u80fd\u52a0 NOT NULL&#xff09;\u3002<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>\u200b\u4e00\u3001\u57fa\u672c\u6982\u5ff5<br \/>\n\u5b9a\u4e49<br \/>\n\u7ea6\u675f\u662f\u6570\u636e\u5e93\u4e2d\u7528\u4e8e\u9650\u5236\u8868\u6570\u636e\u7684\u89c4\u5219&#xff0c;\u901a\u8fc7\u7ea6\u675f\u53ef\u4ee5\u5f3a\u5236\u4fdd\u8bc1\u6570\u636e\u7684\u6b63\u786e\u6027\u3001\u6709\u6548\u6027\u548c\u5b8c\u6574\u6027&#xff0c;\u9632\u6b62\u975e\u6cd5\u6570\u636e\u8fdb\u5165\u6570\u636e\u5e93\u3002<br \/>\n\u4f5c\u7528<br \/>\n\u4fdd\u8bc1\u6570\u636e\u5b8c\u6574\u6027&#xff1a;\u786e\u4fdd\u6570\u636e\u7b26\u5408\u4e1a\u52a1\u903b\u8f91&#xff08;\u5982\u4e3b\u952e\u552f\u4e00\u6807\u8bc6\u3001\u5916\u952e\u5173\u8054\u4e00\u81f4\u6027&#xff09;&#xff1b;<br \/>\n\u9632\u6b62\u9519\u8bef\u6570\u636e&#xff1a;\u9650\u5236\u5b57\u6bb5\u503c\u8303\u56f4&#xff08;\u5982\u975e\u7a7a\u3001\u552f\u4e00\u3001\u68c0\u67e5\u7ea6\u675f&#xff09;&#xff0c;\u907f\u514d\u65e0\u6548\u6570\u636e&#xff08;\u5982\u7a7a\u503c\u3001\u91cd\u590d\u503c&#xff09;&amp;#xff1<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[114,100],"topic":[],"class_list":["post-92476","post","type-post","status-publish","format-standard","hentry","category-server","tag-mysql","tag-100"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.3 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>\u56db\u3001MySQL\u7ea6\u675f - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.wsisp.com\/helps\/92476.html\" \/>\n<meta property=\"og:locale\" content=\"zh_CN\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"\u56db\u3001MySQL\u7ea6\u675f - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"og:description\" content=\"\u200b\u4e00\u3001\u57fa\u672c\u6982\u5ff5 \u5b9a\u4e49 \u7ea6\u675f\u662f\u6570\u636e\u5e93\u4e2d\u7528\u4e8e\u9650\u5236\u8868\u6570\u636e\u7684\u89c4\u5219&#xff0c;\u901a\u8fc7\u7ea6\u675f\u53ef\u4ee5\u5f3a\u5236\u4fdd\u8bc1\u6570\u636e\u7684\u6b63\u786e\u6027\u3001\u6709\u6548\u6027\u548c\u5b8c\u6574\u6027&#xff0c;\u9632\u6b62\u975e\u6cd5\u6570\u636e\u8fdb\u5165\u6570\u636e\u5e93\u3002 \u4f5c\u7528 \u4fdd\u8bc1\u6570\u636e\u5b8c\u6574\u6027&#xff1a;\u786e\u4fdd\u6570\u636e\u7b26\u5408\u4e1a\u52a1\u903b\u8f91&#xff08;\u5982\u4e3b\u952e\u552f\u4e00\u6807\u8bc6\u3001\u5916\u952e\u5173\u8054\u4e00\u81f4\u6027&#xff09;&#xff1b; \u9632\u6b62\u9519\u8bef\u6570\u636e&#xff1a;\u9650\u5236\u5b57\u6bb5\u503c\u8303\u56f4&#xff08;\u5982\u975e\u7a7a\u3001\u552f\u4e00\u3001\u68c0\u67e5\u7ea6\u675f&#xff09;&#xff0c;\u907f\u514d\u65e0\u6548\u6570\u636e&#xff08;\u5982\u7a7a\u503c\u3001\u91cd\u590d\u503c&#xff09;&amp;#xff1\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.wsisp.com\/helps\/92476.html\" \/>\n<meta property=\"og:site_name\" content=\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\" \/>\n<meta property=\"article:published_time\" content=\"2026-08-10T04:40:48+00:00\" \/>\n<meta name=\"author\" content=\"admin\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u4f5c\u8005\" \/>\n\t<meta name=\"twitter:data1\" content=\"admin\" \/>\n\t<meta name=\"twitter:label2\" content=\"\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4\" \/>\n\t<meta name=\"twitter:data2\" content=\"4 \u5206\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/92476.html\",\"url\":\"https:\/\/www.wsisp.com\/helps\/92476.html\",\"name\":\"\u56db\u3001MySQL\u7ea6\u675f - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"isPartOf\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\"},\"datePublished\":\"2026-08-10T04:40:48+00:00\",\"dateModified\":\"2026-08-10T04:40:48+00:00\",\"author\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\"},\"breadcrumb\":{\"@id\":\"https:\/\/www.wsisp.com\/helps\/92476.html#breadcrumb\"},\"inLanguage\":\"zh-Hans\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/www.wsisp.com\/helps\/92476.html\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/92476.html#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"\u9996\u9875\",\"item\":\"https:\/\/www.wsisp.com\/helps\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"\u56db\u3001MySQL\u7ea6\u675f\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#website\",\"url\":\"https:\/\/www.wsisp.com\/helps\/\",\"name\":\"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3\",\"description\":\"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"zh-Hans\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41\",\"name\":\"admin\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"zh-Hans\",\"@id\":\"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"contentUrl\":\"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery\",\"caption\":\"admin\"},\"sameAs\":[\"http:\/\/wp.wsisp.com\"],\"url\":\"https:\/\/www.wsisp.com\/helps\/author\/admin\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"\u56db\u3001MySQL\u7ea6\u675f - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.wsisp.com\/helps\/92476.html","og_locale":"zh_CN","og_type":"article","og_title":"\u56db\u3001MySQL\u7ea6\u675f - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","og_description":"\u200b\u4e00\u3001\u57fa\u672c\u6982\u5ff5 \u5b9a\u4e49 \u7ea6\u675f\u662f\u6570\u636e\u5e93\u4e2d\u7528\u4e8e\u9650\u5236\u8868\u6570\u636e\u7684\u89c4\u5219&#xff0c;\u901a\u8fc7\u7ea6\u675f\u53ef\u4ee5\u5f3a\u5236\u4fdd\u8bc1\u6570\u636e\u7684\u6b63\u786e\u6027\u3001\u6709\u6548\u6027\u548c\u5b8c\u6574\u6027&#xff0c;\u9632\u6b62\u975e\u6cd5\u6570\u636e\u8fdb\u5165\u6570\u636e\u5e93\u3002 \u4f5c\u7528 \u4fdd\u8bc1\u6570\u636e\u5b8c\u6574\u6027&#xff1a;\u786e\u4fdd\u6570\u636e\u7b26\u5408\u4e1a\u52a1\u903b\u8f91&#xff08;\u5982\u4e3b\u952e\u552f\u4e00\u6807\u8bc6\u3001\u5916\u952e\u5173\u8054\u4e00\u81f4\u6027&#xff09;&#xff1b; \u9632\u6b62\u9519\u8bef\u6570\u636e&#xff1a;\u9650\u5236\u5b57\u6bb5\u503c\u8303\u56f4&#xff08;\u5982\u975e\u7a7a\u3001\u552f\u4e00\u3001\u68c0\u67e5\u7ea6\u675f&#xff09;&#xff0c;\u907f\u514d\u65e0\u6548\u6570\u636e&#xff08;\u5982\u7a7a\u503c\u3001\u91cd\u590d\u503c&#xff09;&amp;#xff1","og_url":"https:\/\/www.wsisp.com\/helps\/92476.html","og_site_name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","article_published_time":"2026-08-10T04:40:48+00:00","author":"admin","twitter_card":"summary_large_image","twitter_misc":{"\u4f5c\u8005":"admin","\u9884\u8ba1\u9605\u8bfb\u65f6\u95f4":"4 \u5206"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.wsisp.com\/helps\/92476.html","url":"https:\/\/www.wsisp.com\/helps\/92476.html","name":"\u56db\u3001MySQL\u7ea6\u675f - \u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","isPartOf":{"@id":"https:\/\/www.wsisp.com\/helps\/#website"},"datePublished":"2026-08-10T04:40:48+00:00","dateModified":"2026-08-10T04:40:48+00:00","author":{"@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41"},"breadcrumb":{"@id":"https:\/\/www.wsisp.com\/helps\/92476.html#breadcrumb"},"inLanguage":"zh-Hans","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.wsisp.com\/helps\/92476.html"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/www.wsisp.com\/helps\/92476.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"\u9996\u9875","item":"https:\/\/www.wsisp.com\/helps"},{"@type":"ListItem","position":2,"name":"\u56db\u3001MySQL\u7ea6\u675f"}]},{"@type":"WebSite","@id":"https:\/\/www.wsisp.com\/helps\/#website","url":"https:\/\/www.wsisp.com\/helps\/","name":"\u7f51\u7855\u4e92\u8054\u5e2e\u52a9\u4e2d\u5fc3","description":"\u9999\u6e2f\u670d\u52a1\u5668_\u9999\u6e2f\u4e91\u670d\u52a1\u5668\u8d44\u8baf_\u670d\u52a1\u5668\u5e2e\u52a9\u6587\u6863_\u670d\u52a1\u5668\u6559\u7a0b","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.wsisp.com\/helps\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"zh-Hans"},{"@type":"Person","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/358e386c577a3ab51c4493330a20ad41","name":"admin","image":{"@type":"ImageObject","inLanguage":"zh-Hans","@id":"https:\/\/www.wsisp.com\/helps\/#\/schema\/person\/image\/","url":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","contentUrl":"https:\/\/gravatar.wp-china-yes.net\/avatar\/?s=96&d=mystery","caption":"admin"},"sameAs":["http:\/\/wp.wsisp.com"],"url":"https:\/\/www.wsisp.com\/helps\/author\/admin"}]}},"_links":{"self":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/92476","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/comments?post=92476"}],"version-history":[{"count":0,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/posts\/92476\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/media?parent=92476"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/categories?post=92476"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/tags?post=92476"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.wsisp.com\/helps\/wp-json\/wp\/v2\/topic?post=92476"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}