{"id":5392,"date":"2024-11-14T11:56:15","date_gmt":"2024-11-14T03:56:15","guid":{"rendered":"https:\/\/fwq.ai\/blog\/5392\/"},"modified":"2024-11-14T11:56:15","modified_gmt":"2024-11-14T03:56:15","slug":"mysql%e8%87%aa%e5%a2%9eid%e7%94%a8%e5%ae%8c%e4%ba%86%e6%80%8e%e4%b9%88%e5%8a%9e","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/5392\/","title":{"rendered":"mysql\u81ea\u589eid\u7528\u5b8c\u4e86\u600e\u4e48\u529e"},"content":{"rendered":"<blockquote><p>\n  \u89e3\u51b3 mysql \u81ea\u589e id \u7528\u5b8c\u7684\u95ee\u9898\uff1a\u66f4\u6539\u6570\u636e\u7c7b\u578b\u4e3a bigint\uff0c\u5141\u8bb8\u5b58\u50a8\u66f4\u5927\u7684\u6574\u6570\u3002\u91cd\u7f6e\u81ea\u589e id\uff0c\u4ece\u6307\u5b9a\u503c\u5f00\u59cb\u5206\u914d\u65b0 id\u3002\u91cd\u65b0\u521b\u5efa\u8868\uff0c\u6307\u5b9a\u66f4\u5927\u7684\u81ea\u589e id \u8d77\u59cb\u503c\u3002\u6700\u4f73\u89e3\u51b3\u65b9\u6848\u53d6\u51b3\u4e8e\u8868\u4e2d\u5f53\u524d\u8bb0\u5f55\u7684\u6570\u91cf\u548c\u9884\u8ba1\u7684\u672a\u6765\u589e\u957f\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202405\/28\/2024052810242363489.jpg\" class=\"aligncenter\" title=\"mysql\u81ea\u589eid\u7528\u5b8c\u4e86\u600e\u4e48\u529e\u63d2\u56fe\" alt=\"mysql\u81ea\u589eid\u7528\u5b8c\u4e86\u600e\u4e48\u529e\u63d2\u56fe\" \/><\/p>\n<p><strong>MySQL \u81ea\u589e ID \u7528\u5b8c\u4e86\u600e\u4e48\u529e<\/strong><\/p>\n<p>\u5f53 MySQL \u8868\u4e2d\u7684\u81ea\u589e ID \u7528\u5b8c\u65f6\uff0c\u6570\u636e\u5e93\u5c06\u65e0\u6cd5\u4e3a\u65b0\u63d2\u5165\u7684\u8bb0\u5f55\u5206\u914d\u552f\u4e00\u7684 ID\u3002\u8fd9\u4f1a\u5bfc\u81f4\u6570\u636e\u5b8c\u6574\u6027\u95ee\u9898\u3002\u89e3\u51b3\u6b64\u95ee\u9898\u7684\u6b65\u9aa4\u5982\u4e0b\uff1a<\/p>\n<p><strong>1. \u66f4\u6539\u81ea\u589e ID \u5217\u7684\u6570\u636e\u7c7b\u578b<\/strong><\/p>\n<p>\u5c06\u81ea\u589e ID \u5217\u7684\u6570\u636e\u7c7b\u578b\u4ece INT \u66f4\u6539\u4e3a BIGINT\uff0c\u8fd9\u5c06\u5141\u8bb8\u5b58\u50a8\u66f4\u5927\u7684\u6574\u6570\u503c\u3002<\/p>\n<pre>ALTER TABLE table_name MODIFY column_name BIGINT NOT NULL AUTO_INCREMENT;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>2. \u91cd\u7f6e\u81ea\u589e ID<\/strong><\/p>\n<p>\u91cd\u7f6e\u81ea\u589e ID \u5c06\u4ece\u6307\u5b9a\u503c\u5f00\u59cb\u5206\u914d\u65b0\u7684 ID\u3002<\/p>\n<pre>ALTER TABLE table_name AUTO_INCREMENT = 10000;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>3. \u91cd\u65b0\u521b\u5efa\u8868<\/strong><\/p>\n<p>\u5982\u679c\u65e0\u6cd5\u66f4\u6539\u6570\u636e\u7c7b\u578b\u6216\u91cd\u7f6e\u81ea\u589e ID\uff0c\u5219\u53ef\u4ee5\u91cd\u65b0\u521b\u5efa\u8868\u5e76\u6307\u5b9a\u4e00\u4e2a\u66f4\u5927\u7684\u81ea\u589e ID \u8d77\u59cb\u503c\u3002<\/p>\n<pre>DROP TABLE table_name;\nCREATE TABLE table_name (\n  id BIGINT NOT NULL AUTO_INCREMENT,\n  ...\n);\nINSERT INTO table_name (id, ...) VALUES (999999999999999999, ...);\nALTER TABLE table_name AUTO_INCREMENT = 10000;<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p><strong>\u9009\u62e9\u6700\u4f73\u89e3\u51b3\u65b9\u6848<\/strong><\/p>\n<p>\u9009\u62e9\u6700\u4f73\u89e3\u51b3\u65b9\u6848\u53d6\u51b3\u4e8e\u8868\u4e2d\u5f53\u524d\u8bb0\u5f55\u7684\u6570\u91cf\u548c\u9884\u8ba1\u7684\u672a\u6765\u589e\u957f\u3002<\/p>\n<ul>\n<li>\u5bf9\u4e8e\u8868\u4e2d\u8bb0\u5f55\u8f83\u5c11\u4e14\u672a\u6765\u589e\u957f\u6709\u9650\u7684\u8868\uff0c\u91cd\u7f6e\u81ea\u589e ID \u53ef\u80fd\u5c31\u8db3\u591f\u4e86\u3002<\/li>\n<li>\u5bf9\u4e8e\u8868\u4e2d\u8bb0\u5f55\u8f83\u591a\u6216\u9884\u8ba1\u672a\u6765\u589e\u957f\u663e\u8457\u7684\u8868\uff0c\u66f4\u6539\u6570\u636e\u7c7b\u578b\u6216\u91cd\u65b0\u521b\u5efa\u8868\u662f\u4e00\u4e2a\u66f4\u597d\u7684\u9009\u62e9\u3002<\/li>\n<\/ul>\n<p>\u4ee5\u4e0a\u5c31\u662f\u81ea\u589eid\u7528\u5b8c\u4e86\u600e\u4e48\u529e\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>\u89e3\u51b3 mysql \u81ea\u589e id \u7528\u5b8c\u7684\u95ee\u9898\uff1a\u66f4\u6539\u6570\u636e\u7c7b\u578b\u4e3a bigint\uff0c\u5141\u8bb8\u5b58\u50a8\u66f4\u5927\u7684\u6574\u6570\u3002\u91cd\u7f6e\u81ea\u589e id\uff0c\u4ece\u6307\u5b9a\u503c\u5f00\u59cb\u5206\u914d\u65b0 id\u3002\u91cd\u65b0\u521b\u5efa\u8868\uff0c\u6307\u5b9a\u66f4\u5927\u7684\u81ea\u589e id \u8d77\u59cb\u503c\u3002\u6700\u4f73\u89e3\u51b3\u65b9\u6848\u53d6\u51b3\u4e8e\u8868\u4e2d\u5f53\u524d\u8bb0\u5f55\u7684\u6570\u91cf\u548c\u9884\u8ba1\u7684\u672a\u6765\u589e\u957f\u3002 MySQL \u81ea\u589e ID \u7528\u5b8c\u4e86\u600e\u4e48\u529e \u5f53 MySQL \u8868\u4e2d\u7684\u81ea\u589e ID \u7528\u5b8c\u65f6\uff0c\u6570\u636e\u5e93\u5c06\u65e0\u6cd5\u4e3a\u65b0\u63d2\u5165\u7684\u8bb0\u5f55\u5206\u914d\u552f\u4e00\u7684 ID\u3002\u8fd9\u4f1a\u5bfc\u81f4\u6570\u636e\u5b8c\u6574\u6027\u95ee\u9898\u3002\u89e3\u51b3\u6b64\u95ee\u9898\u7684\u6b65\u9aa4\u5982\u4e0b\uff1a 1. \u66f4\u6539\u81ea\u589e ID \u5217\u7684\u6570\u636e\u7c7b\u578b \u5c06\u81ea\u589e ID \u5217\u7684\u6570\u636e\u7c7b\u578b\u4ece INT \u66f4\u6539\u4e3a BIGINT\uff0c\u8fd9\u5c06\u5141\u8bb8\u5b58\u50a8\u66f4\u5927\u7684\u6574\u6570\u503c\u3002 ALTER TABLE table_name MODIFY column_name BIGINT NOT NULL AUTO_INCREMENT; \u767b\u5f55\u540e\u590d\u5236 2. \u91cd\u7f6e\u81ea\u589e ID \u91cd\u7f6e\u81ea\u589e ID \u5c06\u4ece\u6307\u5b9a\u503c\u5f00\u59cb\u5206\u914d\u65b0\u7684 ID\u3002 ALTER TABLE table_name AUTO_INCREMENT = 10000; \u767b\u5f55\u540e\u590d\u5236 3. [&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-5392","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5392","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=5392"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/5392\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=5392"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=5392"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=5392"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}