{"id":6246,"date":"2024-11-14T13:39:18","date_gmt":"2024-11-14T05:39:18","guid":{"rendered":"https:\/\/fwq.ai\/blog\/6246\/"},"modified":"2024-11-14T13:39:18","modified_gmt":"2024-11-14T05:39:18","slug":"mysql%e5%a6%82%e4%bd%95%e5%88%86%e6%ae%b5%e5%af%bc%e5%87%ba%e6%95%b0%e6%8d%ae","status":"publish","type":"post","link":"https:\/\/fwq.ai\/blog\/6246\/","title":{"rendered":"mysql\u5982\u4f55\u5206\u6bb5\u5bfc\u51fa\u6570\u636e"},"content":{"rendered":"<blockquote><p>\n  mysql \u63d0\u4f9b\u4e24\u79cd\u5206\u6bb5\u5bfc\u51fa\u6570\u636e\u7684\u65b9\u6cd5\uff1a\u4f7f\u7528 limit \u5b50\u53e5\uff0c\u6307\u5b9a\u6bcf\u6b21\u67e5\u8be2\u8fd4\u56de\u7684\u8bb0\u5f55\u6570\u91cf\uff0c\u901a\u8fc7\u9012\u589e offset \u503c\u5206\u6bb5\u5bfc\u51fa\u3002\u4f7f\u7528 mysqldump \u5de5\u5177\uff0c\u63d0\u4f9b\u7075\u6d3b\u7684\u5bfc\u51fa\u9009\u9879\uff0c\u5305\u62ec\u6309\u884c\u6570\u5206\u6bb5\u5bfc\u51fa\u548c\u5728\u4e0d\u540c\u8bbe\u5907\/\u5e73\u53f0\u4e0a\u5bfc\u5165\u3002\n<\/p><\/blockquote>\n<p><img decoding=\"async\" src=\"https:\/\/img.php.cn\/upload\/article\/202406\/15\/2024061516303314351.jpg\" class=\"aligncenter\" title=\"mysql\u5982\u4f55\u5206\u6bb5\u5bfc\u51fa\u6570\u636e\u63d2\u56fe\" alt=\"mysql\u5982\u4f55\u5206\u6bb5\u5bfc\u51fa\u6570\u636e\u63d2\u56fe\" \/><\/p>\n<p><strong>MySQL \u5206\u6bb5\u5bfc\u51fa\u6570\u636e\u7684\u65b9\u6cd5<\/strong><\/p>\n<p>MySQL \u5bfc\u51fa\u6570\u636e\u65f6\uff0c\u901a\u5e38\u9700\u8981\u5bfc\u51fa\u6574\u4e2a\u8868\u7684\u5185\u5bb9\u3002\u4f46\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u9700\u8981\u5206\u6bb5\u5bfc\u51fa\u6570\u636e\uff0c\u4f8b\u5982\uff1a<\/p>\n<ul>\n<li>\u5bfc\u51fa\u6570\u636e\u91cf\u8fc7\u5927\uff0c\u5bfc\u81f4\u5bfc\u51fa\u8fc7\u7a0b\u957f\u65f6\u95f4\u5360\u7528\u670d\u52a1\u5668\u8d44\u6e90<\/li>\n<li>\u9700\u8981\u5c06\u6570\u636e\u5206\u53d1\u5230\u591a\u4e2a\u8bbe\u5907\u6216\u5e73\u53f0<\/li>\n<\/ul>\n<p>MySQL \u63d0\u4f9b\u4e86\u4e24\u79cd\u65b9\u6cd5\u6765\u5206\u6bb5\u5bfc\u51fa\u6570\u636e\uff1a<\/p>\n<p><strong>\u65b9\u6cd5\u4e00\uff1a\u4f7f\u7528 LIMIT \u5b50\u53e5<\/strong><\/p>\n<p>LIMIT \u5b50\u53e5\u53ef\u4ee5\u6307\u5b9a\u6bcf\u6b21\u67e5\u8be2\u8fd4\u56de\u7684\u8bb0\u5f55\u6570\u91cf\u3002\u53ef\u4ee5\u4f7f\u7528\u5b83\u6765\u5206\u6bb5\u5bfc\u51fa\u6570\u636e\uff1a<\/p>\n<pre>SELECT * FROM table_name LIMIT 1000 OFFSET 0;\nSELECT * FROM table_name LIMIT 1000 OFFSET 1000;\nSELECT * FROM table_name LIMIT 1000 OFFSET 2000;\n...<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<p>OFFSET \u5b50\u53e5\u6307\u5b9a\u4ece\u7b2c\u51e0\u4e2a\u8bb0\u5f55\u5f00\u59cb\u67e5\u8be2\u3002\u901a\u8fc7\u9012\u589e OFFSET \u7684\u503c\uff0c\u53ef\u4ee5\u5206\u6bb5\u5bfc\u51fa\u6570\u636e\u3002<\/p>\n<p><strong>\u65b9\u6cd5\u4e8c\uff1a\u4f7f\u7528 dump \u5de5\u5177<\/strong><\/p>\n<p>mysqldump \u5de5\u5177\u63d0\u4f9b\u4e86\u66f4\u7075\u6d3b\u7684\u5bfc\u51fa\u9009\u9879\uff0c\u5305\u62ec\u5206\u6bb5\u5bfc\u51fa\u3002<\/p>\n<pre>mysqldump --opt --single-transaction --flush-logs --skip-tz-utc --column-statistics=0 --quick --order-by-primary --default-character-set=utf8mb4 -u username -p password database_name | split -l 1000000 --numeric-suffixes --additional-suffix=.sql<\/pre>\n<p> \u767b\u5f55\u540e\u590d\u5236 <\/p>\n<ul>\n<li> <strong>&#8211;opt<\/strong>\uff1a\u4f18\u5316\u5bfc\u51fa\u6027\u80fd<\/li>\n<li> <strong>&#8211;single-transaction<\/strong>\uff1a\u5728\u5355\u4e2a\u4e8b\u52a1\u4e2d\u5bfc\u51fa\u6570\u636e\uff0c\u786e\u4fdd\u6570\u636e\u4e00\u81f4\u6027<\/li>\n<li> <strong>&#8211;flush-logs<\/strong>\uff1a\u5728\u5bfc\u51fa\u524d\u5237\u65b0\u4e8c\u8fdb\u5236\u65e5\u5fd7<\/li>\n<li> <strong>&#8211;skip-tz-utc<\/strong>\uff1a\u8df3\u8fc7\u65f6\u533a\u8f6c\u6362\uff0c\u907f\u514d\u6570\u636e\u4e0d\u4e00\u81f4<\/li>\n<li> <strong>&#8211;column-statistics=0<\/strong>\uff1a\u7981\u7528\u5217\u7edf\u8ba1\u4fe1\u606f\u7684\u6536\u96c6\uff0c\u63d0\u9ad8\u5bfc\u51fa\u901f\u5ea6<\/li>\n<li> <strong>&#8211;quick<\/strong>\uff1a\u5feb\u901f\u5bfc\u51fa\uff0c\u4e0d\u5bfc\u51fa\u8868\u7ed3\u6784<\/li>\n<li> <strong>&#8211;order-by-primary<\/strong>\uff1a\u6309\u4e3b\u952e\u987a\u5e8f\u5bfc\u51fa\u6570\u636e\uff0c\u6709\u5229\u4e8e\u6570\u636e\u5bfc\u5165<\/li>\n<li> <strong>&#8211;default-character-set=utf8mb4<\/strong>\uff1a\u8bbe\u7f6e\u9ed8\u8ba4\u5b57\u7b26\u96c6\u4e3a UTF-8<\/li>\n<li> <strong>-u username -p password<\/strong>\uff1a\u6307\u5b9a MySQL \u7528\u6237\u540d\u548c\u5bc6\u7801<\/li>\n<li> <strong>database_name<\/strong>\uff1a\u8981\u5bfc\u51fa\u7684\u6570\u636e\u5e93\u540d\u79f0<\/li>\n<li> <strong>split -l 1000000 &#8211;numeric-suffixes &#8211;additional-suffix=.sql<\/strong>\uff1a\u5c06\u5bfc\u51fa\u7ed3\u679c\u5206\u5272\u6210 100 \u4e07\u884c\u4e00\u6bb5\uff0c\u5e76\u6dfb\u52a0\u6570\u5b57\u540e\u7f00\u548c .sql \u6269\u5c55\u540d<\/li>\n<\/ul>\n<p>\u4f7f\u7528 mysqldump \u5de5\u5177\u5bfc\u51fa\u5206\u6bb5\u6570\u636e\u540e\uff0c\u53ef\u4ee5\u6839\u636e\u9700\u8981\u5728\u4e0d\u540c\u7684\u8bbe\u5907\u6216\u5e73\u53f0\u4e0a\u5bfc\u5165\u6570\u636e\u3002<\/p>\n<p>\u4ee5\u4e0a\u5c31\u662f\u5982\u4f55\u5206\u6bb5\u5bfc\u51fa\u6570\u636e\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 \u63d0\u4f9b\u4e24\u79cd\u5206\u6bb5\u5bfc\u51fa\u6570\u636e\u7684\u65b9\u6cd5\uff1a\u4f7f\u7528 limit \u5b50\u53e5\uff0c\u6307\u5b9a\u6bcf\u6b21\u67e5\u8be2\u8fd4\u56de\u7684\u8bb0\u5f55\u6570\u91cf\uff0c\u901a\u8fc7\u9012\u589e offset \u503c\u5206\u6bb5\u5bfc\u51fa\u3002\u4f7f\u7528 mysqldump \u5de5\u5177\uff0c\u63d0\u4f9b\u7075\u6d3b\u7684\u5bfc\u51fa\u9009\u9879\uff0c\u5305\u62ec\u6309\u884c\u6570\u5206\u6bb5\u5bfc\u51fa\u548c\u5728\u4e0d\u540c\u8bbe\u5907\/\u5e73\u53f0\u4e0a\u5bfc\u5165\u3002 MySQL \u5206\u6bb5\u5bfc\u51fa\u6570\u636e\u7684\u65b9\u6cd5 MySQL \u5bfc\u51fa\u6570\u636e\u65f6\uff0c\u901a\u5e38\u9700\u8981\u5bfc\u51fa\u6574\u4e2a\u8868\u7684\u5185\u5bb9\u3002\u4f46\u5728\u67d0\u4e9b\u60c5\u51b5\u4e0b\uff0c\u6211\u4eec\u9700\u8981\u5206\u6bb5\u5bfc\u51fa\u6570\u636e\uff0c\u4f8b\u5982\uff1a \u5bfc\u51fa\u6570\u636e\u91cf\u8fc7\u5927\uff0c\u5bfc\u81f4\u5bfc\u51fa\u8fc7\u7a0b\u957f\u65f6\u95f4\u5360\u7528\u670d\u52a1\u5668\u8d44\u6e90 \u9700\u8981\u5c06\u6570\u636e\u5206\u53d1\u5230\u591a\u4e2a\u8bbe\u5907\u6216\u5e73\u53f0 MySQL \u63d0\u4f9b\u4e86\u4e24\u79cd\u65b9\u6cd5\u6765\u5206\u6bb5\u5bfc\u51fa\u6570\u636e\uff1a \u65b9\u6cd5\u4e00\uff1a\u4f7f\u7528 LIMIT \u5b50\u53e5 LIMIT \u5b50\u53e5\u53ef\u4ee5\u6307\u5b9a\u6bcf\u6b21\u67e5\u8be2\u8fd4\u56de\u7684\u8bb0\u5f55\u6570\u91cf\u3002\u53ef\u4ee5\u4f7f\u7528\u5b83\u6765\u5206\u6bb5\u5bfc\u51fa\u6570\u636e\uff1a SELECT * FROM table_name LIMIT 1000 OFFSET 0; SELECT * FROM table_name LIMIT 1000 OFFSET 1000; SELECT * FROM table_name LIMIT 1000 OFFSET 2000; &#8230; \u767b\u5f55\u540e\u590d\u5236 OFFSET \u5b50\u53e5\u6307\u5b9a\u4ece\u7b2c\u51e0\u4e2a\u8bb0\u5f55\u5f00\u59cb\u67e5\u8be2\u3002\u901a\u8fc7\u9012\u589e OFFSET \u7684\u503c\uff0c\u53ef\u4ee5\u5206\u6bb5\u5bfc\u51fa\u6570\u636e\u3002 \u65b9\u6cd5\u4e8c\uff1a\u4f7f\u7528 dump \u5de5\u5177 mysqldump [&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-6246","post","type-post","status-publish","format-standard","hentry","category-16"],"_links":{"self":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6246","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=6246"}],"version-history":[{"count":0,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/posts\/6246\/revisions"}],"wp:attachment":[{"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/media?parent=6246"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/categories?post=6246"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fwq.ai\/blog\/wp-json\/wp\/v2\/tags?post=6246"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}