{"id":5431,"date":"2024-11-14T10:04:40","date_gmt":"2024-11-14T02:04:40","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5431\/"},"modified":"2024-11-14T10:04:40","modified_gmt":"2024-11-14T02:04:40","slug":"mysql%e6%9b%b4%e6%96%b0%e8%af%ad%e5%8f%a5%e6%80%8e%e4%b9%88%e5%86%99","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5431\/","title":{"rendered":"mysql\u66f4\u65b0\u8bed\u53e5\u600e\u4e48\u5199"},"content":{"rendered":"<blockquote><p>\n  mysql \u4e2d\u7684\u66f4\u65b0\u8bed\u53e5\u7528\u4e8e\u4fee\u6539\u8868\u4e2d\u73b0\u6709\u8bb0\u5f55\uff0c\u8bed\u6cd5\u4e3a\uff1aupdate table_name set column1 = value1, column2 = value2, &#8230; where condition\uff0c\u5176\u4e2d table_name \u4e3a\u8868\u540d\uff0ccolumn1\u3001column2 \u4e3a\u5217\u540d\uff0cvalue1\u3001value2 \u4e3a\u65b0\u503c\uff0cwhere condition \u4e3a\u53ef\u9009\u6761\u4ef6\uff0c\u7528\u4e8e\u6307\u5b9a\u66f4\u65b0\u54ea\u4e9b\u8bb0\u5f55\u3002\u5e38\u89c1\u6761\u4ef6\u64cd\u4f5c\u7b26\u5305\u62ec =\u3001!=\u3001&gt;\u3001=\u3001\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/28\/2024052812454119040.jpg\" class=\"aligncenter\" title=\"mysql\u66f4\u65b0\u8bed\u53e5\u600e\u4e48\u5199\u63d2\u56fe\" alt=\"mysql\u66f4\u65b0\u8bed\u53e5\u600e\u4e48\u5199\u63d2\u56fe\" \/><\/p>\n<p><strong>MySQL \u66f4\u65b0\u8bed\u53e5<\/strong><\/p>\n<p>MySQL \u4e2d\u7684\u66f4\u65b0\u8bed\u53e5\u7528\u4e8e\u4fee\u6539\u6570\u636e\u5e93\u4e2d\u8868\u4e2d\u73b0\u6709\u8bb0\u5f55\u3002\u8bed\u6cd5\u5982\u4e0b\uff1a<\/p>\n<pre>UPDATE table_name\nSET column1 = value1, column2 = value2, ...\nWHERE condition;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u53c2\u6570\uff1a<\/strong><\/p>\n<ul>\n<li> <strong>table_name\uff1a<\/strong>\u8981\u66f4\u65b0\u7684\u8868\u540d\u3002<\/li>\n<li> <strong>column1, column2, &#8230;\uff1a<\/strong>\u8981\u66f4\u65b0\u7684\u5217\u540d\u3002<\/li>\n<li> <strong>value1, value2, &#8230;\uff1a<\/strong>\u8981\u66f4\u65b0\u7684\u65b0\u503c\u3002<\/li>\n<li> <strong>WHERE condition\uff1a<\/strong>\u53ef\u9009\uff0c\u6307\u5b9a\u66f4\u65b0\u54ea\u4e9b\u8bb0\u5f55\u7684\u6761\u4ef6\u3002<\/li>\n<\/ul>\n<p><strong>\u793a\u4f8b\uff1a<\/strong><\/p>\n<pre>UPDATE customers\nSET name = 'John Doe'\nWHERE id = 1;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>\u6b64\u8bed\u53e5\u5c06\u540d\u4e3a &#8220;customers&#8221; \u8868\u4e2d id \u4e3a 1 \u7684\u8bb0\u5f55\u7684 &#8220;name&#8221; \u5217\u66f4\u65b0\u4e3a &#8220;John Doe&#8221;\u3002<\/p>\n<p><strong>WHERE \u5b50\u53e5\uff1a<\/strong><\/p>\n<p>WHERE \u5b50\u53e5\u7528\u4e8e\u6307\u5b9a\u54ea\u4e9b\u8bb0\u5f55\u5e94\u66f4\u65b0\u3002\u5982\u679c\u6ca1\u6709\u6307\u5b9a WHERE \u5b50\u53e5\uff0c\u5219\u4f1a\u66f4\u65b0\u8868\u4e2d\u7684\u6240\u6709\u8bb0\u5f55\u3002<\/p>\n<p><strong>\u5e38\u89c1\u6761\u4ef6\u64cd\u4f5c\u7b26\uff1a<\/strong><\/p>\n<ul>\n<li>= \u76f8\u7b49<\/li>\n<li>!= \u4e0d\u76f8\u7b49<\/li>\n<li>\n<blockquote><p>\n    \u5927\u4e8e\n  <\/p><\/blockquote>\n<\/li>\n<li> <\/li>\n<li>\n<blockquote><p>\n    = \u5927\u4e8e\u6216\u7b49\u4e8e\n  <\/p><\/blockquote>\n<\/li>\n<li> <\/li>\n<li>LIKE \u6a21\u5f0f\u5339\u914d<\/li>\n<\/ul>\n<p><strong>\u7279\u6b8a\u503c\uff1a<\/strong><\/p>\n<ul>\n<li> <strong>NULL\uff1a<\/strong>\u5c06\u5217\u503c\u8bbe\u7f6e\u4e3a NULL\u3002<\/li>\n<li> <strong>DEFAULT\uff1a<\/strong>\u5c06\u5217\u503c\u8bbe\u7f6e\u4e3a\u5217\u7684\u9ed8\u8ba4\u503c\u3002<\/li>\n<\/ul>\n<p><strong>\u63d0\u793a\uff1a<\/strong><\/p>\n<ul>\n<li>\u4f7f\u7528\u66f4\u65b0\u8bed\u53e5\u65f6\u8981\u5c0f\u5fc3\uff0c\u56e0\u4e3a\u5b83\u53ef\u4ee5\u6c38\u4e45\u66f4\u6539\u6570\u636e\u5e93\u4e2d\u7684\u6570\u636e\u3002<\/li>\n<li>\u5728\u6267\u884c\u66f4\u65b0\u8bed\u53e5\u4e4b\u524d\uff0c\u5efa\u8bae\u4f7f\u7528 SELECT \u8bed\u53e5\u9a8c\u8bc1\u8981\u66f4\u65b0\u7684\u6570\u636e\u3002<\/li>\n<li>\u5bf9\u4e8e\u5927\u6570\u636e\u96c6\uff0c\u4f7f\u7528\u6279\u91cf\u66f4\u65b0\u8bed\u53e5\u53ef\u4ee5\u63d0\u9ad8\u6027\u80fd\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u66f4\u65b0\u8bed\u53e5\u600e\u4e48\u5199\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>mysql \u4e2d\u7684\u66f4\u65b0\u8bed\u53e5\u7528\u4e8e\u4fee\u6539\u8868\u4e2d\u73b0\u6709\u8bb0\u5f55\uff0c\u8bed\u6cd5\u4e3a\uff1aupdate table_name set column1 = value1, column2 = value2, &#8230; where condition\uff0c\u5176\u4e2d table_name \u4e3a\u8868\u540d\uff0ccolumn1\u3001column2 \u4e3a\u5217\u540d\uff0cvalue1\u3001value2 \u4e3a\u65b0\u503c\uff0cwhere condition \u4e3a\u53ef\u9009\u6761\u4ef6\uff0c\u7528\u4e8e\u6307\u5b9a\u66f4\u65b0\u54ea\u4e9b\u8bb0\u5f55\u3002\u5e38\u89c1\u6761\u4ef6\u64cd\u4f5c\u7b26\u5305\u62ec =\u3001!=\u3001&gt;\u3001=\u3001 MySQL \u66f4\u65b0\u8bed\u53e5 MySQL \u4e2d\u7684\u66f4\u65b0\u8bed\u53e5\u7528\u4e8e\u4fee\u6539\u6570\u636e\u5e93\u4e2d\u8868\u4e2d\u73b0\u6709\u8bb0\u5f55\u3002\u8bed\u6cd5\u5982\u4e0b\uff1a UPDATE table_name SET column1 = value1, column2 = value2, &#8230; WHERE condition; \u767b\u5f55\u540e\u590d\u5236 \u53c2\u6570\uff1a table_name\uff1a\u8981\u66f4\u65b0\u7684\u8868\u540d\u3002 column1, column2, &#8230;\uff1a\u8981\u66f4\u65b0\u7684\u5217\u540d\u3002 value1, value2, &#8230;\uff1a\u8981\u66f4\u65b0\u7684\u65b0\u503c\u3002 WHERE condition\uff1a\u53ef\u9009\uff0c\u6307\u5b9a\u66f4\u65b0\u54ea\u4e9b\u8bb0\u5f55\u7684\u6761\u4ef6\u3002 \u793a\u4f8b\uff1a UPDATE customers SET name = &#8216;John Doe&#8217; [&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-5431","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5431","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=5431"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5431\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5431"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5431"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5431"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}