{"id":3965,"date":"2019-03-07T18:21:47","date_gmt":"2019-03-07T10:21:47","guid":{"rendered":"http:\/\/www.xttblog.com\/?p=3965"},"modified":"2019-03-07T18:21:47","modified_gmt":"2019-03-07T10:21:47","slug":"mysql-%e6%b5%b7%e9%87%8f%e6%95%b0%e6%8d%ae%e7%9a%84-5-%e7%a7%8d%e5%88%86%e9%a1%b5%e6%96%b9%e6%b3%95%e5%92%8c%e4%bc%98%e5%8c%96%e6%8a%80%e5%b7%a7","status":"publish","type":"post","link":"https:\/\/www.xttblog.com\/?p=3965","title":{"rendered":"MySQL \u6d77\u91cf\u6570\u636e\u7684 5 \u79cd\u5206\u9875\u65b9\u6cd5\u548c\u4f18\u5316\u6280\u5de7"},"content":{"rendered":"<p>\n\t\u6628\u5929\uff0c\u7fa4\u91cc\u6709\u4e00\u4e2a\u7f51\u53cb\u95ee\u6211\u5173\u4e8e MySQL \u5927\u6570\u636e\u91cf\u5206\u9875\u7684\u95ee\u9898\u3002\u6709\u4eba\u56de\u7b54\u8bf4\u7528\u7f13\u5b58 Redis\uff0c\u8fd9\u4e2a\u5c31\u6bd4\u8f83\u9ebb\u70e6\u4e86\u3002\u800c\u4e14\u522b\u4eba\u95ee\u7684\u662f MySQL \u5206\u9875\uff0c\u800c\u4e0d\u662f\u67b6\u6784\u5982\u4f55\u8bbe\u8ba1\uff01\n<\/p>\n<p>\n\t\u90a3\u4e48\u6211\u4eca\u5929\u5c31\u6765\u5206\u4eab\u4e00\u4e0b\uff0c5 \u79cd\u5e38\u89c1\u7684 MySQL Limit \u5206\u9875\u65b9\u6cd5\u548c\u4f18\u5316\u6280\u5de7\u3002\n<\/p>\n<p>\n\t\u7b2c\u4e00\u79cd\u65b9\u6cd5\uff0c\u76f4\u63a5\u4f7f\u7528\u6570\u636e\u5e93\u63d0\u4f9b\u7684 SQL \u8bed\u53e5 limit \u6765\u5206\u9875\u3002\n<\/p>\n<pre class=\"brush:sql;\">\r\nSELECT * FROM \u8868\u540d\u79f0 LIMIT M,N<\/pre>\n<p>\n\t\u9002\u7528\u4e8e\u6570\u636e\u91cf\u8f83\u5c11\u7684\u60c5\u51b5\u3002\u7f3a\u70b9\u662f\uff0c\u5168\u8868\u626b\u63cf\uff0c\u901f\u5ea6\u4f1a\u5f88\u6162\u4e14\u6709\u7684\u6570\u636e\u5e93\u7ed3\u679c\u96c6\u8fd4\u56de\u4e0d\u7a33\u5b9a(\u5982\u67d0\u6b21\u8fd4\u56de1,2,3,\u53e6\u5916\u7684\u4e00\u6b21\u8fd4\u56de2,1,3)\u3002Limit \u9650\u5236\u7684\u662f\u4ece\u7ed3\u679c\u96c6\u7684 M \u4f4d\u7f6e\u5904\u53d6\u51fa N \u6761\u8f93\u51fa\uff0c\u5176\u4f59\u629b\u5f03\u3002\n<\/p>\n<p>\n\t\u65b9\u6cd5\u4e8c\uff0c\u5efa\u7acb\u4e3b\u952e\u6216\u552f\u4e00\u7d22\u5f15\uff0c\u5229\u7528\u7d22\u5f15(\u5047\u8bbe\u6bcf\u9875 10 \u6761)\u3002\n<\/p>\n<pre class=\"brush:sql;\">\r\nSELECT * FROM \u8868\u540d\u79f0 WHERE id_pk &gt; (pageNum * 10) LIMIT M<\/pre>\n<p>\n\t\u9002\u7528\u4e8e\u6570\u636e\u91cf\u8f83\u591a\u7684\u60c5\u51b5\u3002\u8fd9\u6837\u65b9\u6cd5\uff0c\u4f1a\u4f7f\u7528\u7d22\u5f15\u626b\u63cf\uff0c\u901f\u5ea6\u4f1a\u5f88\u5feb\u3002\u5982\u679c\u4f60\u7684\u6570\u636e\u67e5\u8be2\u51fa\u6765\u5e76\u4e0d\u662f\u6309\u7167 pk_id \u6392\u5e8f\u7684\uff0c\u90a3\u4e48\u5c31\u6709\u53ef\u80fd\u6f0f\u6389\u6570\u636e\u7684\u60c5\u51b5\u3002\u6240\u4ee5\u4f7f\u7528\u7684\u65f6\u5019\u8981\u6ce8\u610f\u3002\u4e0d\u884c\u7684\u8bdd\uff0c\u4f60\u5c31\u7528\u65b9\u6cd5\u4e09\u3002\n<\/p>\n<p>\n\t\u65b9\u6cd5\u4e09\uff0c\u57fa\u4e8e\u7d22\u5f15\u518d\u6392\u5e8f\u3002\n<\/p>\n<pre class=\"brush:sql;\">\r\nSELECT * FROM \u8868\u540d\u79f0 WHERE id_pk &gt; (pageNum*10) ORDER BY id_pk ASC LIMIT M<\/pre>\n<p>\n\t\u8fd9\u79cd\u65b9\u6cd5\u9002\u7528\u4e8e\u6570\u636e\u91cf\u8f83\u591a\u7684\u60c5\u51b5\u3002\u6700\u597d ORDER BY \u540e\u7684\u5217\u5bf9\u8c61\u662f\u4e3b\u952e\u6216\u552f\u4e00\u7d22\u5f15\uff0c\u4f7f\u5f97 ORDER BY \u64cd\u4f5c\u80fd\u5229\u7528\u7d22\u5f15\u3002\n<\/p>\n<p>\n\t\u8fd9\u79cd\u65b9\u6cd5\u7684\u7279\u70b9\u662f\u7d22\u5f15\u626b\u63cf\uff0c\u901f\u5ea6\u4f1a\u5f88\u5feb\u3002\n<\/p>\n<p>\n\t\u65b9\u6cd5\u56db\uff0c\u57fa\u4e8e\u7d22\u5f15\u4f7f\u7528 prepare\uff08\u7b2c\u4e00\u4e2a\u95ee\u53f7\u8868\u793a pageNum\uff0c\u7b2c\u4e8c\u4e2a \uff1f\u8868\u793a\u6bcf\u9875\u5143\u7ec4\u6570\uff09\u3002\n<\/p>\n<pre class=\"brush:sql;\">\r\nPREPARE stmt_name FROM SELECT * FROM \u8868\u540d\u79f0 WHERE id_pk &gt; (\uff1f* \uff1f) ORDER BY id_pk ASC LIMIT M<\/pre>\n<p>\n\t\u8fd9\u4e2a SQL \u5f88\u5389\u5bb3\uff0c\u9002\u5408\u6d77\u91cf\u6570\u636e\u7684\u573a\u666f\u3002\u8fd9\u4e2a\u67e5\u8be2\u4f1a\u4f7f\u7528\u7d22\u5f15\u626b\u63cf\uff0c\u901f\u5ea6\u4f1a\u5f88\u5feb\u3002prepare \u8bed\u53e5\u53c8\u6bd4\u4e00\u822c\u7684\u67e5\u8be2\u8bed\u53e5\u5feb\u4e00\u70b9\u3002\n<\/p>\n<p>\n\t\u65b9\u6848\u4e94\uff0c\u5229\u7528 MySQL \u652f\u6301 ORDER \u64cd\u4f5c\u53ef\u4ee5\u5229\u7528\u7d22\u5f15\u5feb\u901f\u5b9a\u4f4d\u90e8\u5206\u5143\u7ec4\uff0c\u907f\u514d\u5168\u8868\u626b\u63cf\u3002\n<\/p>\n<p>\n\t\u4f8b\u5982\uff1a\u8bfb\u7b2c 101000 \u5230 101019 \u884c\u5143\u7ec4( pk \u662f\u4e3b\u952e\/\u552f\u4e00\u952e)\u3002\n<\/p>\n<pre class=\"brush:java;\">\r\nSELECT * FROM \u8868\u540d\u79f0 WHERE pk &gt;= 101000 ORDER BY pk ASC LIMIT 0,20<\/pre>\n<p>\n\t\u65f6\u95f4\u5173\u7cfb\uff0c\u6211\u90fd\u4e0d\u8d34\u6d4b\u8bd5\u6570\u636e\u4e86\u3002\u6709\u95ee\u9898\uff0c\u660e\u5929\u7fa4\u91cc\u8ba8\u8bba\u3002\n<\/p>\n<p>\n\t\u5b66\u4e60\u662f\u65f6\u523b\u8fdb\u884c\u7684\uff0c\u4e0d\u80fd\u9047\u5230\u95ee\u9898\u4e86\uff0c\u624d\u53bb\u5b66\u3002\u90a3\u5c31\u665a\u4e86\uff0c\u8fd8\u662f\u4e0b\u9762\u8fd9\u4e2a\u8bfe\u7a0b\uff0c\u5f88\u4fbf\u5b9c\u3002\u60f3\u6df1\u5165\u7406\u89e3 MySQL\uff0c\u5efa\u8bae\u4f60\u8fd8\u662f\u770b\u770b\u5427\uff0c\u8fd4\u73b0\u8fd8\u5728\u8fdb\u884c\uff0c\u901a\u8fc7\u6211\u7684\u4e8c\u7ef4\u7801\u8d2d\u4e70\uff0c\u8fd4\u73b0 5 \u5143\u7ea2\u5305\u3002\n<\/p>\n<p>\n\t<img decoding=\"async\" alt=\"MySQL \u662f\u600e\u6837\u8fd0\u884c\u7684\uff1a\u4ece\u6839\u513f\u4e0a\u7406\u89e3 MySQL\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/wx1.sinaimg.cn\/large\/8fa5dcfcgy1g0t9zxvp8cj20p018g43u.jpg\" style=\"width: 900px;height: 1600px\" \/>\n<\/p>\n<p>\n\t\u77e5\u8bc6\u65e0\u4ef7\uff0c\u8fd9\u8fd8\u4e0d\u591f\u4f60\u4e00\u987f\u996d\u94b1\uff0c\u4e5f\u4e0d\u591f\u4f60\u4e00\u5305\u70df\u94b1\u3002<\/p>\n<!-- <audio autoplay=\"autoplay\" height=\"100\" width=\"100\" hidden=\"true\"><source src=\"https:\/\/c.coka.la\/orAvPR.mp3\" type=\"audio\/mp3\"\/><\/audio><img decoding=\"async\" src=\"https:\/\/images.weserv.nl\/?url=https:\/\/ws3.sinaimg.cn\/large\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/> --><p><!-- <img decoding=\"async\" src=\"https:\/\/raw.githubusercontent.com\/xmt1139057136\/xttblog\/master\/8fa5dcfcgy1g4em3rzar5j20ib089ae0.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/>--><img decoding=\"async\" src=\"https:\/\/saas.51autoparts.cn\/api\/admin\/sys-file\/oss\/file?fileName=84db51f8561e448f9a4fda2eff0811f9.jpg\" alt=\"\u4e1a\u4f59\u8349\u516c\u4f17\u53f7\"\/><\/p><p>\u6700\u540e\uff0c\u6b22\u8fce\u5173\u6ce8\u6211\u7684\u4e2a\u4eba\u5fae\u4fe1\u516c\u4f17\u53f7\uff1a\u4e1a\u4f59\u8349\uff08yyucao\uff09\uff01<b>\u53ef\u52a0\u4f5c\u8005\u5fae\u4fe1\u53f7\uff1a<font color=\"red\">xttblog2<\/font>\u3002\u5907\u6ce8\uff1a\u201c1\u201d\uff0c\u6dfb\u52a0\u535a\u4e3b\u5fae\u4fe1\u62c9\u4f60\u8fdb\u5fae\u4fe1\u7fa4\u3002\u5907\u6ce8\u9519\u8bef\u4e0d\u4f1a\u540c\u610f\u597d\u53cb\u7533\u8bf7\u3002<\/b>\u518d\u6b21\u611f\u8c22\u60a8\u7684\u5173\u6ce8\uff01\u540e\u7eed\u6709\u7cbe\u5f69\u5185\u5bb9\u4f1a\u7b2c\u4e00\u65f6\u95f4\u53d1\u7ed9\u60a8\uff01\u539f\u521b\u6587\u7ae0\u6295\u7a3f\u8bf7\u53d1\u9001\u81f3532009913@qq.com\u90ae\u7bb1\u3002\u5546\u52a1\u5408\u4f5c\u4e5f\u53ef\u6dfb\u52a0\u4f5c\u8005\u5fae\u4fe1\u8fdb\u884c\u8054\u7cfb\uff01<\/p><p>\u672c\u6587\u539f\u6587\u51fa\u5904\uff1a<a href=\"https:\/\/www.xttblog.com\">\u4e1a\u4f59\u8349<\/a>\uff1a &raquo; <a href=\"https:\/\/www.xttblog.com\/?p=3965\">MySQL \u6d77\u91cf\u6570\u636e\u7684 5 \u79cd\u5206\u9875\u65b9\u6cd5\u548c\u4f18\u5316\u6280\u5de7<\/a><\/p><!-- <div class=\"bd-reward-stl\"><button id=\"bdRewardBtn\"><span><\/span><\/button><\/div> -->","protected":false},"excerpt":{"rendered":"<p>\u6628\u5929\uff0c\u7fa4\u91cc\u6709\u4e00\u4e2a\u7f51\u53cb\u95ee\u6211\u5173\u4e8e MySQL \u5927\u6570\u636e\u91cf\u5206\u9875\u7684\u95ee\u9898\u3002\u6709\u4eba\u56de\u7b54\u8bf4\u7528\u7f13\u5b58 Redis\uff0c\u8fd9\u4e2a\u5c31\u6bd4\u8f83\u9ebb\u70e6\u4e86\u3002 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[12],"tags":[83,580,291,392,393],"class_list":["post-3965","post","type-post","status-publish","format-standard","hentry","category-sql","tag-mysql","tag-mysql----dba","tag-mysqladmin"],"_links":{"self":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3965","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=3965"}],"version-history":[{"count":1,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3965\/revisions"}],"predecessor-version":[{"id":3966,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=\/wp\/v2\/posts\/3965\/revisions\/3966"}],"wp:attachment":[{"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=3965"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=3965"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.xttblog.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=3965"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}