{"id":1285,"date":"2022-06-20T09:22:15","date_gmt":"2022-06-20T01:22:15","guid":{"rendered":"https:\/\/sanlangcode.com\/?p=1285"},"modified":"2022-06-20T09:22:15","modified_gmt":"2022-06-20T01:22:15","slug":"mysql%e9%ab%98%e6%80%a7%e8%83%bd%e4%bc%98%e5%8c%96%e8%a7%84%e8%8c%83%e5%bb%ba%e8%ae%ae","status":"publish","type":"post","link":"https:\/\/sanlangcode.com\/index.php\/2022\/06\/20\/mysql%e9%ab%98%e6%80%a7%e8%83%bd%e4%bc%98%e5%8c%96%e8%a7%84%e8%8c%83%e5%bb%ba%e8%ae%ae\/","title":{"rendered":"MySQL\u9ad8\u6027\u80fd\u4f18\u5316\u89c4\u8303\u5efa\u8bae"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u6570\u636e\u5e93\u547d\u4ee4\u89c4\u8303<\/h2>\n\n\n\n<p>\u2022\u6240\u6709\u6570\u636e\u5e93\u5bf9\u8c61\u540d\u79f0\u5fc5\u987b\u4f7f\u7528\u5c0f\u5199\u5b57\u6bcd\u5e76\u7528\u4e0b\u5212\u7ebf\u5206\u5272\u2022\u6240\u6709\u6570\u636e\u5e93\u5bf9\u8c61\u540d\u79f0\u7981\u6b62\u4f7f\u7528 MySQL \u4fdd\u7559\u5173\u952e\u5b57\uff08\u5982\u679c\u8868\u540d\u4e2d\u5305\u542b\u5173\u952e\u5b57\u67e5\u8be2\u65f6\uff0c\u9700\u8981\u5c06\u5176\u7528\u5355\u5f15\u53f7\u62ec\u8d77\u6765\uff09\u2022\u6570\u636e\u5e93\u5bf9\u8c61\u7684\u547d\u540d\u8981\u80fd\u505a\u5230\u89c1\u540d\u8bc6\u610f\uff0c\u5e76\u4e14\u6700\u540e\u4e0d\u8981\u8d85\u8fc7 32 \u4e2a\u5b57\u7b26\u2022\u4e34\u65f6\u5e93\u8868\u5fc5\u987b\u4ee5 tmp_\u4e3a\u524d\u7f00\u5e76\u4ee5\u65e5\u671f\u4e3a\u540e\u7f00\uff0c\u5907\u4efd\u8868\u5fc5\u987b\u4ee5 bak_\u4e3a\u524d\u7f00\u5e76\u4ee5\u65e5\u671f (\u65f6\u95f4\u6233) \u4e3a\u540e\u7f00\u2022\u6240\u6709\u5b58\u50a8\u76f8\u540c\u6570\u636e\u7684\u5217\u540d\u548c\u5217\u7c7b\u578b\u5fc5\u987b\u4e00\u81f4\uff08\u4e00\u822c\u4f5c\u4e3a\u5173\u8054\u5217\uff0c\u5982\u679c\u67e5\u8be2\u65f6\u5173\u8054\u5217\u7c7b\u578b\u4e0d\u4e00\u81f4\u4f1a\u81ea\u52a8\u8fdb\u884c\u6570\u636e\u7c7b\u578b\u9690\u5f0f\u8f6c\u6362\uff0c\u4f1a\u9020\u6210\u5217\u4e0a\u7684\u7d22\u5f15\u5931\u6548\uff0c\u5bfc\u81f4\u67e5\u8be2\u6548\u7387\u964d\u4f4e\uff09<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u6570\u636e\u5e93\u57fa\u672c\u8bbe\u8ba1\u89c4\u8303<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. \u6240\u6709\u8868\u5fc5\u987b\u4f7f\u7528 Innodb \u5b58\u50a8\u5f15\u64ce<\/h3>\n\n\n\n<p>\u6ca1\u6709\u7279\u6b8a\u8981\u6c42\uff08\u5373 Innodb \u65e0\u6cd5\u6ee1\u8db3\u7684\u529f\u80fd\u5982\uff1a\u5217\u5b58\u50a8\uff0c\u5b58\u50a8\u7a7a\u95f4\u6570\u636e\u7b49\uff09\u7684\u60c5\u51b5\u4e0b\uff0c\u6240\u6709\u8868\u5fc5\u987b\u4f7f\u7528 Innodb \u5b58\u50a8\u5f15\u64ce\uff08MySQL5.5 \u4e4b\u524d\u9ed8\u8ba4\u4f7f\u7528 Myisam\uff0c5.6 \u4ee5\u540e\u9ed8\u8ba4\u7684\u4e3a Innodb\uff09\u3002<\/p>\n\n\n\n<p>Innodb \u652f\u6301\u4e8b\u52a1\uff0c\u652f\u6301\u884c\u7ea7\u9501\uff0c\u66f4\u597d\u7684\u6062\u590d\u6027\uff0c\u9ad8\u5e76\u53d1\u4e0b\u6027\u80fd\u66f4\u597d\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. \u6570\u636e\u5e93\u548c\u8868\u7684\u5b57\u7b26\u96c6\u7edf\u4e00\u4f7f\u7528 UTF8<\/h3>\n\n\n\n<p>\u517c\u5bb9\u6027\u66f4\u597d\uff0c\u7edf\u4e00\u5b57\u7b26\u96c6\u53ef\u4ee5\u907f\u514d\u7531\u4e8e\u5b57\u7b26\u96c6\u8f6c\u6362\u4ea7\u751f\u7684\u4e71\u7801\uff0c\u4e0d\u540c\u7684\u5b57\u7b26\u96c6\u8fdb\u884c\u6bd4\u8f83\u524d\u9700\u8981\u8fdb\u884c\u8f6c\u6362\u4f1a\u9020\u6210\u7d22\u5f15\u5931\u6548\uff0c\u5982\u679c\u6570\u636e\u5e93\u4e2d\u6709\u5b58\u50a8 emoji \u8868\u60c5\u7684\u9700\u8981\uff0c\u5b57\u7b26\u96c6\u9700\u8981\u91c7\u7528 utf8mb4 \u5b57\u7b26\u96c6\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3. \u6240\u6709\u8868\u548c\u5b57\u6bb5\u90fd\u9700\u8981\u6dfb\u52a0\u6ce8\u91ca<\/h3>\n\n\n\n<p>\u4f7f\u7528 comment \u4ece\u53e5\u6dfb\u52a0\u8868\u548c\u5217\u7684\u5907\u6ce8\uff0c\u4ece\u4e00\u5f00\u59cb\u5c31\u8fdb\u884c\u6570\u636e\u5b57\u5178\u7684\u7ef4\u62a4<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4. \u5c3d\u91cf\u63a7\u5236\u5355\u8868\u6570\u636e\u91cf\u7684\u5927\u5c0f,\u5efa\u8bae\u63a7\u5236\u5728 500 \u4e07\u4ee5\u5185\u3002<\/h3>\n\n\n\n<p>500 \u4e07\u5e76\u4e0d\u662f MySQL \u6570\u636e\u5e93\u7684\u9650\u5236\uff0c\u8fc7\u5927\u4f1a\u9020\u6210\u4fee\u6539\u8868\u7ed3\u6784\uff0c\u5907\u4efd\uff0c\u6062\u590d\u90fd\u4f1a\u6709\u5f88\u5927\u7684\u95ee\u9898\u3002<\/p>\n\n\n\n<p>\u53ef\u4ee5\u7528\u5386\u53f2\u6570\u636e\u5f52\u6863\uff08\u5e94\u7528\u4e8e\u65e5\u5fd7\u6570\u636e\uff09\uff0c\u5206\u5e93\u5206\u8868\uff08\u5e94\u7528\u4e8e\u4e1a\u52a1\u6570\u636e\uff09\u7b49\u624b\u6bb5\u6765\u63a7\u5236\u6570\u636e\u91cf\u5927\u5c0f<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">5. \u8c28\u614e\u4f7f\u7528 MySQL \u5206\u533a\u8868<\/h3>\n\n\n\n<p>\u5206\u533a\u8868\u5728\u7269\u7406\u4e0a\u8868\u73b0\u4e3a\u591a\u4e2a\u6587\u4ef6\uff0c\u5728\u903b\u8f91\u4e0a\u8868\u73b0\u4e3a\u4e00\u4e2a\u8868\uff1b<\/p>\n\n\n\n<p>\u8c28\u614e\u9009\u62e9\u5206\u533a\u952e\uff0c\u8de8\u5206\u533a\u67e5\u8be2\u6548\u7387\u53ef\u80fd\u66f4\u4f4e\uff1b<\/p>\n\n\n\n<p>\u5efa\u8bae\u91c7\u7528\u7269\u7406\u5206\u8868\u7684\u65b9\u5f0f\u7ba1\u7406\u5927\u6570\u636e\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">6.\u5c3d\u91cf\u505a\u5230\u51b7\u70ed\u6570\u636e\u5206\u79bb,\u51cf\u5c0f\u8868\u7684\u5bbd\u5ea6<\/h3>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>MySQL \u9650\u5236\u6bcf\u4e2a\u8868\u6700\u591a\u5b58\u50a8 4096 \u5217\uff0c\u5e76\u4e14\u6bcf\u4e00\u884c\u6570\u636e\u7684\u5927\u5c0f\u4e0d\u80fd\u8d85\u8fc7 65535 \u5b57\u8282\u3002<\/p><\/blockquote>\n\n\n\n<p>\u51cf\u5c11\u78c1\u76d8 IO,\u4fdd\u8bc1\u70ed\u6570\u636e\u7684\u5185\u5b58\u7f13\u5b58\u547d\u4e2d\u7387\uff08\u8868\u8d8a\u5bbd\uff0c\u628a\u8868\u88c5\u8f7d\u8fdb\u5185\u5b58\u7f13\u51b2\u6c60\u65f6\u6240\u5360\u7528\u7684\u5185\u5b58\u4e5f\u5c31\u8d8a\u5927,\u4e5f\u4f1a\u6d88\u8017\u66f4\u591a\u7684 IO\uff09\uff1b<\/p>\n\n\n\n<p>\u66f4\u6709\u6548\u7684\u5229\u7528\u7f13\u5b58\uff0c\u907f\u514d\u8bfb\u5165\u65e0\u7528\u7684\u51b7\u6570\u636e\uff1b<\/p>\n\n\n\n<p>\u7ecf\u5e38\u4e00\u8d77\u4f7f\u7528\u7684\u5217\u653e\u5230\u4e00\u4e2a\u8868\u4e2d\uff08\u907f\u514d\u66f4\u591a\u7684\u5173\u8054\u64cd\u4f5c\uff09\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">7. \u7981\u6b62\u5728\u8868\u4e2d\u5efa\u7acb\u9884\u7559\u5b57\u6bb5<\/h3>\n\n\n\n<p>\u9884\u7559\u5b57\u6bb5\u7684\u547d\u540d\u5f88\u96be\u505a\u5230\u89c1\u540d\u8bc6\u4e49\u3002<\/p>\n\n\n\n<p>\u9884\u7559\u5b57\u6bb5\u65e0\u6cd5\u786e\u8ba4\u5b58\u50a8\u7684\u6570\u636e\u7c7b\u578b\uff0c\u6240\u4ee5\u65e0\u6cd5\u9009\u62e9\u5408\u9002\u7684\u7c7b\u578b\u3002<\/p>\n\n\n\n<p>\u5bf9\u9884\u7559\u5b57\u6bb5\u7c7b\u578b\u7684\u4fee\u6539\uff0c\u4f1a\u5bf9\u8868\u8fdb\u884c\u9501\u5b9a\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">8. \u7981\u6b62\u5728\u6570\u636e\u5e93\u4e2d\u5b58\u50a8\u56fe\u7247,\u6587\u4ef6\u7b49\u5927\u7684\u4e8c\u8fdb\u5236\u6570\u636e<\/h3>\n\n\n\n<p>\u901a\u5e38\u6587\u4ef6\u5f88\u5927\uff0c\u4f1a\u77ed\u65f6\u95f4\u5185\u9020\u6210\u6570\u636e\u91cf\u5feb\u901f\u589e\u957f\uff0c\u6570\u636e\u5e93\u8fdb\u884c\u6570\u636e\u5e93\u8bfb\u53d6\u65f6\uff0c\u901a\u5e38\u4f1a\u8fdb\u884c\u5927\u91cf\u7684\u968f\u673a IO \u64cd\u4f5c\uff0c\u6587\u4ef6\u5f88\u5927\u65f6\uff0cIO \u64cd\u4f5c\u5f88\u8017\u65f6\u3002<\/p>\n\n\n\n<p>\u901a\u5e38\u5b58\u50a8\u4e8e\u6587\u4ef6\u670d\u52a1\u5668\uff0c\u6570\u636e\u5e93\u53ea\u5b58\u50a8\u6587\u4ef6\u5730\u5740\u4fe1\u606f<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">9. \u7981\u6b62\u5728\u7ebf\u4e0a\u505a\u6570\u636e\u5e93\u538b\u529b\u6d4b\u8bd5<\/h3>\n\n\n\n<h3 class=\"wp-block-heading\">10. \u7981\u6b62\u4ece\u5f00\u53d1\u73af\u5883,\u6d4b\u8bd5\u73af\u5883\u76f4\u63a5\u8fde\u63a5\u751f\u6210\u73af\u5883\u6570\u636e\u5e93<\/h3>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u6570\u636e\u5e93\u5b57\u6bb5\u8bbe\u8ba1\u89c4\u8303<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. \u4f18\u5148\u9009\u62e9\u7b26\u5408\u5b58\u50a8\u9700\u8981\u7684\u6700\u5c0f\u7684\u6570\u636e\u7c7b\u578b<\/h3>\n\n\n\n<p><strong>\u539f\u56e0\uff1a<\/strong><\/p>\n\n\n\n<p>\u5217\u7684\u5b57\u6bb5\u8d8a\u5927\uff0c\u5efa\u7acb\u7d22\u5f15\u65f6\u6240\u9700\u8981\u7684\u7a7a\u95f4\u4e5f\u5c31\u8d8a\u5927\uff0c\u8fd9\u6837\u4e00\u9875\u4e2d\u6240\u80fd\u5b58\u50a8\u7684\u7d22\u5f15\u8282\u70b9\u7684\u6570\u91cf\u4e5f\u5c31\u8d8a\u5c11\u4e5f\u8d8a\u5c11\uff0c\u5728\u904d\u5386\u65f6\u6240\u9700\u8981\u7684 IO \u6b21\u6570\u4e5f\u5c31\u8d8a\u591a\uff0c\u7d22\u5f15\u7684\u6027\u80fd\u4e5f\u5c31\u8d8a\u5dee\u3002<\/p>\n\n\n\n<p><strong>\u65b9\u6cd5\uff1a<\/strong><\/p>\n\n\n\n<p><strong>a.\u5c06\u5b57\u7b26\u4e32\u8f6c\u6362\u6210\u6570\u5b57\u7c7b\u578b\u5b58\u50a8,\u5982:\u5c06 IP \u5730\u5740\u8f6c\u6362\u6210\u6574\u5f62\u6570\u636e<\/strong><\/p>\n\n\n\n<p>MySQL \u63d0\u4f9b\u4e86\u4e24\u4e2a\u65b9\u6cd5\u6765\u5904\u7406 ip \u5730\u5740<\/p>\n\n\n\n<p>\u2022inet_aton \u628a ip \u8f6c\u4e3a\u65e0\u7b26\u53f7\u6574\u578b (4-8 \u4f4d)\u2022inet_ntoa \u628a\u6574\u578b\u7684 ip \u8f6c\u4e3a\u5730\u5740<\/p>\n\n\n\n<p>\u63d2\u5165\u6570\u636e\u524d\uff0c\u5148\u7528 inet_aton \u628a ip \u5730\u5740\u8f6c\u4e3a\u6574\u578b\uff0c\u53ef\u4ee5\u8282\u7701\u7a7a\u95f4\uff0c\u663e\u793a\u6570\u636e\u65f6\uff0c\u4f7f\u7528 inet_ntoa \u628a\u6574\u578b\u7684 ip \u5730\u5740\u8f6c\u4e3a\u5730\u5740\u663e\u793a\u5373\u53ef\u3002<\/p>\n\n\n\n<p><strong>b.\u5bf9\u4e8e\u975e\u8d1f\u578b\u7684\u6570\u636e (\u5982\u81ea\u589e ID,\u6574\u578b IP) \u6765\u8bf4,\u8981\u4f18\u5148\u4f7f\u7528\u65e0\u7b26\u53f7\u6574\u578b\u6765\u5b58\u50a8<\/strong><\/p>\n\n\n\n<p><strong>\u539f\u56e0\uff1a<\/strong><\/p>\n\n\n\n<p>\u65e0\u7b26\u53f7\u76f8\u5bf9\u4e8e\u6709\u7b26\u53f7\u53ef\u4ee5\u591a\u51fa\u4e00\u500d\u7684\u5b58\u50a8\u7a7a\u95f4<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><\/li><\/ul>\n\n\n\n<pre class=\"wp-block-preformatted\"><code>SIGNED INT -2147483648~2147483647<\/code><code>UNSIGNED INT 0~4294967295<\/code><\/pre>\n\n\n\n<p>VARCHAR(N) \u4e2d\u7684 N \u4ee3\u8868\u7684\u662f\u5b57\u7b26\u6570\uff0c\u800c\u4e0d\u662f\u5b57\u8282\u6570\uff0c\u4f7f\u7528 UTF8 \u5b58\u50a8 255 \u4e2a\u6c49\u5b57 Varchar(255)=765 \u4e2a\u5b57\u8282\u3002<strong>\u8fc7\u5927\u7684\u957f\u5ea6\u4f1a\u6d88\u8017\u66f4\u591a\u7684\u5185\u5b58\u3002<\/strong><\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. \u907f\u514d\u4f7f\u7528 TEXT,BLOB \u6570\u636e\u7c7b\u578b\uff0c\u6700\u5e38\u89c1\u7684 TEXT \u7c7b\u578b\u53ef\u4ee5\u5b58\u50a8 64k \u7684\u6570\u636e<\/h3>\n\n\n\n<p><strong>a. \u5efa\u8bae\u628a BLOB \u6216\u662f TEXT \u5217\u5206\u79bb\u5230\u5355\u72ec\u7684\u6269\u5c55\u8868\u4e2d<\/strong><\/p>\n\n\n\n<p>MySQL \u5185\u5b58\u4e34\u65f6\u8868\u4e0d\u652f\u6301 TEXT\u3001BLOB \u8fd9\u6837\u7684\u5927\u6570\u636e\u7c7b\u578b\uff0c\u5982\u679c\u67e5\u8be2\u4e2d\u5305\u542b\u8fd9\u6837\u7684\u6570\u636e\uff0c\u5728\u6392\u5e8f\u7b49\u64cd\u4f5c\u65f6\uff0c\u5c31\u4e0d\u80fd\u4f7f\u7528\u5185\u5b58\u4e34\u65f6\u8868\uff0c\u5fc5\u987b\u4f7f\u7528\u78c1\u76d8\u4e34\u65f6\u8868\u8fdb\u884c\u3002\u800c\u4e14\u5bf9\u4e8e\u8fd9\u79cd\u6570\u636e\uff0cMySQL \u8fd8\u662f\u8981\u8fdb\u884c\u4e8c\u6b21\u67e5\u8be2\uff0c\u4f1a\u4f7f sql \u6027\u80fd\u53d8\u5f97\u5f88\u5dee\uff0c\u4f46\u662f\u4e0d\u662f\u8bf4\u4e00\u5b9a\u4e0d\u80fd\u4f7f\u7528\u8fd9\u6837\u7684\u6570\u636e\u7c7b\u578b\u3002<\/p>\n\n\n\n<p>\u5982\u679c\u4e00\u5b9a\u8981\u4f7f\u7528\uff0c\u5efa\u8bae\u628a BLOB \u6216\u662f TEXT \u5217\u5206\u79bb\u5230\u5355\u72ec\u7684\u6269\u5c55\u8868\u4e2d\uff0c\u67e5\u8be2\u65f6\u4e00\u5b9a\u4e0d\u8981\u4f7f\u7528 select * \u800c\u53ea\u9700\u8981\u53d6\u51fa\u5fc5\u8981\u7684\u5217\uff0c\u4e0d\u9700\u8981 TEXT \u5217\u7684\u6570\u636e\u65f6\u4e0d\u8981\u5bf9\u8be5\u5217\u8fdb\u884c\u67e5\u8be2\u3002<\/p>\n\n\n\n<p><strong>2\u3001TEXT \u6216 BLOB \u7c7b\u578b\u53ea\u80fd\u4f7f\u7528\u524d\u7f00\u7d22\u5f15<\/strong><\/p>\n\n\n\n<p>\u56e0\u4e3aMySQL<sup>[1]<\/sup>&nbsp;\u5bf9\u7d22\u5f15\u5b57\u6bb5\u957f\u5ea6\u662f\u6709\u9650\u5236\u7684\uff0c\u6240\u4ee5 TEXT \u7c7b\u578b\u53ea\u80fd\u4f7f\u7528\u524d\u7f00\u7d22\u5f15\uff0c\u5e76\u4e14 TEXT \u5217\u4e0a\u662f\u4e0d\u80fd\u6709\u9ed8\u8ba4\u503c\u7684<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3. \u907f\u514d\u4f7f\u7528 ENUM \u7c7b\u578b<\/h3>\n\n\n\n<p>\u4fee\u6539 ENUM \u503c\u9700\u8981\u4f7f\u7528 ALTER \u8bed\u53e5<\/p>\n\n\n\n<p>ENUM \u7c7b\u578b\u7684 ORDER BY \u64cd\u4f5c\u6548\u7387\u4f4e\uff0c\u9700\u8981\u989d\u5916\u64cd\u4f5c<\/p>\n\n\n\n<p>\u7981\u6b62\u4f7f\u7528\u6570\u503c\u4f5c\u4e3a ENUM \u7684\u679a\u4e3e\u503c<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4. \u5c3d\u53ef\u80fd\u628a\u6240\u6709\u5217\u5b9a\u4e49\u4e3a NOT NULL<\/h3>\n\n\n\n<p><strong>\u539f\u56e0\uff1a<\/strong><\/p>\n\n\n\n<p>\u7d22\u5f15 NULL \u5217\u9700\u8981\u989d\u5916\u7684\u7a7a\u95f4\u6765\u4fdd\u5b58\uff0c\u6240\u4ee5\u8981\u5360\u7528\u66f4\u591a\u7684\u7a7a\u95f4<\/p>\n\n\n\n<p>\u8fdb\u884c\u6bd4\u8f83\u548c\u8ba1\u7b97\u65f6\u8981\u5bf9 NULL \u503c\u505a\u7279\u522b\u7684\u5904\u7406<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">5. \u4f7f\u7528 TIMESTAMP(4 \u4e2a\u5b57\u8282) \u6216 DATETIME \u7c7b\u578b (8 \u4e2a\u5b57\u8282) \u5b58\u50a8\u65f6\u95f4<\/h3>\n\n\n\n<p>TIMESTAMP \u5b58\u50a8\u7684\u65f6\u95f4\u8303\u56f4 1970-01-01 00:00:01 ~ 2038-01-19-03:14:07<\/p>\n\n\n\n<p>TIMESTAMP \u5360\u7528 4 \u5b57\u8282\u548c INT \u76f8\u540c\uff0c\u4f46\u6bd4 INT \u53ef\u8bfb\u6027\u9ad8<\/p>\n\n\n\n<p>\u8d85\u51fa TIMESTAMP \u53d6\u503c\u8303\u56f4\u7684\u4f7f\u7528 DATETIME \u7c7b\u578b\u5b58\u50a8<\/p>\n\n\n\n<p><strong>\u7ecf\u5e38\u4f1a\u6709\u4eba\u7528\u5b57\u7b26\u4e32\u5b58\u50a8\u65e5\u671f\u578b\u7684\u6570\u636e\uff08\u4e0d\u6b63\u786e\u7684\u505a\u6cd5\uff09<\/strong><\/p>\n\n\n\n<p>\u2022\u7f3a\u70b9 1\uff1a\u65e0\u6cd5\u7528\u65e5\u671f\u51fd\u6570\u8fdb\u884c\u8ba1\u7b97\u548c\u6bd4\u8f83\u2022\u7f3a\u70b9 2\uff1a\u7528\u5b57\u7b26\u4e32\u5b58\u50a8\u65e5\u671f\u8981\u5360\u7528\u66f4\u591a\u7684\u7a7a\u95f4<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">6. \u540c\u8d22\u52a1\u76f8\u5173\u7684\u91d1\u989d\u7c7b\u6570\u636e\u5fc5\u987b\u4f7f\u7528 decimal \u7c7b\u578b<\/h3>\n\n\n\n<p>\u2022\u975e\u7cbe\u51c6\u6d6e\u70b9\uff1afloat,double\u2022\u7cbe\u51c6\u6d6e\u70b9\uff1adecimal<\/p>\n\n\n\n<p>Decimal \u7c7b\u578b\u4e3a\u7cbe\u51c6\u6d6e\u70b9\u6570\uff0c\u5728\u8ba1\u7b97\u65f6\u4e0d\u4f1a\u4e22\u5931\u7cbe\u5ea6<\/p>\n\n\n\n<p>\u5360\u7528\u7a7a\u95f4\u7531\u5b9a\u4e49\u7684\u5bbd\u5ea6\u51b3\u5b9a\uff0c\u6bcf 4 \u4e2a\u5b57\u8282\u53ef\u4ee5\u5b58\u50a8 9 \u4f4d\u6570\u5b57\uff0c\u5e76\u4e14\u5c0f\u6570\u70b9\u8981\u5360\u7528\u4e00\u4e2a\u5b57\u8282<\/p>\n\n\n\n<p>\u53ef\u7528\u4e8e\u5b58\u50a8\u6bd4 bigint \u66f4\u5927\u7684\u6574\u578b\u6570\u636e<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u7d22\u5f15\u8bbe\u8ba1\u89c4\u8303<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. \u9650\u5236\u6bcf\u5f20\u8868\u4e0a\u7684\u7d22\u5f15\u6570\u91cf,\u5efa\u8bae\u5355\u5f20\u8868\u7d22\u5f15\u4e0d\u8d85\u8fc7 5 \u4e2a<\/h3>\n\n\n\n<p>\u7d22\u5f15\u5e76\u4e0d\u662f\u8d8a\u591a\u8d8a\u597d\uff01\u7d22\u5f15\u53ef\u4ee5\u63d0\u9ad8\u6548\u7387\u540c\u6837\u53ef\u4ee5\u964d\u4f4e\u6548\u7387\u3002<\/p>\n\n\n\n<p>\u7d22\u5f15\u53ef\u4ee5\u589e\u52a0\u67e5\u8be2\u6548\u7387\uff0c\u4f46\u540c\u6837\u4e5f\u4f1a\u964d\u4f4e\u63d2\u5165\u548c\u66f4\u65b0\u7684\u6548\u7387\uff0c\u751a\u81f3\u6709\u4e9b\u60c5\u51b5\u4e0b\u4f1a\u964d\u4f4e\u67e5\u8be2\u6548\u7387\u3002<\/p>\n\n\n\n<p>\u56e0\u4e3a MySQL \u4f18\u5316\u5668\u5728\u9009\u62e9\u5982\u4f55\u4f18\u5316\u67e5\u8be2\u65f6\uff0c\u4f1a\u6839\u636e\u7edf\u4e00\u4fe1\u606f\uff0c\u5bf9\u6bcf\u4e00\u4e2a\u53ef\u4ee5\u7528\u5230\u7684\u7d22\u5f15\u6765\u8fdb\u884c\u8bc4\u4f30\uff0c\u4ee5\u751f\u6210\u51fa\u4e00\u4e2a\u6700\u597d\u7684\u6267\u884c\u8ba1\u5212\uff0c\u5982\u679c\u540c\u65f6\u6709\u5f88\u591a\u4e2a\u7d22\u5f15\u90fd\u53ef\u4ee5\u7528\u4e8e\u67e5\u8be2\uff0c\u5c31\u4f1a\u589e\u52a0 MySQL \u4f18\u5316\u5668\u751f\u6210\u6267\u884c\u8ba1\u5212\u7684\u65f6\u95f4\uff0c\u540c\u6837\u4f1a\u964d\u4f4e\u67e5\u8be2\u6027\u80fd\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. \u7981\u6b62\u7ed9\u8868\u4e2d\u7684\u6bcf\u4e00\u5217\u90fd\u5efa\u7acb\u5355\u72ec\u7684\u7d22\u5f15<\/h3>\n\n\n\n<p>5.6 \u7248\u672c\u4e4b\u524d\uff0c\u4e00\u4e2a sql \u53ea\u80fd\u4f7f\u7528\u5230\u4e00\u4e2a\u8868\u4e2d\u7684\u4e00\u4e2a\u7d22\u5f15\uff0c5.6 \u4ee5\u540e\uff0c\u867d\u7136\u6709\u4e86\u5408\u5e76\u7d22\u5f15\u7684\u4f18\u5316\u65b9\u5f0f\uff0c\u4f46\u662f\u8fd8\u662f\u8fdc\u8fdc\u6ca1\u6709\u4f7f\u7528\u4e00\u4e2a\u8054\u5408\u7d22\u5f15\u7684\u67e5\u8be2\u65b9\u5f0f\u597d\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3. \u6bcf\u4e2a Innodb \u8868\u5fc5\u987b\u6709\u4e2a\u4e3b\u952e<\/h3>\n\n\n\n<p>Innodb \u662f\u4e00\u79cd\u7d22\u5f15\u7ec4\u7ec7\u8868\uff1a\u6570\u636e\u7684\u5b58\u50a8\u7684\u903b\u8f91\u987a\u5e8f\u548c\u7d22\u5f15\u7684\u987a\u5e8f\u662f\u76f8\u540c\u7684\u3002\u6bcf\u4e2a\u8868\u90fd\u53ef\u4ee5\u6709\u591a\u4e2a\u7d22\u5f15\uff0c\u4f46\u662f\u8868\u7684\u5b58\u50a8\u987a\u5e8f\u53ea\u80fd\u6709\u4e00\u79cd\u3002<\/p>\n\n\n\n<p>Innodb \u662f\u6309\u7167\u4e3b\u952e\u7d22\u5f15\u7684\u987a\u5e8f\u6765\u7ec4\u7ec7\u8868\u7684<\/p>\n\n\n\n<p>\u2022\u4e0d\u8981\u4f7f\u7528\u66f4\u65b0\u9891\u7e41\u7684\u5217\u4f5c\u4e3a\u4e3b\u952e\uff0c\u4e0d\u9002\u7528\u591a\u5217\u4e3b\u952e\uff08\u76f8\u5f53\u4e8e\u8054\u5408\u7d22\u5f15\uff09\u2022\u4e0d\u8981\u4f7f\u7528 UUID,MD5,HASH,\u5b57\u7b26\u4e32\u5217\u4f5c\u4e3a\u4e3b\u952e\uff08\u65e0\u6cd5\u4fdd\u8bc1\u6570\u636e\u7684\u987a\u5e8f\u589e\u957f\uff09\u2022\u4e3b\u952e\u5efa\u8bae\u4f7f\u7528\u81ea\u589e ID \u503c<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">4. \u5e38\u89c1\u7d22\u5f15\u5217\u5efa\u8bae<\/h3>\n\n\n\n<p>\u2022\u51fa\u73b0\u5728 SELECT\u3001UPDATE\u3001DELETE \u8bed\u53e5\u7684 WHERE \u4ece\u53e5\u4e2d\u7684\u5217\u2022\u5305\u542b\u5728 ORDER BY\u3001GROUP BY\u3001DISTINCT \u4e2d\u7684\u5b57\u6bb5\u2022\u5e76\u4e0d\u8981\u5c06\u7b26\u5408 1 \u548c 2 \u4e2d\u7684\u5b57\u6bb5\u7684\u5217\u90fd\u5efa\u7acb\u4e00\u4e2a\u7d22\u5f15\uff0c \u901a\u5e38\u5c06 1\u30012 \u4e2d\u7684\u5b57\u6bb5\u5efa\u7acb\u8054\u5408\u7d22\u5f15\u6548\u679c\u66f4\u597d\u2022\u591a\u8868 join \u7684\u5173\u8054\u5217<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">5.\u5982\u4f55\u9009\u62e9\u7d22\u5f15\u5217\u7684\u987a\u5e8f<\/h3>\n\n\n\n<p>\u5efa\u7acb\u7d22\u5f15\u7684\u76ee\u7684\u662f\uff1a\u5e0c\u671b\u901a\u8fc7\u7d22\u5f15\u8fdb\u884c\u6570\u636e\u67e5\u627e\uff0c\u51cf\u5c11\u968f\u673a IO\uff0c\u589e\u52a0\u67e5\u8be2\u6027\u80fd \uff0c\u7d22\u5f15\u80fd\u8fc7\u6ee4\u51fa\u8d8a\u5c11\u7684\u6570\u636e\uff0c\u5219\u4ece\u78c1\u76d8\u4e2d\u8bfb\u5165\u7684\u6570\u636e\u4e5f\u5c31\u8d8a\u5c11\u3002<\/p>\n\n\n\n<p>\u2022\u533a\u5206\u5ea6\u6700\u9ad8\u7684\u653e\u5728\u8054\u5408\u7d22\u5f15\u7684\u6700\u5de6\u4fa7\uff08\u533a\u5206\u5ea6=\u5217\u4e2d\u4e0d\u540c\u503c\u7684\u6570\u91cf\/\u5217\u7684\u603b\u884c\u6570\uff09\u2022\u5c3d\u91cf\u628a\u5b57\u6bb5\u957f\u5ea6\u5c0f\u7684\u5217\u653e\u5728\u8054\u5408\u7d22\u5f15\u7684\u6700\u5de6\u4fa7\uff08\u56e0\u4e3a\u5b57\u6bb5\u957f\u5ea6\u8d8a\u5c0f\uff0c\u4e00\u9875\u80fd\u5b58\u50a8\u7684\u6570\u636e\u91cf\u8d8a\u5927\uff0cIO \u6027\u80fd\u4e5f\u5c31\u8d8a\u597d\uff09\u2022\u4f7f\u7528\u6700\u9891\u7e41\u7684\u5217\u653e\u5230\u8054\u5408\u7d22\u5f15\u7684\u5de6\u4fa7\uff08\u8fd9\u6837\u53ef\u4ee5\u6bd4\u8f83\u5c11\u7684\u5efa\u7acb\u4e00\u4e9b\u7d22\u5f15\uff09<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">6. \u907f\u514d\u5efa\u7acb\u5197\u4f59\u7d22\u5f15\u548c\u91cd\u590d\u7d22\u5f15\uff08\u589e\u52a0\u4e86\u67e5\u8be2\u4f18\u5316\u5668\u751f\u6210\u6267\u884c\u8ba1\u5212\u7684\u65f6\u95f4\uff09<\/h3>\n\n\n\n<p>\u2022\u91cd\u590d\u7d22\u5f15\u793a\u4f8b\uff1aprimary key(id)\u3001index(id)\u3001unique index(id)\u2022\u5197\u4f59\u7d22\u5f15\u793a\u4f8b\uff1aindex(a,b,c)\u3001index(a,b)\u3001index(a)<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">7. \u5bf9\u4e8e\u9891\u7e41\u7684\u67e5\u8be2\u4f18\u5148\u8003\u8651\u4f7f\u7528\u8986\u76d6\u7d22\u5f15<\/h3>\n\n\n\n<blockquote class=\"wp-block-quote is-layout-flow wp-block-quote-is-layout-flow\"><p>\u8986\u76d6\u7d22\u5f15\uff1a\u5c31\u662f\u5305\u542b\u4e86\u6240\u6709\u67e5\u8be2\u5b57\u6bb5 (where,select,ordery by,group by \u5305\u542b\u7684\u5b57\u6bb5) \u7684\u7d22\u5f15<\/p><\/blockquote>\n\n\n\n<p><strong>\u8986\u76d6\u7d22\u5f15\u7684\u597d\u5904\uff1a<\/strong><\/p>\n\n\n\n<p>\u2022<strong>\u907f\u514d Innodb \u8868\u8fdb\u884c\u7d22\u5f15\u7684\u4e8c\u6b21\u67e5\u8be2:<\/strong>&nbsp;Innodb \u662f\u4ee5\u805a\u96c6\u7d22\u5f15\u7684\u987a\u5e8f\u6765\u5b58\u50a8\u7684\uff0c\u5bf9\u4e8e Innodb \u6765\u8bf4\uff0c\u4e8c\u7ea7\u7d22\u5f15\u5728\u53f6\u5b50\u8282\u70b9\u4e2d\u6240\u4fdd\u5b58\u7684\u662f\u884c\u7684\u4e3b\u952e\u4fe1\u606f\uff0c\u5982\u679c\u662f\u7528\u4e8c\u7ea7\u7d22\u5f15\u67e5\u8be2\u6570\u636e\u7684\u8bdd\uff0c\u5728\u67e5\u627e\u5230\u76f8\u5e94\u7684\u952e\u503c\u540e\uff0c\u8fd8\u8981\u901a\u8fc7\u4e3b\u952e\u8fdb\u884c\u4e8c\u6b21\u67e5\u8be2\u624d\u80fd\u83b7\u53d6\u6211\u4eec\u771f\u5b9e\u6240\u9700\u8981\u7684\u6570\u636e\u3002\u800c\u5728\u8986\u76d6\u7d22\u5f15\u4e2d\uff0c\u4e8c\u7ea7\u7d22\u5f15\u7684\u952e\u503c\u4e2d\u53ef\u4ee5\u83b7\u53d6\u6240\u6709\u7684\u6570\u636e\uff0c\u907f\u514d\u4e86\u5bf9\u4e3b\u952e\u7684\u4e8c\u6b21\u67e5\u8be2 \uff0c\u51cf\u5c11\u4e86 IO \u64cd\u4f5c\uff0c\u63d0\u5347\u4e86\u67e5\u8be2\u6548\u7387\u3002\u2022<strong>\u53ef\u4ee5\u628a\u968f\u673a IO \u53d8\u6210\u987a\u5e8f IO \u52a0\u5feb\u67e5\u8be2\u6548\u7387:<\/strong>&nbsp;\u7531\u4e8e\u8986\u76d6\u7d22\u5f15\u662f\u6309\u952e\u503c\u7684\u987a\u5e8f\u5b58\u50a8\u7684\uff0c\u5bf9\u4e8e IO \u5bc6\u96c6\u578b\u7684\u8303\u56f4\u67e5\u627e\u6765\u8bf4\uff0c\u5bf9\u6bd4\u968f\u673a\u4ece\u78c1\u76d8\u8bfb\u53d6\u6bcf\u4e00\u884c\u7684\u6570\u636e IO \u8981\u5c11\u7684\u591a\uff0c\u56e0\u6b64\u5229\u7528\u8986\u76d6\u7d22\u5f15\u5728\u8bbf\u95ee\u65f6\u4e5f\u53ef\u4ee5\u628a\u78c1\u76d8\u7684\u968f\u673a\u8bfb\u53d6\u7684 IO \u8f6c\u53d8\u6210\u7d22\u5f15\u67e5\u627e\u7684\u987a\u5e8f IO\u3002<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h3 class=\"wp-block-heading\">8.\u7d22\u5f15 SET \u89c4\u8303<\/h3>\n\n\n\n<p><strong>\u5c3d\u91cf\u907f\u514d\u4f7f\u7528\u5916\u952e\u7ea6\u675f<\/strong><\/p>\n\n\n\n<p>\u2022\u4e0d\u5efa\u8bae\u4f7f\u7528\u5916\u952e\u7ea6\u675f\uff08foreign key\uff09\uff0c\u4f46\u4e00\u5b9a\u8981\u5728\u8868\u4e0e\u8868\u4e4b\u95f4\u7684\u5173\u8054\u952e\u4e0a\u5efa\u7acb\u7d22\u5f15\u2022\u5916\u952e\u53ef\u7528\u4e8e\u4fdd\u8bc1\u6570\u636e\u7684\u53c2\u7167\u5b8c\u6574\u6027\uff0c\u4f46\u5efa\u8bae\u5728\u4e1a\u52a1\u7aef\u5b9e\u73b0\u2022\u5916\u952e\u4f1a\u5f71\u54cd\u7236\u8868\u548c\u5b50\u8868\u7684\u5199\u64cd\u4f5c\u4ece\u800c\u964d\u4f4e\u6027\u80fd<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u6570\u636e\u5e93 SQL \u5f00\u53d1\u89c4\u8303<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. \u5efa\u8bae\u4f7f\u7528\u9884\u7f16\u8bd1\u8bed\u53e5\u8fdb\u884c\u6570\u636e\u5e93\u64cd\u4f5c<\/h3>\n\n\n\n<p>\u9884\u7f16\u8bd1\u8bed\u53e5\u53ef\u4ee5\u91cd\u590d\u4f7f\u7528\u8fd9\u4e9b\u8ba1\u5212\uff0c\u51cf\u5c11 SQL \u7f16\u8bd1\u6240\u9700\u8981\u7684\u65f6\u95f4\uff0c\u8fd8\u53ef\u4ee5\u89e3\u51b3\u52a8\u6001 SQL \u6240\u5e26\u6765\u7684 SQL \u6ce8\u5165\u7684\u95ee\u9898\u3002<\/p>\n\n\n\n<p>\u53ea\u4f20\u53c2\u6570\uff0c\u6bd4\u4f20\u9012 SQL \u8bed\u53e5\u66f4\u9ad8\u6548\u3002<\/p>\n\n\n\n<p>\u76f8\u540c\u8bed\u53e5\u53ef\u4ee5\u4e00\u6b21\u89e3\u6790\uff0c\u591a\u6b21\u4f7f\u7528\uff0c\u63d0\u9ad8\u5904\u7406\u6548\u7387\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. \u907f\u514d\u6570\u636e\u7c7b\u578b\u7684\u9690\u5f0f\u8f6c\u6362<\/h3>\n\n\n\n<p>\u9690\u5f0f\u8f6c\u6362\u4f1a\u5bfc\u81f4\u7d22\u5f15\u5931\u6548\u5982:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>select name,phone from customer where id = '111';<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">3. \u5145\u5206\u5229\u7528\u8868\u4e0a\u5df2\u7ecf\u5b58\u5728\u7684\u7d22\u5f15<\/h3>\n\n\n\n<p>\u907f\u514d\u4f7f\u7528\u53cc%\u53f7\u7684\u67e5\u8be2\u6761\u4ef6\u3002\u5982\uff1a<code>a like '%123%'<\/code>\uff0c\uff08\u5982\u679c\u65e0\u524d\u7f6e%,\u53ea\u6709\u540e\u7f6e%\uff0c\u662f\u53ef\u4ee5\u7528\u5230\u5217\u4e0a\u7684\u7d22\u5f15\u7684\uff09<\/p>\n\n\n\n<p>\u4e00\u4e2a SQL \u53ea\u80fd\u5229\u7528\u5230\u590d\u5408\u7d22\u5f15\u4e2d\u7684\u4e00\u5217\u8fdb\u884c\u8303\u56f4\u67e5\u8be2\u3002\u5982\uff1a\u6709 a,b,c \u5217\u7684\u8054\u5408\u7d22\u5f15\uff0c\u5728\u67e5\u8be2\u6761\u4ef6\u4e2d\u6709 a \u5217\u7684\u8303\u56f4\u67e5\u8be2\uff0c\u5219\u5728 b,c \u5217\u4e0a\u7684\u7d22\u5f15\u5c06\u4e0d\u4f1a\u88ab\u7528\u5230\u3002<\/p>\n\n\n\n<p>\u5728\u5b9a\u4e49\u8054\u5408\u7d22\u5f15\u65f6\uff0c\u5982\u679c a \u5217\u8981\u7528\u5230\u8303\u56f4\u67e5\u627e\u7684\u8bdd\uff0c\u5c31\u8981\u628a a \u5217\u653e\u5230\u8054\u5408\u7d22\u5f15\u7684\u53f3\u4fa7\uff0c\u4f7f\u7528 left join \u6216 not exists \u6765\u4f18\u5316 not in \u64cd\u4f5c\uff0c\u56e0\u4e3a not in \u4e5f\u901a\u5e38\u4f1a\u4f7f\u7528\u7d22\u5f15\u5931\u6548\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4. \u6570\u636e\u5e93\u8bbe\u8ba1\u65f6\uff0c\u5e94\u8be5\u8981\u5bf9\u4ee5\u540e\u6269\u5c55\u8fdb\u884c\u8003\u8651<\/h3>\n\n\n\n<h3 class=\"wp-block-heading\">5. \u7a0b\u5e8f\u8fde\u63a5\u4e0d\u540c\u7684\u6570\u636e\u5e93\u4f7f\u7528\u4e0d\u540c\u7684\u8d26\u53f7\uff0c\u8fdb\u5236\u8de8\u5e93\u67e5\u8be2<\/h3>\n\n\n\n<p>\u2022\u4e3a\u6570\u636e\u5e93\u8fc1\u79fb\u548c\u5206\u5e93\u5206\u8868\u7559\u51fa\u4f59\u5730\u2022\u964d\u4f4e\u4e1a\u52a1\u8026\u5408\u5ea6\u2022\u907f\u514d\u6743\u9650\u8fc7\u5927\u800c\u4ea7\u751f\u7684\u5b89\u5168\u98ce\u9669<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">6. \u7981\u6b62\u4f7f\u7528 SELECT * \u5fc5\u987b\u4f7f\u7528 SELECT &lt;\u5b57\u6bb5\u5217\u8868&gt; \u67e5\u8be2<\/h3>\n\n\n\n<p><strong>\u539f\u56e0\uff1a<\/strong><\/p>\n\n\n\n<p>\u2022\u6d88\u8017\u66f4\u591a\u7684 CPU \u548c IO \u4ee5\u7f51\u7edc\u5e26\u5bbd\u8d44\u6e90\u2022\u65e0\u6cd5\u4f7f\u7528\u8986\u76d6\u7d22\u5f15\u2022\u53ef\u51cf\u5c11\u8868\u7ed3\u6784\u53d8\u66f4\u5e26\u6765\u7684\u5f71\u54cd<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">7. \u7981\u6b62\u4f7f\u7528\u4e0d\u542b\u5b57\u6bb5\u5217\u8868\u7684 INSERT \u8bed\u53e5<\/h3>\n\n\n\n<p>\u5982\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>insert into values ('a','b','c');<\/code><\/pre>\n\n\n\n<p>\u5e94\u4f7f\u7528\uff1a<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>insert into t(c1,c2,c3) values ('a','b','c');<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">8. \u907f\u514d\u4f7f\u7528\u5b50\u67e5\u8be2\uff0c\u53ef\u4ee5\u628a\u5b50\u67e5\u8be2\u4f18\u5316\u4e3a join \u64cd\u4f5c<\/h3>\n\n\n\n<p>\u901a\u5e38\u5b50\u67e5\u8be2\u5728 in \u5b50\u53e5\u4e2d\uff0c\u4e14\u5b50\u67e5\u8be2\u4e2d\u4e3a\u7b80\u5355 SQL(\u4e0d\u5305\u542b union\u3001group by\u3001order by\u3001limit \u4ece\u53e5) \u65f6,\u624d\u53ef\u4ee5\u628a\u5b50\u67e5\u8be2\u8f6c\u5316\u4e3a\u5173\u8054\u67e5\u8be2\u8fdb\u884c\u4f18\u5316\u3002<\/p>\n\n\n\n<p><strong>\u5b50\u67e5\u8be2\u6027\u80fd\u5dee\u7684\u539f\u56e0\uff1a<\/strong><\/p>\n\n\n\n<p>\u5b50\u67e5\u8be2\u7684\u7ed3\u679c\u96c6\u65e0\u6cd5\u4f7f\u7528\u7d22\u5f15\uff0c\u901a\u5e38\u5b50\u67e5\u8be2\u7684\u7ed3\u679c\u96c6\u4f1a\u88ab\u5b58\u50a8\u5230\u4e34\u65f6\u8868\u4e2d\uff0c\u4e0d\u8bba\u662f\u5185\u5b58\u4e34\u65f6\u8868\u8fd8\u662f\u78c1\u76d8\u4e34\u65f6\u8868\u90fd\u4e0d\u4f1a\u5b58\u5728\u7d22\u5f15\uff0c\u6240\u4ee5\u67e5\u8be2\u6027\u80fd\u4f1a\u53d7\u5230\u4e00\u5b9a\u7684\u5f71\u54cd\u3002\u7279\u522b\u662f\u5bf9\u4e8e\u8fd4\u56de\u7ed3\u679c\u96c6\u6bd4\u8f83\u5927\u7684\u5b50\u67e5\u8be2\uff0c\u5176\u5bf9\u67e5\u8be2\u6027\u80fd\u7684\u5f71\u54cd\u4e5f\u5c31\u8d8a\u5927\u3002<\/p>\n\n\n\n<p>\u7531\u4e8e\u5b50\u67e5\u8be2\u4f1a\u4ea7\u751f\u5927\u91cf\u7684\u4e34\u65f6\u8868\u4e5f\u6ca1\u6709\u7d22\u5f15\uff0c\u6240\u4ee5\u4f1a\u6d88\u8017\u8fc7\u591a\u7684 CPU \u548c IO \u8d44\u6e90\uff0c\u4ea7\u751f\u5927\u91cf\u7684\u6162\u67e5\u8be2\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">9. \u907f\u514d\u4f7f\u7528 JOIN \u5173\u8054\u592a\u591a\u7684\u8868<\/h3>\n\n\n\n<p>\u5bf9\u4e8e MySQL \u6765\u8bf4\uff0c\u662f\u5b58\u5728\u5173\u8054\u7f13\u5b58\u7684\uff0c\u7f13\u5b58\u7684\u5927\u5c0f\u53ef\u4ee5\u7531 join_buffer_size \u53c2\u6570\u8fdb\u884c\u8bbe\u7f6e\u3002<\/p>\n\n\n\n<p>\u5728 MySQL \u4e2d\uff0c\u5bf9\u4e8e\u540c\u4e00\u4e2a SQL \u591a\u5173\u8054\uff08join\uff09\u4e00\u4e2a\u8868\uff0c\u5c31\u4f1a\u591a\u5206\u914d\u4e00\u4e2a\u5173\u8054\u7f13\u5b58\uff0c\u5982\u679c\u5728\u4e00\u4e2a SQL \u4e2d\u5173\u8054\u7684\u8868\u8d8a\u591a\uff0c\u6240\u5360\u7528\u7684\u5185\u5b58\u4e5f\u5c31\u8d8a\u5927\u3002<\/p>\n\n\n\n<p>\u5982\u679c\u7a0b\u5e8f\u4e2d\u5927\u91cf\u7684\u4f7f\u7528\u4e86\u591a\u8868\u5173\u8054\u7684\u64cd\u4f5c\uff0c\u540c\u65f6 join_buffer_size \u8bbe\u7f6e\u7684\u4e5f\u4e0d\u5408\u7406\u7684\u60c5\u51b5\u4e0b\uff0c\u5c31\u5bb9\u6613\u9020\u6210\u670d\u52a1\u5668\u5185\u5b58\u6ea2\u51fa\u7684\u60c5\u51b5\uff0c\u5c31\u4f1a\u5f71\u54cd\u5230\u670d\u52a1\u5668\u6570\u636e\u5e93\u6027\u80fd\u7684\u7a33\u5b9a\u6027\u3002<\/p>\n\n\n\n<p>\u540c\u65f6\u5bf9\u4e8e\u5173\u8054\u64cd\u4f5c\u6765\u8bf4\uff0c\u4f1a\u4ea7\u751f\u4e34\u65f6\u8868\u64cd\u4f5c\uff0c\u5f71\u54cd\u67e5\u8be2\u6548\u7387\uff0cMySQL \u6700\u591a\u5141\u8bb8\u5173\u8054 61 \u4e2a\u8868\uff0c\u5efa\u8bae\u4e0d\u8d85\u8fc7 5 \u4e2a\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">10. \u51cf\u5c11\u540c\u6570\u636e\u5e93\u7684\u4ea4\u4e92\u6b21\u6570<\/h3>\n\n\n\n<p>\u6570\u636e\u5e93\u66f4\u9002\u5408\u5904\u7406\u6279\u91cf\u64cd\u4f5c\uff0c\u5408\u5e76\u591a\u4e2a\u76f8\u540c\u7684\u64cd\u4f5c\u5230\u4e00\u8d77\uff0c\u53ef\u4ee5\u63d0\u9ad8\u5904\u7406\u6548\u7387\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">11. \u5bf9\u5e94\u540c\u4e00\u5217\u8fdb\u884c or \u5224\u65ad\u65f6\uff0c\u4f7f\u7528 in \u4ee3\u66ff or<\/h3>\n\n\n\n<p>in \u7684\u503c\u4e0d\u8981\u8d85\u8fc7 500 \u4e2a\uff0cin \u64cd\u4f5c\u53ef\u4ee5\u66f4\u6709\u6548\u7684\u5229\u7528\u7d22\u5f15\uff0cor \u5927\u591a\u6570\u60c5\u51b5\u4e0b\u5f88\u5c11\u80fd\u5229\u7528\u5230\u7d22\u5f15\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">12. \u7981\u6b62\u4f7f\u7528 order by rand() \u8fdb\u884c\u968f\u673a\u6392\u5e8f<\/h3>\n\n\n\n<p>order by rand() \u4f1a\u628a\u8868\u4e2d\u6240\u6709\u7b26\u5408\u6761\u4ef6\u7684\u6570\u636e\u88c5\u8f7d\u5230\u5185\u5b58\u4e2d\uff0c\u7136\u540e\u5728\u5185\u5b58\u4e2d\u5bf9\u6240\u6709\u6570\u636e\u6839\u636e\u968f\u673a\u751f\u6210\u7684\u503c\u8fdb\u884c\u6392\u5e8f\uff0c\u5e76\u4e14\u53ef\u80fd\u4f1a\u5bf9\u6bcf\u4e00\u884c\u90fd\u751f\u6210\u4e00\u4e2a\u968f\u673a\u503c\uff0c\u5982\u679c\u6ee1\u8db3\u6761\u4ef6\u7684\u6570\u636e\u96c6\u975e\u5e38\u5927\uff0c\u5c31\u4f1a\u6d88\u8017\u5927\u91cf\u7684 CPU \u548c IO \u53ca\u5185\u5b58\u8d44\u6e90\u3002<\/p>\n\n\n\n<p>\u63a8\u8350\u5728\u7a0b\u5e8f\u4e2d\u83b7\u53d6\u4e00\u4e2a\u968f\u673a\u503c\uff0c\u7136\u540e\u4ece\u6570\u636e\u5e93\u4e2d\u83b7\u53d6\u6570\u636e\u7684\u65b9\u5f0f\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">13. WHERE \u4ece\u53e5\u4e2d\u7981\u6b62\u5bf9\u5217\u8fdb\u884c\u51fd\u6570\u8f6c\u6362\u548c\u8ba1\u7b97<\/h3>\n\n\n\n<p>\u5bf9\u5217\u8fdb\u884c\u51fd\u6570\u8f6c\u6362\u6216\u8ba1\u7b97\u65f6\u4f1a\u5bfc\u81f4\u65e0\u6cd5\u4f7f\u7528\u7d22\u5f15<\/p>\n\n\n\n<p><strong>\u4e0d\u63a8\u8350\uff1a<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>where date(create_time)='20190101'<\/code><\/pre>\n\n\n\n<p><strong>\u63a8\u8350\uff1a<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\"><li><\/li><\/ul>\n\n\n\n<pre class=\"wp-block-code\"><code>where create_time &gt;= '20190101' and create_time &lt; '20190102'<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">14. \u5728\u660e\u663e\u4e0d\u4f1a\u6709\u91cd\u590d\u503c\u65f6\u4f7f\u7528 UNION ALL \u800c\u4e0d\u662f UNION<\/h3>\n\n\n\n<p>\u2022UNION \u4f1a\u628a\u4e24\u4e2a\u7ed3\u679c\u96c6\u7684\u6240\u6709\u6570\u636e\u653e\u5230\u4e34\u65f6\u8868\u4e2d\u540e\u518d\u8fdb\u884c\u53bb\u91cd\u64cd\u4f5c\u2022UNION ALL \u4e0d\u4f1a\u518d\u5bf9\u7ed3\u679c\u96c6\u8fdb\u884c\u53bb\u91cd\u64cd\u4f5c<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">15. \u62c6\u5206\u590d\u6742\u7684\u5927 SQL \u4e3a\u591a\u4e2a\u5c0f SQL<\/h3>\n\n\n\n<p>\u2022\u5927 SQL \u903b\u8f91\u4e0a\u6bd4\u8f83\u590d\u6742\uff0c\u9700\u8981\u5360\u7528\u5927\u91cf CPU \u8fdb\u884c\u8ba1\u7b97\u7684 SQL\u2022MySQL \u4e2d\uff0c\u4e00\u4e2a SQL \u53ea\u80fd\u4f7f\u7528\u4e00\u4e2a CPU \u8fdb\u884c\u8ba1\u7b97\u2022SQL \u62c6\u5206\u540e\u53ef\u4ee5\u901a\u8fc7\u5e76\u884c\u6267\u884c\u6765\u63d0\u9ad8\u5904\u7406\u6548\u7387<\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<h2 class=\"wp-block-heading\">\u6570\u636e\u5e93\u64cd\u4f5c\u884c\u4e3a\u89c4\u8303<\/h2>\n\n\n\n<h3 class=\"wp-block-heading\">1. \u8d85 100 \u4e07\u884c\u7684\u6279\u91cf\u5199 (UPDATE,DELETE,INSERT) \u64cd\u4f5c,\u8981\u5206\u6279\u591a\u6b21\u8fdb\u884c\u64cd\u4f5c<\/h3>\n\n\n\n<p><strong>\u5927\u6279\u91cf\u64cd\u4f5c\u53ef\u80fd\u4f1a\u9020\u6210\u4e25\u91cd\u7684\u4e3b\u4ece\u5ef6\u8fdf<\/strong><\/p>\n\n\n\n<p>\u4e3b\u4ece\u73af\u5883\u4e2d,\u5927\u6279\u91cf\u64cd\u4f5c\u53ef\u80fd\u4f1a\u9020\u6210\u4e25\u91cd\u7684\u4e3b\u4ece\u5ef6\u8fdf\uff0c\u5927\u6279\u91cf\u7684\u5199\u64cd\u4f5c\u4e00\u822c\u90fd\u9700\u8981\u6267\u884c\u4e00\u5b9a\u957f\u7684\u65f6\u95f4\uff0c \u800c\u53ea\u6709\u5f53\u4e3b\u5e93\u4e0a\u6267\u884c\u5b8c\u6210\u540e\uff0c\u624d\u4f1a\u5728\u5176\u4ed6\u4ece\u5e93\u4e0a\u6267\u884c\uff0c\u6240\u4ee5\u4f1a\u9020\u6210\u4e3b\u5e93\u4e0e\u4ece\u5e93\u957f\u65f6\u95f4\u7684\u5ef6\u8fdf\u60c5\u51b5<\/p>\n\n\n\n<p><strong>binlog \u65e5\u5fd7\u4e3a row \u683c\u5f0f\u65f6\u4f1a\u4ea7\u751f\u5927\u91cf\u7684\u65e5\u5fd7<\/strong><\/p>\n\n\n\n<p>\u5927\u6279\u91cf\u5199\u64cd\u4f5c\u4f1a\u4ea7\u751f\u5927\u91cf\u65e5\u5fd7\uff0c\u7279\u522b\u662f\u5bf9\u4e8e row \u683c\u5f0f\u4e8c\u8fdb\u5236\u6570\u636e\u800c\u8a00\uff0c\u7531\u4e8e\u5728 row \u683c\u5f0f\u4e2d\u4f1a\u8bb0\u5f55\u6bcf\u4e00\u884c\u6570\u636e\u7684\u4fee\u6539\uff0c\u6211\u4eec\u4e00\u6b21\u4fee\u6539\u7684\u6570\u636e\u8d8a\u591a\uff0c\u4ea7\u751f\u7684\u65e5\u5fd7\u91cf\u4e5f\u5c31\u4f1a\u8d8a\u591a\uff0c\u65e5\u5fd7\u7684\u4f20\u8f93\u548c\u6062\u590d\u6240\u9700\u8981\u7684\u65f6\u95f4\u4e5f\u5c31\u8d8a\u957f\uff0c\u8fd9\u4e5f\u662f\u9020\u6210\u4e3b\u4ece\u5ef6\u8fdf\u7684\u4e00\u4e2a\u539f\u56e0<\/p>\n\n\n\n<p><strong>\u907f\u514d\u4ea7\u751f\u5927\u4e8b\u52a1\u64cd\u4f5c<\/strong><\/p>\n\n\n\n<p>\u5927\u6279\u91cf\u4fee\u6539\u6570\u636e\uff0c\u4e00\u5b9a\u662f\u5728\u4e00\u4e2a\u4e8b\u52a1\u4e2d\u8fdb\u884c\u7684\uff0c\u8fd9\u5c31\u4f1a\u9020\u6210\u8868\u4e2d\u5927\u6279\u91cf\u6570\u636e\u8fdb\u884c\u9501\u5b9a\uff0c\u4ece\u800c\u5bfc\u81f4\u5927\u91cf\u7684\u963b\u585e\uff0c\u963b\u585e\u4f1a\u5bf9 MySQL \u7684\u6027\u80fd\u4ea7\u751f\u975e\u5e38\u5927\u7684\u5f71\u54cd\u3002<\/p>\n\n\n\n<p>\u7279\u522b\u662f\u957f\u65f6\u95f4\u7684\u963b\u585e\u4f1a\u5360\u6ee1\u6240\u6709\u6570\u636e\u5e93\u7684\u53ef\u7528\u8fde\u63a5\uff0c\u8fd9\u4f1a\u4f7f\u751f\u4ea7\u73af\u5883\u4e2d\u7684\u5176\u4ed6\u5e94\u7528\u65e0\u6cd5\u8fde\u63a5\u5230\u6570\u636e\u5e93\uff0c\u56e0\u6b64\u4e00\u5b9a\u8981\u6ce8\u610f\u5927\u6279\u91cf\u5199\u64cd\u4f5c\u8981\u8fdb\u884c\u5206\u6279<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">2. \u5bf9\u4e8e\u5927\u8868\u4f7f\u7528 pt-online-schema-change \u4fee\u6539\u8868\u7ed3\u6784<\/h3>\n\n\n\n<p>\u2022\u907f\u514d\u5927\u8868\u4fee\u6539\u4ea7\u751f\u7684\u4e3b\u4ece\u5ef6\u8fdf\u2022\u907f\u514d\u5728\u5bf9\u8868\u5b57\u6bb5\u8fdb\u884c\u4fee\u6539\u65f6\u8fdb\u884c\u9501\u8868<\/p>\n\n\n\n<p>\u5bf9\u5927\u8868\u6570\u636e\u7ed3\u6784\u7684\u4fee\u6539\u4e00\u5b9a\u8981\u8c28\u614e\uff0c\u4f1a\u9020\u6210\u4e25\u91cd\u7684\u9501\u8868\u64cd\u4f5c\uff0c\u5c24\u5176\u662f\u751f\u4ea7\u73af\u5883\uff0c\u662f\u4e0d\u80fd\u5bb9\u5fcd\u7684\u3002<\/p>\n\n\n\n<p>pt-online-schema-change \u5b83\u4f1a\u9996\u5148\u5efa\u7acb\u4e00\u4e2a\u4e0e\u539f\u8868\u7ed3\u6784\u76f8\u540c\u7684\u65b0\u8868\uff0c\u5e76\u4e14\u5728\u65b0\u8868\u4e0a\u8fdb\u884c\u8868\u7ed3\u6784\u7684\u4fee\u6539\uff0c\u7136\u540e\u518d\u628a\u539f\u8868\u4e2d\u7684\u6570\u636e\u590d\u5236\u5230\u65b0\u8868\u4e2d\uff0c\u5e76\u5728\u539f\u8868\u4e2d\u589e\u52a0\u4e00\u4e9b\u89e6\u53d1\u5668\u3002\u628a\u539f\u8868\u4e2d\u65b0\u589e\u7684\u6570\u636e\u4e5f\u590d\u5236\u5230\u65b0\u8868\u4e2d\uff0c\u5728\u884c\u6240\u6709\u6570\u636e\u590d\u5236\u5b8c\u6210\u4e4b\u540e\uff0c\u628a\u65b0\u8868\u547d\u540d\u6210\u539f\u8868\uff0c\u5e76\u628a\u539f\u6765\u7684\u8868\u5220\u9664\u6389\u3002\u628a\u539f\u6765\u4e00\u4e2a DDL \u64cd\u4f5c\uff0c\u5206\u89e3\u6210\u591a\u4e2a\u5c0f\u7684\u6279\u6b21\u8fdb\u884c\u3002<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">3. \u7981\u6b62\u4e3a\u7a0b\u5e8f\u4f7f\u7528\u7684\u8d26\u53f7\u8d4b\u4e88 super \u6743\u9650<\/h3>\n\n\n\n<p>\u2022\u5f53\u8fbe\u5230\u6700\u5927\u8fde\u63a5\u6570\u9650\u5236\u65f6\uff0c\u8fd8\u8fd0\u884c 1 \u4e2a\u6709 super \u6743\u9650\u7684\u7528\u6237\u8fde\u63a5\u2022super \u6743\u9650\u53ea\u80fd\u7559\u7ed9 DBA \u5904\u7406\u95ee\u9898\u7684\u8d26\u53f7\u4f7f\u7528<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">4. \u5bf9\u4e8e\u7a0b\u5e8f\u8fde\u63a5\u6570\u636e\u5e93\u8d26\u53f7,\u9075\u5faa\u6743\u9650\u6700\u5c0f\u539f\u5219<\/h3>\n\n\n\n<p>\u2022\u7a0b\u5e8f\u4f7f\u7528\u6570\u636e\u5e93\u8d26\u53f7\u53ea\u80fd\u5728\u4e00\u4e2a DB \u4e0b\u4f7f\u7528\uff0c\u4e0d\u51c6\u8de8\u5e93\u2022\u7a0b\u5e8f\u4f7f\u7528\u7684\u8d26\u53f7\u539f\u5219\u4e0a\u4e0d\u51c6\u6709 drop \u6743\u9650<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6570\u636e\u5e93\u547d\u4ee4\u89c4\u8303 \u2022\u6240\u6709\u6570\u636e\u5e93\u5bf9\u8c61&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":1038,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-1285","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-4"],"_links":{"self":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/posts\/1285","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/comments?post=1285"}],"version-history":[{"count":0,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/posts\/1285\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/media\/1038"}],"wp:attachment":[{"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/media?parent=1285"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/categories?post=1285"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sanlangcode.com\/index.php\/wp-json\/wp\/v2\/tags?post=1285"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}