{"id":6162,"date":"2024-11-14T09:41:56","date_gmt":"2024-11-14T01:41:56","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6162\/"},"modified":"2024-11-14T09:41:56","modified_gmt":"2024-11-14T01:41:56","slug":"mysql%e5%a6%82%e4%bd%95%e5%88%a0%e9%99%a4%e5%a4%96%e9%94%ae%e7%ba%a6%e6%9d%9f","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6162\/","title":{"rendered":"mysql\u5982\u4f55\u5220\u9664\u5916\u952e\u7ea6\u675f"},"content":{"rendered":"<blockquote><p>\n  \u5982\u4f55\u5220\u9664 mysql \u5916\u952e\u7ea6\u675f\u7981\u7528\u5916\u952e\u68c0\u67e5\u4f7f\u7528 alter table \u8bed\u53e5\u5220\u9664\u5916\u952e\u7ea6\u675f\u542f\u7528\u5916\u952e\u68c0\u67e5\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202406\/14\/2024061403422147311.jpg\" class=\"aligncenter\" title=\"mysql\u5982\u4f55\u5220\u9664\u5916\u952e\u7ea6\u675f\u63d2\u56fe\" alt=\"mysql\u5982\u4f55\u5220\u9664\u5916\u952e\u7ea6\u675f\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5220\u9664 MySQL \u5916\u952e\u7ea6\u675f<\/strong><\/p>\n<p>MySQL \u7684\u5916\u952e\u7ea6\u675f\u6709\u52a9\u4e8e\u7ef4\u62a4\u6570\u636e\u7684\u5b8c\u6574\u6027\u548c\u4e00\u81f4\u6027\uff0c\u4f46\u6709\u65f6\u4e5f\u53ef\u80fd\u9700\u8981\u5220\u9664\u8fd9\u4e9b\u7ea6\u675f\u3002\u4ee5\u4e0b\u662f\u5220\u9664 MySQL \u5916\u952e\u7ea6\u675f\u7684\u6b65\u9aa4\uff1a<\/p>\n<p><strong>\u6b65\u9aa4 1\uff1a\u7981\u7528\u5916\u952e\u68c0\u67e5<\/strong><\/p>\n<p>\u9996\u5148\uff0c\u9700\u8981\u7981\u7528\u5916\u952e\u68c0\u67e5\uff0c\u4ee5\u9632\u6b62\u5728\u5220\u9664\u7ea6\u675f\u65f6\u51fa\u73b0\u9519\u8bef\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u67e5\u8be2\uff1a<\/p>\n<pre>SET FOREIGN_KEY_CHECKS=0;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6b65\u9aa4 2\uff1a\u5220\u9664\u5916\u952e\u7ea6\u675f<\/strong><\/p>\n<p>\u63a5\u4e0b\u6765\uff0c\u4f7f\u7528 ALTER TABLE \u8bed\u53e5\u5220\u9664\u5916\u952e\u7ea6\u675f\u3002\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre>ALTER TABLE table_name\nDROP FOREIGN KEY constraint_name;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u5176\u4e2d\uff1a<\/p>\n<ul>\n<li>table_name \u662f\u8981\u5220\u9664\u5916\u952e\u7ea6\u675f\u7684\u8868\u540d\u3002<\/li>\n<li>constraint_name \u662f\u5916\u952e\u7ea6\u675f\u7684\u540d\u79f0\u3002<\/li>\n<\/ul>\n<p>\u4f8b\u5982\uff0c\u8981\u5220\u9664\u540d\u4e3a fk_customer_order \u7684\u5916\u952e\u7ea6\u675f\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u67e5\u8be2\uff1a<\/p>\n<pre>ALTER TABLE order\nDROP FOREIGN KEY fk_customer_order;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u6b65\u9aa4 3\uff1a\u542f\u7528\u5916\u952e\u68c0\u67e5<\/strong><\/p>\n<p>\u6700\u540e\uff0c\u91cd\u65b0\u542f\u7528\u5916\u952e\u68c0\u67e5\uff0c\u4ee5\u786e\u4fdd\u7ee7\u7eed\u4fdd\u6301\u6570\u636e\u7684\u5b8c\u6574\u6027\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u67e5\u8be2\uff1a<\/p>\n<pre>SET FOREIGN_KEY_CHECKS=1;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u5220\u9664\u5916\u952e\u7ea6\u675f\u7684\u8be6\u7ec6\u5185\u5bb9\uff0c\u66f4\u591a\u8bf7\u5173\u6ce8\u7c73\u4e91\u7f51\u5176\u5b83\u76f8\u5173\u6587\u7ae0\uff01<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5982\u4f55\u5220\u9664 mysql \u5916\u952e\u7ea6\u675f\u7981\u7528\u5916\u952e\u68c0\u67e5\u4f7f\u7528 alter table \u8bed\u53e5\u5220\u9664\u5916\u952e\u7ea6\u675f\u542f\u7528\u5916\u952e\u68c0\u67e5 \u5982\u4f55\u5220\u9664 MySQL \u5916\u952e\u7ea6\u675f MySQL \u7684\u5916\u952e\u7ea6\u675f\u6709\u52a9\u4e8e\u7ef4\u62a4\u6570\u636e\u7684\u5b8c\u6574\u6027\u548c\u4e00\u81f4\u6027\uff0c\u4f46\u6709\u65f6\u4e5f\u53ef\u80fd\u9700\u8981\u5220\u9664\u8fd9\u4e9b\u7ea6\u675f\u3002\u4ee5\u4e0b\u662f\u5220\u9664 MySQL \u5916\u952e\u7ea6\u675f\u7684\u6b65\u9aa4\uff1a \u6b65\u9aa4 1\uff1a\u7981\u7528\u5916\u952e\u68c0\u67e5 \u9996\u5148\uff0c\u9700\u8981\u7981\u7528\u5916\u952e\u68c0\u67e5\uff0c\u4ee5\u9632\u6b62\u5728\u5220\u9664\u7ea6\u675f\u65f6\u51fa\u73b0\u9519\u8bef\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u67e5\u8be2\uff1a SET FOREIGN_KEY_CHECKS=0; \u767b\u5f55\u540e\u590d\u5236 \u6b65\u9aa4 2\uff1a\u5220\u9664\u5916\u952e\u7ea6\u675f \u63a5\u4e0b\u6765\uff0c\u4f7f\u7528 ALTER TABLE \u8bed\u53e5\u5220\u9664\u5916\u952e\u7ea6\u675f\u3002\u8bed\u6cd5\u5982\u4e0b\uff1a ALTER TABLE table_name DROP FOREIGN KEY constraint_name; \u767b\u5f55\u540e\u590d\u5236 \u5176\u4e2d\uff1a table_name \u662f\u8981\u5220\u9664\u5916\u952e\u7ea6\u675f\u7684\u8868\u540d\u3002 constraint_name \u662f\u5916\u952e\u7ea6\u675f\u7684\u540d\u79f0\u3002 \u4f8b\u5982\uff0c\u8981\u5220\u9664\u540d\u4e3a fk_customer_order \u7684\u5916\u952e\u7ea6\u675f\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u67e5\u8be2\uff1a ALTER TABLE order DROP FOREIGN KEY fk_customer_order; \u767b\u5f55\u540e\u590d\u5236 \u6b65\u9aa4 3\uff1a\u542f\u7528\u5916\u952e\u68c0\u67e5 \u6700\u540e\uff0c\u91cd\u65b0\u542f\u7528\u5916\u952e\u68c0\u67e5\uff0c\u4ee5\u786e\u4fdd\u7ee7\u7eed\u4fdd\u6301\u6570\u636e\u7684\u5b8c\u6574\u6027\u3002\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u67e5\u8be2\uff1a SET FOREIGN_KEY_CHECKS=1; \u767b\u5f55\u540e\u590d\u5236 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[16],"tags":[],"class_list":["post-6162","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6162","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/comments?post=6162"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6162\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6162"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6162"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6162"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}