{"id":6217,"date":"2024-11-14T09:47:37","date_gmt":"2024-11-14T01:47:37","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6217\/"},"modified":"2024-11-14T09:47:37","modified_gmt":"2024-11-14T01:47:37","slug":"mysql%e8%87%aa%e5%a2%9e%e4%b8%bb%e9%94%ae%e5%a6%82%e4%bd%95%e8%ae%be%e7%bd%ae","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6217\/","title":{"rendered":"mysql\u81ea\u589e\u4e3b\u952e\u5982\u4f55\u8bbe\u7f6e"},"content":{"rendered":"<blockquote><p>\n  mysql \u4e2d\u8bbe\u7f6e\u81ea\u589e\u4e3b\u952e\u7684\u65b9\u6cd5\u5305\u62ec\uff1a\u521b\u5efa\u8868\u65f6\u6307\u5b9a\uff08create table&#8230; auto_increment\uff09\u3001\u8868\u521b\u5efa\u540e\u6dfb\u52a0\uff08alter table&#8230; primary key\uff09\u3002\u81ea\u589e\u4e3b\u952e\u5177\u6709\u552f\u4e00\u6027\u3001\u81ea\u52a8\u751f\u6210\u548c\u9ad8\u6027\u80fd\u7684\u7279\u70b9\uff0c\u4f46\u4e5f\u9700\u8981\u8003\u8651\u9009\u62e9\u5408\u9002\u7684\u6570\u636e\u7c7b\u578b\u3001\u907f\u514d\u624b\u52a8\u63d2\u5165\u548c\u7ef4\u62a4\u8868\u4e4b\u95f4\u7684\u5f15\u7528\u5b8c\u6574\u6027\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202406\/15\/2024061514033098814.jpg\" class=\"aligncenter\" title=\"mysql\u81ea\u589e\u4e3b\u952e\u5982\u4f55\u8bbe\u7f6e\u63d2\u56fe\" alt=\"mysql\u81ea\u589e\u4e3b\u952e\u5982\u4f55\u8bbe\u7f6e\u63d2\u56fe\" \/><\/p>\n<p><strong>\u5982\u4f55\u5728 MySQL \u4e2d\u8bbe\u7f6e\u81ea\u589e\u4e3b\u952e<\/strong><\/p>\n<p>\u81ea\u589e\u4e3b\u952e\u662f MySQL \u8868\u4e2d\u4e00\u79cd\u7279\u6b8a\u7c7b\u578b\u7684\u5217\uff0c\u5b83\u4e3a\u63d2\u5165\u8868\u4e2d\u7684\u6bcf\u4e00\u884c\u81ea\u52a8\u751f\u6210\u4e00\u4e2a\u552f\u4e00\u503c\u3002\u8fd9\u5bf9\u4e8e\u521b\u5efa\u548c\u7ba1\u7406\u552f\u4e00\u6807\u8bc6\u7b26\u975e\u5e38\u6709\u7528\u3002<\/p>\n<p><strong>\u8bbe\u7f6e\u81ea\u589e\u4e3b\u952e\u7684\u6b65\u9aa4\uff1a<\/strong><\/p>\n<ol>\n<li><strong>\u521b\u5efa\u8868\u65f6\u6307\u5b9a\u81ea\u589e\u4e3b\u952e\uff1a<\/strong><\/li>\n<\/ol>\n<pre>CREATE TABLE table_name (\n  id INT NOT NULL AUTO_INCREMENT,\n  ... \u5176\u4ed6\u5217\n);<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<blockquote><p>\n  \u5728\u6b64\u793a\u4f8b\u4e2d\uff0cid \u5217\u5c06\u88ab\u5b9a\u4e49\u4e3a\u81ea\u589e\u4e3b\u952e\u3002\n<\/p><\/blockquote>\n<ol>\n<li><strong>\u5728\u8868\u521b\u5efa\u540e\u6dfb\u52a0\u81ea\u589e\u4e3b\u952e\uff1a<\/strong><\/li>\n<\/ol>\n<pre>ALTER TABLE table_name ADD COLUMN id INT NOT NULL AUTO_INCREMENT PRIMARY KEY;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<blockquote><p>\n  \u6b64\u8bed\u53e5\u5c06\u5728\u5df2\u5b58\u5728\u7684\u8868\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u81ea\u589e\u4e3b\u952e\u3002\n<\/p><\/blockquote>\n<p><strong>\u81ea\u589e\u4e3b\u952e\u7684\u4f18\u70b9\uff1a<\/strong><\/p>\n<ul>\n<li> <strong>\u552f\u4e00\u6027\uff1a<\/strong>\u81ea\u589e\u4e3b\u952e\u4fdd\u8bc1\u6bcf\u4e00\u884c\u90fd\u6709\u4e00\u4e2a\u552f\u4e00\u7684\u6807\u8bc6\u7b26\uff0c\u4ece\u800c\u9632\u6b62\u91cd\u590d\u3002<\/li>\n<li> <strong>\u81ea\u52a8\u751f\u6210\uff1a<\/strong>\u6570\u636e\u5e93\u4f1a\u81ea\u52a8\u751f\u6210\u4e3b\u952e\uff0c\u65e0\u9700\u5e94\u7528\u7a0b\u5e8f\u663e\u5f0f\u8bbe\u7f6e\uff0c\u7b80\u5316\u4e86\u5f00\u53d1\u8fc7\u7a0b\u3002<\/li>\n<li> <strong>\u9ad8\u6027\u80fd\uff1a<\/strong>MySQL \u5185\u90e8\u4f18\u5316\u4e86\u81ea\u589e\u4e3b\u952e\u7684\u5b9e\u73b0\uff0c\u4f7f\u5176\u80fd\u591f\u9ad8\u6548\u5730\u751f\u6210\u552f\u4e00\u503c\u3002<\/li>\n<\/ul>\n<p><strong>\u81ea\u589e\u4e3b\u952e\u7684\u6ce8\u610f\u4e8b\u9879\uff1a<\/strong><\/p>\n<ul>\n<li> <strong>\u8c28\u614e\u9009\u62e9\u6570\u636e\u7c7b\u578b\uff1a<\/strong>\u81ea\u589e\u4e3b\u952e\u901a\u5e38\u4f7f\u7528\u6574\u6570\u7c7b\u578b\uff0c\u5982 INT \u6216 BIGINT\uff0c\u4ee5\u786e\u4fdd\u751f\u6210\u8db3\u591f\u5927\u7684\u552f\u4e00\u503c\u3002<\/li>\n<li> <strong>\u907f\u514d\u624b\u52a8\u63d2\u5165\uff1a<\/strong>\u5c3d\u91cf\u4e0d\u8981\u624b\u52a8\u63d2\u5165\u81ea\u589e\u4e3b\u952e\u7684\u503c\uff0c\u56e0\u4e3a\u8fd9\u53ef\u80fd\u5bfc\u81f4\u4e3b\u952e\u51b2\u7a81\u3002<\/li>\n<li> <strong>\u8003\u8651\u4f7f\u7528\u5916\u952e\uff1a<\/strong>\u5982\u679c\u591a\u4e2a\u8868\u901a\u8fc7\u5916\u952e\u5173\u8054\u5230\u81ea\u589e\u4e3b\u952e\u5217\uff0c\u5219\u5e94\u5c0f\u5fc3\u7ef4\u62a4\u8868\u4e4b\u95f4\u7684\u5f15\u7528\u5b8c\u6574\u6027\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u81ea\u589e\u4e3b\u952e\u5982\u4f55\u8bbe\u7f6e\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\u8bbe\u7f6e\u81ea\u589e\u4e3b\u952e\u7684\u65b9\u6cd5\u5305\u62ec\uff1a\u521b\u5efa\u8868\u65f6\u6307\u5b9a\uff08create table&#8230; auto_increment\uff09\u3001\u8868\u521b\u5efa\u540e\u6dfb\u52a0\uff08alter table&#8230; primary key\uff09\u3002\u81ea\u589e\u4e3b\u952e\u5177\u6709\u552f\u4e00\u6027\u3001\u81ea\u52a8\u751f\u6210\u548c\u9ad8\u6027\u80fd\u7684\u7279\u70b9\uff0c\u4f46\u4e5f\u9700\u8981\u8003\u8651\u9009\u62e9\u5408\u9002\u7684\u6570\u636e\u7c7b\u578b\u3001\u907f\u514d\u624b\u52a8\u63d2\u5165\u548c\u7ef4\u62a4\u8868\u4e4b\u95f4\u7684\u5f15\u7528\u5b8c\u6574\u6027\u3002 \u5982\u4f55\u5728 MySQL \u4e2d\u8bbe\u7f6e\u81ea\u589e\u4e3b\u952e \u81ea\u589e\u4e3b\u952e\u662f MySQL \u8868\u4e2d\u4e00\u79cd\u7279\u6b8a\u7c7b\u578b\u7684\u5217\uff0c\u5b83\u4e3a\u63d2\u5165\u8868\u4e2d\u7684\u6bcf\u4e00\u884c\u81ea\u52a8\u751f\u6210\u4e00\u4e2a\u552f\u4e00\u503c\u3002\u8fd9\u5bf9\u4e8e\u521b\u5efa\u548c\u7ba1\u7406\u552f\u4e00\u6807\u8bc6\u7b26\u975e\u5e38\u6709\u7528\u3002 \u8bbe\u7f6e\u81ea\u589e\u4e3b\u952e\u7684\u6b65\u9aa4\uff1a \u521b\u5efa\u8868\u65f6\u6307\u5b9a\u81ea\u589e\u4e3b\u952e\uff1a CREATE TABLE table_name ( id INT NOT NULL AUTO_INCREMENT, &#8230; \u5176\u4ed6\u5217 ); \u767b\u5f55\u540e\u590d\u5236 \u5728\u6b64\u793a\u4f8b\u4e2d\uff0cid \u5217\u5c06\u88ab\u5b9a\u4e49\u4e3a\u81ea\u589e\u4e3b\u952e\u3002 \u5728\u8868\u521b\u5efa\u540e\u6dfb\u52a0\u81ea\u589e\u4e3b\u952e\uff1a ALTER TABLE table_name ADD COLUMN id INT NOT NULL AUTO_INCREMENT PRIMARY KEY; \u767b\u5f55\u540e\u590d\u5236 \u6b64\u8bed\u53e5\u5c06\u5728\u5df2\u5b58\u5728\u7684\u8868\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u81ea\u589e\u4e3b\u952e\u3002 \u81ea\u589e\u4e3b\u952e\u7684\u4f18\u70b9\uff1a \u552f\u4e00\u6027\uff1a\u81ea\u589e\u4e3b\u952e\u4fdd\u8bc1\u6bcf\u4e00\u884c\u90fd\u6709\u4e00\u4e2a\u552f\u4e00\u7684\u6807\u8bc6\u7b26\uff0c\u4ece\u800c\u9632\u6b62\u91cd\u590d\u3002 \u81ea\u52a8\u751f\u6210\uff1a\u6570\u636e\u5e93\u4f1a\u81ea\u52a8\u751f\u6210\u4e3b\u952e\uff0c\u65e0\u9700\u5e94\u7528\u7a0b\u5e8f\u663e\u5f0f\u8bbe\u7f6e\uff0c\u7b80\u5316\u4e86\u5f00\u53d1\u8fc7\u7a0b\u3002 \u9ad8\u6027\u80fd\uff1aMySQL \u5185\u90e8\u4f18\u5316\u4e86\u81ea\u589e\u4e3b\u952e\u7684\u5b9e\u73b0\uff0c\u4f7f\u5176\u80fd\u591f\u9ad8\u6548\u5730\u751f\u6210\u552f\u4e00\u503c\u3002 \u81ea\u589e\u4e3b\u952e\u7684\u6ce8\u610f\u4e8b\u9879\uff1a \u8c28\u614e\u9009\u62e9\u6570\u636e\u7c7b\u578b\uff1a\u81ea\u589e\u4e3b\u952e\u901a\u5e38\u4f7f\u7528\u6574\u6570\u7c7b\u578b\uff0c\u5982 INT \u6216 BIGINT\uff0c\u4ee5\u786e\u4fdd\u751f\u6210\u8db3\u591f\u5927\u7684\u552f\u4e00\u503c\u3002 [&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-6217","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6217","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=6217"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6217\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6217"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6217"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6217"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}