{"id":1070,"date":"2021-09-01T21:40:00","date_gmt":"2021-09-01T13:40:00","guid":{"rendered":"http:\/\/www.tra56.com\/?p=1070"},"modified":"2021-09-01T21:40:00","modified_gmt":"2021-09-01T13:40:00","slug":"1070","status":"publish","type":"post","link":"https:\/\/www.tra56.com\/1070.html","title":{"rendered":"mysql \u5e38\u89c1\u9762\u8bd5\u9898"},"content":{"rendered":"

\u4e00\u3001\u4e3a\u4ec0\u4e48\u7528\u81ea\u589e\u5217\u4f5c\u4e3a\u4e3b\u952e<\/strong><\/p>\n

1\u3001\u5982\u679c\u6211\u4eec\u5b9a\u4e49\u4e86\u4e3b\u952e(PRIMARY KEY)\uff0c\u90a3\u4e48InnoDB\u4f1a\u9009\u62e9\u4e3b\u952e\u4f5c\u4e3a\u805a\u96c6\u7d22\u5f15\u3002<\/p>\n

\u5982\u679c\u6ca1\u6709\u663e\u5f0f\u5b9a\u4e49\u4e3b\u952e\uff0c\u5219InnoDB\u4f1a\u9009\u62e9\u7b2c\u4e00\u4e2a\u4e0d\u5305\u542b\u6709NULL\u503c\u7684\u552f\u4e00\u7d22\u5f15\u4f5c\u4e3a\u4e3b\u952e\u7d22\u5f15\u3002<\/p>\n

\u5982\u679c\u4e5f\u6ca1\u6709\u8fd9\u6837\u7684\u552f\u4e00\u7d22\u5f15\uff0c\u5219InnoDB\u4f1a\u9009\u62e9\u5185\u7f6e6\u5b57\u8282\u957f\u7684ROWID\u4f5c\u4e3a\u9690\u542b\u7684\u805a\u96c6\u7d22\u5f15(ROWID\u968f\u7740\u884c\u8bb0\u5f55\u7684\u5199\u5165\u800c\u4e3b\u952e\u9012\u589e\uff0c\u8fd9\u4e2aROWID\u4e0d\u50cfORACLE\u7684ROWID\u90a3\u6837\u53ef\u5f15\u7528\uff0c\u662f\u9690\u542b\u7684)\u3002<\/p>\n

2\u3001\u6570\u636e\u8bb0\u5f55\u672c\u8eab\u88ab\u5b58\u4e8e\u4e3b\u7d22\u5f15\uff08\u4e00\u9897B+Tree\uff09\u7684\u53f6\u5b50\u8282\u70b9\u4e0a\uff0c\u8fd9\u5c31\u8981\u6c42\u540c\u4e00\u4e2a\u53f6\u5b50\u8282\u70b9\u5185\uff08\u5927\u5c0f\u4e3a\u4e00\u4e2a\u5185\u5b58\u9875\u6216\u78c1\u76d8\u9875\uff09\u7684\u5404\u6761\u6570\u636e\u8bb0\u5f55\u6309\u4e3b\u952e\u987a\u5e8f\u5b58\u653e<\/p>\n

\u56e0\u6b64\u6bcf\u5f53\u6709\u4e00\u6761\u65b0\u7684\u8bb0\u5f55\u63d2\u5165\u65f6\uff0cMySQL\u4f1a\u6839\u636e\u5176\u4e3b\u952e\u5c06\u5176\u63d2\u5165\u9002\u5f53\u7684\u8282\u70b9\u548c\u4f4d\u7f6e\uff0c\u5982\u679c\u9875\u9762\u8fbe\u5230\u88c5\u8f7d\u56e0\u5b50\uff08InnoDB\u9ed8\u8ba4\u4e3a15\/16\uff09\uff0c\u5219\u5f00\u8f9f\u4e00\u4e2a\u65b0\u7684\u9875\uff08\u8282\u70b9\uff09<\/p>\n

3\u3001\u5982\u679c\u8868\u4f7f\u7528\u81ea\u589e\u4e3b\u952e\uff0c\u90a3\u4e48\u6bcf\u6b21\u63d2\u5165\u65b0\u7684\u8bb0\u5f55\uff0c\u8bb0\u5f55\u5c31\u4f1a\u987a\u5e8f\u6dfb\u52a0\u5230\u5f53\u524d\u7d22\u5f15\u8282\u70b9\u7684\u540e\u7eed\u4f4d\u7f6e\uff0c\u5f53\u4e00\u9875\u5199\u6ee1\uff0c\u5c31\u4f1a\u81ea\u52a8\u5f00\u8f9f\u4e00\u4e2a\u65b0\u7684\u9875<\/p>\n

4\u3001\u5982\u679c\u4f7f\u7528\u975e\u81ea\u589e\u4e3b\u952e\uff08\u5982\u679c\u8eab\u4efd\u8bc1\u53f7\u6216\u5b66\u53f7\u7b49\uff09\uff0c\u7531\u4e8e\u6bcf\u6b21\u63d2\u5165\u4e3b\u952e\u7684\u503c\u8fd1\u4f3c\u4e8e\u968f\u673a\uff0c\u56e0\u6b64\u6bcf\u6b21\u65b0\u7eaa\u5f55\u90fd\u8981\u88ab\u63d2\u5230\u73b0\u6709\u7d22\u5f15\u9875\u5f97\u4e2d\u95f4\u67d0\u4e2a\u4f4d\u7f6e<\/p>\n

\u6b64\u65f6MySQL\u4e0d\u5f97\u4e0d\u4e3a\u4e86\u5c06\u65b0\u8bb0\u5f55\u63d2\u5230\u5408\u9002\u4f4d\u7f6e\u800c\u79fb\u52a8\u6570\u636e\uff0c\u751a\u81f3\u76ee\u6807\u9875\u9762\u53ef\u80fd\u5df2\u7ecf\u88ab\u56de\u5199\u5230\u78c1\u76d8\u4e0a\u800c\u4ece\u7f13\u5b58\u4e2d\u6e05\u6389\uff0c\u6b64\u65f6\u53c8\u8981\u4ece\u78c1\u76d8\u4e0a\u8bfb\u56de\u6765\uff0c\u8fd9\u589e\u52a0\u4e86\u5f88\u591a\u5f00\u9500<\/p>\n

\u540c\u65f6\u9891\u7e41\u7684\u79fb\u52a8\u3001\u5206\u9875\u64cd\u4f5c\u9020\u6210\u4e86\u5927\u91cf\u7684\u788e\u7247\uff0c\u5f97\u5230\u4e86\u4e0d\u591f\u7d27\u51d1\u7684\u7d22\u5f15\u7ed3\u6784\uff0c\u540e\u7eed\u4e0d\u5f97\u4e0d\u901a\u8fc7OPTIMIZE TABLE\u6765\u91cd\u5efa\u8868\u5e76\u4f18\u5316\u586b\u5145\u9875\u9762\u3002<\/p>\n

\u4e8c\u3001\u4e3a\u4ec0\u4e48\u4f7f\u7528\u6570\u636e\u7d22\u5f15\u80fd\u63d0\u9ad8\u6548\u7387<\/strong><\/p>\n

    \n
  1. \n

    \u6570\u636e\u7d22\u5f15\u7684\u5b58\u50a8\u662f\u6709\u5e8f\u7684<\/p>\n<\/li>\n

  2. \n

    \u5728\u6709\u5e8f\u7684\u60c5\u51b5\u4e0b\uff0c\u901a\u8fc7\u7d22\u5f15\u67e5\u8be2\u4e00\u4e2a\u6570\u636e\u662f\u65e0\u9700\u904d\u5386\u7d22\u5f15\u8bb0\u5f55\u7684<\/p>\n<\/li>\n

  3. \n

    \u6781\u7aef\u60c5\u51b5\u4e0b\uff0c\u6570\u636e\u7d22\u5f15\u7684\u67e5\u8be2\u6548\u7387\u4e3a\u4e8c\u5206\u6cd5\u67e5\u8be2\u6548\u7387\uff0c\u8d8b\u8fd1\u4e8e log2(N)<\/p>\n<\/li>\n<\/ol>\n

    \u4e09\u3001B+\u6811\u7d22\u5f15\u548c\u54c8\u5e0c\u7d22\u5f15\u7684\u533a\u522b<\/strong><\/p>\n

    B+\u6811\u662f\u4e00\u4e2a\u5e73\u8861\u7684\u591a\u53c9\u6811\uff0c\u4ece\u6839\u8282\u70b9\u5230\u6bcf\u4e2a\u53f6\u5b50\u8282\u70b9\u7684\u9ad8\u5ea6\u5dee\u503c\u4e0d\u8d85\u8fc71\uff0c\u800c\u4e14\u540c\u5c42\u7ea7\u7684\u8282\u70b9\u95f4\u6709\u6307\u9488\u76f8\u4e92\u94fe\u63a5\uff0c\u662f\u6709\u5e8f\u7684\uff0c\u5982\u4e0b\u56fe\uff1a<\/p>\n

    \"\"<\/p>\n

    \u54c8\u5e0c\u7d22\u5f15\u5c31\u662f\u91c7\u7528\u4e00\u5b9a\u7684\u54c8\u5e0c\u7b97\u6cd5\uff0c\u628a\u952e\u503c\u6362\u7b97\u6210\u65b0\u7684\u54c8\u5e0c\u503c\uff0c\u68c0\u7d22\u65f6\u4e0d\u9700\u8981\u7c7b\u4f3cB+\u6811\u90a3\u6837\u4ece\u6839\u8282\u70b9\u5230\u53f6\u5b50\u8282\u70b9\u9010\u7ea7\u67e5\u627e\uff0c\u53ea\u9700\u4e00\u6b21\u54c8\u5e0c\u7b97\u6cd5\u5373\u53ef,\u662f\u65e0\u5e8f\u7684\uff0c\u5982\u4e0b\u56fe\u6240\u793a\uff1a<\/p>\n

    \"\"<\/p>\n

    \u56db\u3001\u54c8\u5e0c\u7d22\u5f15\u7684\u4f18\u52bf\uff1a<\/strong><\/p>\n

    \u7b49\u503c\u67e5\u8be2\uff0c<\/strong>\u54c8\u5e0c\u7d22\u5f15\u5177\u6709\u7edd\u5bf9\u4f18\u52bf\uff08\u524d\u63d0\u662f\uff1a\u6ca1\u6709\u5927\u91cf\u91cd\u590d\u952e\u503c\uff0c\u5982\u679c\u5927\u91cf\u91cd\u590d\u952e\u503c\u65f6\uff0c\u54c8\u5e0c\u7d22\u5f15\u7684\u6548\u7387\u5f88\u4f4e\uff0c\u56e0\u4e3a\u5b58\u5728\u6240\u8c13\u7684\u54c8\u5e0c\u78b0\u649e\u95ee\u9898\u3002\uff09<\/p>\n

    \u4e94\u3001\u54c8\u5e0c\u7d22\u5f15\u4e0d\u9002\u7528\u7684\u573a\u666f\uff1a<\/strong><\/p>\n

      \n
    1. \n

      \u4e0d\u652f\u6301\u8303\u56f4\u67e5\u8be2<\/p>\n<\/li>\n

    2. \n

      \u4e0d\u652f\u6301\u7d22\u5f15\u5b8c\u6210\u6392\u5e8f<\/p>\n<\/li>\n

    3. \n

      \u4e0d\u652f\u6301\u8054\u5408\u7d22\u5f15\u7684\u6700\u5de6\u524d\u7f00\u5339\u914d\u89c4\u5219<\/p>\n<\/li>\n<\/ol>\n

      \u901a\u5e38\uff0cB+\u6811\u7d22\u5f15\u7ed3\u6784\u9002\u7528\u4e8e\u7edd\u5927\u591a\u6570\u573a\u666f\uff0c\u50cf\u4e0b\u9762\u8fd9\u79cd\u573a\u666f\u7528\u54c8\u5e0c\u7d22\u5f15\u624d\u66f4\u6709\u4f18\u52bf\uff1a<\/p>\n

      \u5728HEAP\u8868\u4e2d\uff0c\u5982\u679c\u5b58\u50a8\u7684\u6570\u636e\u91cd\u590d\u5ea6\u5f88\u4f4e\uff08\u4e5f\u5c31\u662f\u8bf4\u57fa\u6570\u5f88\u5927\uff09\uff0c\u5bf9\u8be5\u5217\u6570\u636e\u4ee5\u7b49\u503c\u67e5\u8be2\u4e3a\u4e3b\uff0c\u6ca1\u6709\u8303\u56f4\u67e5\u8be2\u3001\u6ca1\u6709\u6392\u5e8f\u7684\u65f6\u5019\uff0c\u7279\u522b\u9002\u5408\u91c7\u7528\u54c8\u5e0c\u7d22\u5f15\uff0c\u4f8b\u5982\u8fd9\u79cdSQL\uff1a<\/p>\n

      # \u4ec5\u7b49\u503c\u67e5\u8be2<\/p>\n

      select id, name from table where name='\u674e\u660e'; <\/p>\n

      \u800c\u5e38\u7528\u7684 InnoDB \u5f15\u64ce\u4e2d\u9ed8\u8ba4\u4f7f\u7528\u7684\u662fB+\u6811\u7d22\u5f15\uff0c\u5b83\u4f1a\u5b9e\u65f6\u76d1\u63a7\u8868\u4e0a\u7d22\u5f15\u7684\u4f7f\u7528\u60c5\u51b5\u3002<\/p>\n

      \u5982\u679c\u8ba4\u4e3a\u5efa\u7acb\u54c8\u5e0c\u7d22\u5f15\u53ef\u4ee5\u63d0\u9ad8\u67e5\u8be2\u6548\u7387\uff0c\u5219\u81ea\u52a8\u5728\u5185\u5b58\u4e2d\u7684\u201c\u81ea\u9002\u5e94\u54c8\u5e0c\u7d22\u5f15\u7f13\u51b2\u533a\u201d\u5efa\u7acb\u54c8\u5e0c\u7d22\u5f15\uff08\u5728InnoDB\u4e2d\u9ed8\u8ba4\u5f00\u542f\u81ea\u9002\u5e94\u54c8\u5e0c\u7d22\u5f15\uff09\u3002<\/p>\n

      \u901a\u8fc7\u89c2\u5bdf\u641c\u7d22\u6a21\u5f0f\uff0cMySQL\u4f1a\u5229\u7528index key\u7684\u524d\u7f00\u5efa\u7acb\u54c8\u5e0c\u7d22\u5f15\uff0c\u5982\u679c\u4e00\u4e2a\u8868\u51e0\u4e4e\u5927\u90e8\u5206\u90fd\u5728\u7f13\u51b2\u6c60\u4e2d\uff0c\u90a3\u4e48\u5efa\u7acb\u4e00\u4e2a\u54c8\u5e0c\u7d22\u5f15\u80fd\u591f\u52a0\u5feb\u7b49\u503c\u67e5\u8be2\u3002<\/p>\n

      \u6ce8\u610f<\/strong>\uff1a\u5728\u67d0\u4e9b\u5de5\u4f5c\u8d1f\u8f7d\u4e0b\uff0c\u901a\u8fc7\u54c8\u5e0c\u7d22\u5f15\u67e5\u627e\u5e26\u6765\u7684\u6027\u80fd\u63d0\u5347\u8fdc\u5927\u4e8e\u989d\u5916\u7684\u76d1\u63a7\u7d22\u5f15\u641c\u7d22\u60c5\u51b5\u548c\u4fdd\u6301\u8fd9\u4e2a\u54c8\u5e0c\u8868\u7ed3\u6784\u6240\u5e26\u6765\u7684\u5f00\u9500\u3002<\/p>\n

      \u4f46\u67d0\u4e9b\u65f6\u5019\uff0c\u5728\u8d1f\u8f7d\u9ad8\u7684\u60c5\u51b5\u4e0b\uff0c\u81ea\u9002\u5e94\u54c8\u5e0c\u7d22\u5f15\u4e2d\u6dfb\u52a0\u7684read\/write\u9501\u4e5f\u4f1a\u5e26\u6765\u7ade\u4e89\uff0c\u6bd4\u5982\u9ad8\u5e76\u53d1\u7684join\u64cd\u4f5c\u3002like\u64cd\u4f5c\u548c%\u7684\u901a\u914d\u7b26\u64cd\u4f5c\u4e5f\u4e0d\u9002\u7528\u4e8e\u81ea\u9002\u5e94\u54c8\u5e0c\u7d22\u5f15\uff0c\u53ef\u80fd\u8981\u5173\u95ed\u81ea\u9002\u5e94\u54c8\u5e0c\u7d22\u5f15\u3002<\/p>\n

      \u516d\u3001B\u6811\u548cB+\u6811\u7684\u533a\u522b<\/strong><\/p>\n

      1\u3001B\u6811\uff0c\u6bcf\u4e2a\u8282\u70b9\u90fd\u5b58\u50a8key\u548cdata\uff0c\u6240\u6709\u8282\u70b9\u7ec4\u6210\u8fd9\u68f5\u6811\uff0c\u5e76\u4e14\u53f6\u5b50\u8282\u70b9\u6307\u9488\u4e3anul\uff0c\u53f6\u5b50\u7ed3\u70b9\u4e0d\u5305\u542b\u4efb\u4f55\u5173\u952e\u5b57\u4fe1\u606f\u3002<\/p>\n

      \"\"<\/p>\n

      2\u3001B+\u6811\uff0c\u6240\u6709\u7684\u53f6\u5b50\u7ed3\u70b9\u4e2d\u5305\u542b\u4e86\u5168\u90e8\u5173\u952e\u5b57\u7684\u4fe1\u606f\uff0c\u53ca\u6307\u5411\u542b\u6709\u8fd9\u4e9b\u5173\u952e\u5b57\u8bb0\u5f55\u7684\u6307\u9488\uff0c\u4e14\u53f6\u5b50\u7ed3\u70b9\u672c\u8eab\u4f9d\u5173\u952e\u5b57\u7684\u5927\u5c0f\u81ea\u5c0f\u800c\u5927\u7684\u987a\u5e8f\u94fe\u63a5<\/p>\n

      \u6240\u6709\u7684\u975e\u7ec8\u7aef\u7ed3\u70b9\u53ef\u4ee5\u770b\u6210\u662f\u7d22\u5f15\u90e8\u5206\uff0c\u7ed3\u70b9\u4e2d\u4ec5\u542b\u6709\u5176\u5b50\u6811\u6839\u7ed3\u70b9\u4e2d\u6700\u5927\uff08\u6216\u6700\u5c0f\uff09\u5173\u952e\u5b57\u3002 (\u800cB \u6811\u7684\u975e\u7ec8\u8282\u70b9\u4e5f\u5305\u542b\u9700\u8981\u67e5\u627e\u7684\u6709\u6548\u4fe1\u606f)<\/p>\n

      \"\"<\/p>\n

      \u4e03\u3001\u4e3a\u4ec0\u4e48\u8bf4B+\u6bd4B\u6811\u66f4\u9002\u5408\u5b9e\u9645\u5e94\u7528\u4e2d\u64cd\u4f5c\u7cfb\u7edf\u7684\u6587\u4ef6\u7d22\u5f15\u548c\u6570\u636e\u5e93\u7d22\u5f15\uff1f<\/strong><\/p>\n

      1\u3001B+\u7684\u78c1\u76d8\u8bfb\u5199\u4ee3\u4ef7\u66f4\u4f4e\u3002<\/p>\n

      B+\u7684\u5185\u90e8\u7ed3\u70b9\u5e76\u6ca1\u6709\u6307\u5411\u5173\u952e\u5b57\u5177\u4f53\u4fe1\u606f\u7684\u6307\u9488\uff0c\u56e0\u6b64\u5176\u5185\u90e8\u7ed3\u70b9\u76f8\u5bf9B\u6811\u66f4\u5c0f\u3002<\/p>\n

      \u5982\u679c\u628a\u6240\u6709\u540c\u4e00\u5185\u90e8\u7ed3\u70b9\u7684\u5173\u952e\u5b57\u5b58\u653e\u5728\u540c\u4e00\u76d8\u5757\u4e2d\uff0c\u90a3\u4e48\u76d8\u5757\u6240\u80fd\u5bb9\u7eb3\u7684\u5173\u952e\u5b57\u6570\u91cf\u4e5f\u8d8a\u591a\u3002\u4e00\u6b21\u6027\u8bfb\u5165\u5185\u5b58\u4e2d\u7684\u9700\u8981\u67e5\u627e\u7684\u5173\u952e\u5b57\u4e5f\u5c31\u8d8a\u591a\u3002\u76f8\u5bf9\u6765\u8bf4IO\u8bfb\u5199\u6b21\u6570\u4e5f\u5c31\u964d\u4f4e\u4e86\u3002<\/p>\n

      2\u3001B+-tree\u7684\u67e5\u8be2\u6548\u7387\u66f4\u52a0\u7a33\u5b9a\u3002<\/p>\n

      \u7531\u4e8e\u975e\u7ec8\u7ed3\u70b9\u5e76\u4e0d\u662f\u6700\u7ec8\u6307\u5411\u6587\u4ef6\u5185\u5bb9\u7684\u7ed3\u70b9\uff0c\u800c\u53ea\u662f\u53f6\u5b50\u7ed3\u70b9\u4e2d\u5173\u952e\u5b57\u7684\u7d22\u5f15\u3002\u6240\u4ee5\u4efb\u4f55\u5173\u952e\u5b57\u7684\u67e5\u627e\u5fc5\u987b\u8d70\u4e00\u6761\u4ece\u6839\u7ed3\u70b9\u5230\u53f6\u5b50\u7ed3\u70b9\u7684\u8def\u3002\u6240\u6709\u5173\u952e\u5b57\u67e5\u8be2\u7684\u8def\u5f84\u957f\u5ea6\u76f8\u540c\uff0c\u5bfc\u81f4\u6bcf\u4e00\u4e2a\u6570\u636e\u7684\u67e5\u8be2\u6548\u7387\u76f8\u5f53\u3002<\/p>\n

      \u516b\u3001MySQL\u8054\u5408\u7d22\u5f15<\/strong><\/p>\n

      1\u3001\u8054\u5408\u7d22\u5f15\u662f\u4e24\u4e2a\u6216\u66f4\u591a\u4e2a\u5217\u4e0a\u7684\u7d22\u5f15\u3002<\/p>\n

      \u5bf9\u4e8e\u8054\u5408\u7d22\u5f15:Mysql\u4ece\u5de6\u5230\u53f3\u7684\u4f7f\u7528\u7d22\u5f15\u4e2d\u7684\u5b57\u6bb5\uff0c\u4e00\u4e2a\u67e5\u8be2\u53ef\u4ee5\u53ea\u4f7f\u7528\u7d22\u5f15\u4e2d\u7684\u4e00\u90e8\u4efd\uff0c\u4f46\u53ea\u80fd\u662f\u6700\u5de6\u4fa7\u90e8\u5206\u3002<\/p>\n

      \u4f8b\u5982\u7d22\u5f15\u662fkey index (a,b,c). \u53ef\u4ee5\u652f\u6301a \u3001 a,b \u3001 a,b,c 3\u79cd\u7ec4\u5408\u8fdb\u884c\u67e5\u627e\uff0c\u4f46\u4e0d\u652f\u6301 b,c\u8fdb\u884c\u67e5\u627e .\u5f53\u6700\u5de6\u4fa7\u5b57\u6bb5\u662f\u5e38\u91cf\u5f15\u7528\u65f6\uff0c\u7d22\u5f15\u5c31\u5341\u5206\u6709\u6548\u3002<\/p>\n

      2\u3001\u5229\u7528\u7d22\u5f15\u4e2d\u7684\u9644\u52a0\u5217\uff0c\u60a8\u53ef\u4ee5\u7f29\u5c0f\u641c\u7d22\u7684\u8303\u56f4\uff0c\u4f46\u4f7f\u7528\u4e00\u4e2a\u5177\u6709\u4e24\u5217\u7684\u7d22\u5f15\u4e0d\u540c\u4e8e\u4f7f\u7528\u4e24\u4e2a\u5355\u72ec\u7684\u7d22\u5f15\u3002<\/p>\n

      \u590d\u5408\u7d22\u5f15\u7684\u7ed3\u6784\u4e0e\u7535\u8bdd\u7c3f\u7c7b\u4f3c\uff0c\u4eba\u540d\u7531\u59d3\u548c\u540d\u6784\u6210\uff0c\u7535\u8bdd\u7c3f\u9996\u5148\u6309\u59d3\u6c0f\u5bf9\u8fdb\u884c\u6392\u5e8f\uff0c\u7136\u540e\u6309\u540d\u5b57\u5bf9\u6709\u76f8\u540c\u59d3\u6c0f\u7684\u4eba\u8fdb\u884c\u6392\u5e8f\u3002<\/p>\n

      \u5982\u679c\u60a8\u77e5\u9053\u59d3\uff0c\u7535\u8bdd\u7c3f\u5c06\u975e\u5e38\u6709\u7528\uff1b\u5982\u679c\u60a8\u77e5\u9053\u59d3\u548c\u540d\uff0c\u7535\u8bdd\u7c3f\u5219\u66f4\u4e3a\u6709\u7528\uff0c\u4f46\u5982\u679c\u60a8\u53ea\u77e5\u9053\u540d\u4e0d\u77e5\u9053\u59d3\uff0c\u7535\u8bdd\u7c3f\u5c06\u6ca1\u6709\u7528\u5904\u3002<\/p>\n

      \u4e5d\u3001\u4ec0\u4e48\u60c5\u51b5\u4e0b\u5e94\u4e0d\u5efa\u6216\u5c11\u5efa\u7d22\u5f15<\/strong><\/p>\n

      1\u3001\u8868\u8bb0\u5f55\u592a\u5c11<\/p>\n

      2\u3001\u7ecf\u5e38\u63d2\u5165\u3001\u5220\u9664\u3001\u4fee\u6539\u7684\u8868<\/p>\n

      3\u3001\u6570\u636e\u91cd\u590d\u4e14\u5206\u5e03\u5e73\u5747\u7684\u8868\u5b57\u6bb5\uff0c\u5047\u5982\u4e00\u4e2a\u8868\u670910\u4e07\u884c\u8bb0\u5f55\uff0c\u6709\u4e00\u4e2a\u5b57\u6bb5A\u53ea\u6709T\u548cF\u4e24\u79cd\u503c\uff0c\u4e14\u6bcf\u4e2a\u503c\u7684\u5206\u5e03\u6982\u7387\u5927\u7ea6\u4e3a50%\uff0c\u90a3\u4e48\u5bf9\u8fd9\u79cd\u8868A\u5b57\u6bb5\u5efa\u7d22\u5f15\u4e00\u822c\u4e0d\u4f1a\u63d0\u9ad8\u6570\u636e\u5e93\u7684\u67e5\u8be2\u901f\u5ea6\u3002<\/p>\n

      4\u3001\u7ecf\u5e38\u548c\u4e3b\u5b57\u6bb5\u4e00\u5757\u67e5\u8be2\u4f46\u4e3b\u5b57\u6bb5\u7d22\u5f15\u503c\u6bd4\u8f83\u591a\u7684\u8868\u5b57\u6bb5<\/p>\n

      \u5341\u3001\u4ec0\u4e48\u662f\u8868\u5206\u533a\uff1f<\/strong><\/p>\n

      \u8868\u5206\u533a\uff0c\u662f\u6307\u6839\u636e\u4e00\u5b9a\u89c4\u5219\uff0c\u5c06\u6570\u636e\u5e93\u4e2d\u7684\u4e00\u5f20\u8868\u5206\u89e3\u6210\u591a\u4e2a\u66f4\u5c0f\u7684\uff0c\u5bb9\u6613\u7ba1\u7406\u7684\u90e8\u5206\u3002\u4ece\u903b\u8f91\u4e0a\u770b\uff0c\u53ea\u6709\u4e00\u5f20\u8868\uff0c\u4f46\u662f\u5e95\u5c42\u5374\u662f\u7531\u591a\u4e2a\u7269\u7406\u5206\u533a\u7ec4\u6210\u3002<\/p>\n

      \u5341\u4e00\u3001\u8868\u5206\u533a\u4e0e\u5206\u8868\u7684\u533a\u522b<\/strong><\/p>\n

      \u5206\u8868<\/strong>\uff1a\u6307\u7684\u662f\u901a\u8fc7\u4e00\u5b9a\u89c4\u5219\uff0c\u5c06\u4e00\u5f20\u8868\u5206\u89e3\u6210\u591a\u5f20\u4e0d\u540c\u7684\u8868\u3002\u6bd4\u5982\u5c06\u7528\u6237\u8ba2\u5355\u8bb0\u5f55\u6839\u636e\u65f6\u95f4\u6210\u591a\u4e2a\u8868\u3002<\/p>\n

      \u5206\u8868\u4e0e\u5206\u533a\u7684\u533a\u522b\u5728\u4e8e<\/strong>\uff1a\u5206\u533a\u4ece\u903b\u8f91\u4e0a\u6765\u8bb2\u53ea\u6709\u4e00\u5f20\u8868\uff0c\u800c\u5206\u8868\u5219\u662f\u5c06\u4e00\u5f20\u8868\u5206\u89e3\u6210\u591a\u5f20\u8868\u3002<\/p>\n

      \u5341\u4e8c\u3001\u8868\u5206\u533a\u6709\u4ec0\u4e48\u597d\u5904\uff1f<\/strong><\/p>\n

      1\u3001\u5b58\u50a8\u66f4\u591a\u6570\u636e<\/strong>\u3002\u5206\u533a\u8868\u7684\u6570\u636e\u53ef\u4ee5\u5206\u5e03\u5728\u4e0d\u540c\u7684\u7269\u7406\u8bbe\u5907\u4e0a\uff0c\u4ece\u800c\u9ad8\u6548\u5730\u5229\u7528\u591a\u4e2a\u786c\u4ef6\u8bbe\u5907\u3002\u548c\u5355\u4e2a\u78c1\u76d8\u6216\u8005\u6587\u4ef6\u7cfb\u7edf\u76f8\u6bd4\uff0c\u53ef\u4ee5\u5b58\u50a8\u66f4\u591a\u6570\u636e<\/p>\n

      2\u3001\u4f18\u5316\u67e5\u8be2<\/strong>\u3002\u5728where\u8bed\u53e5\u4e2d\u5305\u542b\u5206\u533a\u6761\u4ef6\u65f6\uff0c\u53ef\u4ee5\u53ea\u626b\u63cf\u4e00\u4e2a\u6216\u591a\u4e2a\u5206\u533a\u8868\u6765\u63d0\u9ad8\u67e5\u8be2\u6548\u7387\uff1b\u6d89\u53casum\u548ccount\u8bed\u53e5\u65f6\uff0c\u4e5f\u53ef\u4ee5\u5728\u591a\u4e2a\u5206\u533a\u4e0a\u5e76\u884c\u5904\u7406\uff0c\u6700\u540e\u6c47\u603b\u7ed3\u679c\u3002<\/p>\n

      3\u3001\u5206\u533a\u8868\u66f4\u5bb9\u6613\u7ef4\u62a4<\/strong>\u3002\u4f8b\u5982\uff1a\u60f3\u6279\u91cf\u5220\u9664\u5927\u91cf\u6570\u636e\u53ef\u4ee5\u6e05\u9664\u6574\u4e2a\u5206\u533a\u3002<\/p>\n

      4\u3001\u907f\u514d\u67d0\u4e9b\u7279\u6b8a\u7684\u74f6\u9888<\/strong>\uff0c\u4f8b\u5982InnoDB\u7684\u5355\u4e2a\u7d22\u5f15\u7684\u4e92\u65a5\u8bbf\u95ee\uff0cext3\u95ee\u4ef7\u4f60\u7cfb\u7edf\u7684inode\u9501\u7ade\u4e89\u7b49\u3002<\/p>\n

      \u5341\u4e09\u3001\u5206\u533a\u8868\u7684\u9650\u5236\u56e0\u7d20<\/strong><\/p>\n

        \n
      1. \n

        \u4e00\u4e2a\u8868\u6700\u591a\u53ea\u80fd\u67091024\u4e2a\u5206\u533a<\/p>\n<\/li>\n

      2. \n

        MySQL5.1\u4e2d\uff0c\u5206\u533a\u8868\u8fbe\u5f0f\u5fc5\u987b\u662f\u6574\u6570\uff0c\u6216\u8005\u8fd4\u56de\u6574\u6570\u7684\u8868\u8fbe\u5f0f\u3002\u5728MySQL5.5\u4e2d\u63d0\u4f9b\u4e86\u975e\u6574\u6570\u8868\u8fbe\u5f0f\u5206\u533a\u7684\u652f\u6301\u3002<\/p>\n<\/li>\n

      3. \n

        \u5982\u679c\u5206\u533a\u5b57\u6bb5\u4e2d\u6709\u4e3b\u952e\u6216\u8005\u552f\u4e00\u7d22\u5f15\u7684\u5217\uff0c\u90a3\u4e48\u591a\u6709\u4e3b\u952e\u5217\u548c\u552f\u4e00\u7d22\u5f15\u5217\u90fd\u5fc5\u987b\u5305\u542b\u8fdb\u6765\u3002\u5373\uff1a\u5206\u533a\u5b57\u6bb5\u8981\u4e48\u4e0d\u5305\u542b\u4e3b\u952e\u6216\u8005\u7d22\u5f15\u5217\uff0c\u8981\u4e48\u5305\u542b\u5168\u90e8\u4e3b\u952e\u548c\u7d22\u5f15\u5217\u3002<\/p>\n<\/li>\n

      4. \n

        \u5206\u533a\u8868\u4e2d\u65e0\u6cd5\u4f7f\u7528\u5916\u952e\u7ea6\u675f<\/p>\n<\/li>\n

      5. \n

        MySQL\u7684\u5206\u533a\u9002\u7528\u4e8e\u4e00\u4e2a\u8868\u7684\u6240\u6709\u6570\u636e\u548c\u7d22\u5f15\uff0c\u4e0d\u80fd\u53ea\u5bf9\u8868\u6570\u636e\u5206\u533a\u800c\u4e0d\u5bf9\u7d22\u5f15\u5206\u533a\uff0c\u4e5f\u4e0d\u80fd\u53ea\u5bf9\u7d22\u5f15\u5206\u533a\u800c\u4e0d\u5bf9\u8868\u5206\u533a\uff0c\u4e5f\u4e0d\u80fd\u53ea\u5bf9\u8868\u7684\u4e00\u90e8\u5206\u6570\u636e\u5206\u533a\u3002<\/p>\n<\/li>\n<\/ol>\n

        \u5341\u56db\u3001\u5982\u4f55\u5224\u65ad\u5f53\u524dMySQL\u662f\u5426\u652f\u6301\u5206\u533a\uff1f<\/strong><\/p>\n

        \u547d\u4ee4\uff1ashow variables like '%partition%' \u8fd0\u884c\u7ed3\u679c:<\/p>\n

         <\/span><\/p>\n

        have_partintioning \u7684\u503c\u4e3aYES\uff0c\u8868\u793a\u652f\u6301\u5206\u533a\u3002<\/p>\n

        \u5341\u4e94\u3001MySQL\u652f\u6301\u7684\u5206\u533a\u7c7b\u578b\u6709\u54ea\u4e9b\uff1f<\/strong><\/p>\n

          \n
        1. \n

          RANGE\u5206\u533a<\/strong>\uff1a \u8fd9\u79cd\u6a21\u5f0f\u5141\u8bb8\u5c06\u6570\u636e\u5212\u5206\u4e0d\u540c\u8303\u56f4\u3002\u4f8b\u5982\u53ef\u4ee5\u5c06\u4e00\u4e2a\u8868\u901a\u8fc7\u5e74\u4efd\u5212\u5206\u6210\u82e5\u5e72\u4e2a\u5206\u533a<\/p>\n<\/li>\n

        2. \n

          LIST\u5206\u533a<\/strong>\uff1a \u8fd9\u79cd\u6a21\u5f0f\u5141\u8bb8\u7cfb\u7edf\u901a\u8fc7\u9884\u5b9a\u4e49\u7684\u5217\u8868\u7684\u503c\u6765\u5bf9\u6570\u636e\u8fdb\u884c\u5206\u5272\u3002\u6309\u7167List\u4e2d\u7684\u503c\u5206\u533a\uff0c\u4e0eRANGE\u7684\u533a\u522b\u662f\uff0crange\u5206\u533a\u7684\u533a\u95f4\u8303\u56f4\u503c\u662f\u8fde\u7eed\u7684\u3002<\/p>\n<\/li>\n

        3. \n

          HASH\u5206\u533a<\/strong> \uff1a\u8fd9\u4e2d\u6a21\u5f0f\u5141\u8bb8\u901a\u8fc7\u5bf9\u8868\u7684\u4e00\u4e2a\u6216\u591a\u4e2a\u5217\u7684Hash Key\u8fdb\u884c\u8ba1\u7b97\uff0c\u6700\u540e\u901a\u8fc7\u8fd9\u4e2aHash\u7801\u4e0d\u540c\u6570\u503c\u5bf9\u5e94\u7684\u6570\u636e\u533a\u57df\u8fdb\u884c\u5206\u533a\u3002\u4f8b\u5982\u53ef\u4ee5\u5efa\u7acb\u4e00\u4e2a\u5bf9\u8868\u4e3b\u952e\u8fdb\u884c\u5206\u533a\u7684\u8868\u3002<\/p>\n<\/li>\n

        4. \n

          KEY\u5206\u533a <\/strong>\uff1a\u4e0a\u9762Hash\u6a21\u5f0f\u7684\u4e00\u79cd\u5ef6\u4f38\uff0c\u8fd9\u91cc\u7684Hash Key\u662fMySQL\u7cfb\u7edf\u4ea7\u751f\u7684\u3002<\/p>\n<\/li>\n<\/ol>\n

          \u5341\u516d\u3001\u56db\u79cd\u9694\u79bb\u7ea7\u522b<\/strong><\/p>\n

            \n
          1. \n

            Serializable (\u4e32\u884c\u5316)<\/strong>\uff1a\u53ef\u907f\u514d\u810f\u8bfb\u3001\u4e0d\u53ef\u91cd\u590d\u8bfb\u3001\u5e7b\u8bfb\u7684\u53d1\u751f\u3002<\/p>\n<\/li>\n

          2. \n

            Repeatable read (\u53ef\u91cd\u590d\u8bfb)<\/strong>\uff1a\u53ef\u907f\u514d\u810f\u8bfb\u3001\u4e0d\u53ef\u91cd\u590d\u8bfb\u7684\u53d1\u751f\u3002<\/p>\n<\/li>\n

          3. \n

            Read committed (\u8bfb\u5df2\u63d0\u4ea4)<\/strong>\uff1a\u53ef\u907f\u514d\u810f\u8bfb\u7684\u53d1\u751f\u3002<\/p>\n<\/li>\n

          4. \n

            Read uncommitted (\u8bfb\u672a\u63d0\u4ea4)<\/strong>\uff1a\u6700\u4f4e\u7ea7\u522b\uff0c\u4efb\u4f55\u60c5\u51b5\u90fd\u65e0\u6cd5\u4fdd\u8bc1\u3002<\/p>\n<\/li>\n<\/ol>\n

            \u5341\u4e03\u3001\u5173\u4e8eMVVC<\/strong><\/p>\n

            MySQL InnoDB\u5b58\u50a8\u5f15\u64ce\uff0c\u5b9e\u73b0\u7684\u662f\u57fa\u4e8e\u591a\u7248\u672c\u7684\u5e76\u53d1\u63a7\u5236\u534f\u8bae\u2014\u2014MVCC (Multi-Version Concurrency Control) <\/p>\n

            \u6ce8<\/strong>\uff1a\u4e0eMVCC\u76f8\u5bf9\u7684\uff0c\u662f\u57fa\u4e8e\u9501\u7684\u5e76\u53d1\u63a7\u5236\uff0cLock-Based Concurrency Control<\/p>\n

            MVCC\u6700\u5927\u7684\u597d\u5904<\/strong>\uff1a\u8bfb\u4e0d\u52a0\u9501\uff0c\u8bfb\u5199\u4e0d\u51b2\u7a81\u3002\u5728\u8bfb\u591a\u5199\u5c11\u7684OLTP\u5e94\u7528\u4e2d\uff0c\u8bfb\u5199\u4e0d\u51b2\u7a81\u662f\u975e\u5e38\u91cd\u8981\u7684\uff0c\u6781\u5927\u7684\u589e\u52a0\u4e86\u7cfb\u7edf\u7684\u5e76\u53d1\u6027\u80fd\uff0c\u73b0\u9636\u6bb5\u51e0\u4e4e\u6240\u6709\u7684RDBMS\uff0c\u90fd\u652f\u6301\u4e86MVCC\u3002<\/p>\n

              \n
            1. \n

              LBCC\uff1aLock-Based Concurrency Control\uff0c\u57fa\u4e8e\u9501\u7684\u5e76\u53d1\u63a7\u5236<\/p>\n<\/li>\n

            2. \n

              MVCC\uff1aMulti-Version Concurrency Control<\/p>\n

              \u57fa\u4e8e\u591a\u7248\u672c\u7684\u5e76\u53d1\u63a7\u5236\u534f\u8bae\u3002\u7eaf\u7cb9\u57fa\u4e8e\u9501\u7684\u5e76\u53d1\u673a\u5236\u5e76\u53d1\u91cf\u4f4e\uff0cMVCC\u662f\u5728\u57fa\u4e8e\u9501\u7684\u5e76\u53d1\u63a7\u5236\u4e0a\u7684\u6539\u8fdb\uff0c\u4e3b\u8981\u662f\u5728\u8bfb\u64cd\u4f5c\u4e0a\u63d0\u9ad8\u4e86\u5e76\u53d1\u91cf\u3002<\/p>\n<\/li>\n<\/ol>\n

              \u5341\u516b\u3001\u5728MVCC\u5e76\u53d1\u63a7\u5236\u4e2d\uff0c\u8bfb\u64cd\u4f5c\u53ef\u4ee5\u5206\u6210\u4e24\u7c7b\uff1a<\/strong><\/p>\n

                \n
              1. \n

                \u5feb\u7167\u8bfb (snapshot read)<\/strong>\uff1a\u8bfb\u53d6\u7684\u662f\u8bb0\u5f55\u7684\u53ef\u89c1\u7248\u672c (\u6709\u53ef\u80fd\u662f\u5386\u53f2\u7248\u672c)\uff0c\u4e0d\u7528\u52a0\u9501\uff08\u5171\u4eab\u8bfb\u9501s\u9501\u4e5f\u4e0d\u52a0\uff0c\u6240\u4ee5\u4e0d\u4f1a\u963b\u585e\u5176\u4ed6\u4e8b\u52a1\u7684\u5199\uff09<\/p>\n<\/li>\n

              2. \n

                \u5f53\u524d\u8bfb (current read)<\/strong>\uff1a\u8bfb\u53d6\u7684\u662f\u8bb0\u5f55\u7684\u6700\u65b0\u7248\u672c\uff0c\u5e76\u4e14\uff0c\u5f53\u524d\u8bfb\u8fd4\u56de\u7684\u8bb0\u5f55\uff0c\u90fd\u4f1a\u52a0\u4e0a\u9501\uff0c\u4fdd\u8bc1\u5176\u4ed6\u4e8b\u52a1\u4e0d\u4f1a\u518d\u5e76\u53d1\u4fee\u6539\u8fd9\u6761\u8bb0\u5f55<\/p>\n<\/li>\n<\/ol>\n

                \u5341\u4e5d\u3001\u884c\u7ea7\u9501\u5b9a\u7684\u4f18\u70b9\uff1a<\/strong><\/p>\n

                1\u3001\u5f53\u5728\u8bb8\u591a\u7ebf\u7a0b\u4e2d\u8bbf\u95ee\u4e0d\u540c\u7684\u884c\u65f6\u53ea\u5b58\u5728\u5c11\u91cf\u9501\u5b9a\u51b2\u7a81\u3002<\/p>\n

                2\u3001\u56de\u6eda\u65f6\u53ea\u6709\u5c11\u91cf\u7684\u66f4\u6539<\/p>\n

                3\u3001\u53ef\u4ee5\u957f\u65f6\u95f4\u9501\u5b9a\u5355\u4e00\u7684\u884c\u3002<\/p>\n

                \u4e8c\u5341\u3001\u884c\u7ea7\u9501\u5b9a\u7684\u7f3a\u70b9\uff1a<\/strong><\/p>\n

                  \n
                1. \n

                  \u6bd4\u9875\u7ea7\u6216\u8868\u7ea7\u9501\u5b9a\u5360\u7528\u66f4\u591a\u7684\u5185\u5b58\u3002<\/p>\n<\/li>\n

                2. \n

                  \u5f53\u5728\u8868\u7684\u5927\u90e8\u5206\u4e2d\u4f7f\u7528\u65f6\uff0c\u6bd4\u9875\u7ea7\u6216\u8868\u7ea7\u9501\u5b9a\u901f\u5ea6\u6162\uff0c\u56e0\u4e3a\u4f60\u5fc5\u987b\u83b7\u53d6\u66f4\u591a\u7684\u9501\u3002<\/p>\n<\/li>\n

                3. \n

                  \u5982\u679c\u4f60\u5728\u5927\u90e8\u5206\u6570\u636e\u4e0a\u7ecf\u5e38\u8fdb\u884cGROUP BY\u64cd\u4f5c\u6216\u8005\u5fc5\u987b\u7ecf\u5e38\u626b\u63cf\u6574\u4e2a\u8868\uff0c\u6bd4\u5176\u5b83\u9501\u5b9a\u660e\u663e\u6162\u5f88\u591a\u3002<\/p>\n<\/li>\n

                4. \n

                  \u7528\u9ad8\u7ea7\u522b\u9501\u5b9a\uff0c\u901a\u8fc7\u652f\u6301\u4e0d\u540c\u7684\u7c7b\u578b\u9501\u5b9a\uff0c\u4f60\u4e5f\u53ef\u4ee5\u5f88\u5bb9\u6613\u5730\u8c03\u8282\u5e94\u7528\u7a0b\u5e8f\uff0c\u56e0\u4e3a\u5176\u9501\u6210\u672c\u5c0f\u4e8e\u884c\u7ea7\u9501\u5b9a\u3002<\/p>\n<\/li>\n<\/ol>\n

                  \u4e8c\u5341\u4e00\u3001MySQL\u4f18\u5316<\/strong><\/p>\n

                    \n
                  1. \n

                    \u5f00\u542f\u67e5\u8be2\u7f13\u5b58\uff0c\u4f18\u5316\u67e5\u8be2<\/p>\n<\/li>\n

                  2. \n

                    explain\u4f60\u7684select\u67e5\u8be2\uff0c\u8fd9\u53ef\u4ee5\u5e2e\u4f60\u5206\u6790\u4f60\u7684\u67e5\u8be2\u8bed\u53e5\u6216\u662f\u8868\u7ed3\u6784\u7684\u6027\u80fd\u74f6\u9888\u3002EXPLAIN \u7684\u67e5\u8be2\u7ed3\u679c\u8fd8\u4f1a\u544a\u8bc9\u4f60\u4f60\u7684\u7d22\u5f15\u4e3b\u952e\u88ab\u5982\u4f55\u5229\u7528\u7684\uff0c\u4f60\u7684\u6570\u636e\u8868\u662f\u5982\u4f55\u88ab\u641c\u7d22\u548c\u6392\u5e8f\u7684<\/p>\n<\/li>\n

                  3. \n

                    \u5f53\u53ea\u8981\u4e00\u884c\u6570\u636e\u65f6\u4f7f\u7528limit 1\uff0cMySQL\u6570\u636e\u5e93\u5f15\u64ce\u4f1a\u5728\u627e\u5230\u4e00\u6761\u6570\u636e\u540e\u505c\u6b62\u641c\u7d22\uff0c\u800c\u4e0d\u662f\u7ee7\u7eed\u5f80\u540e\u67e5\u5c11\u4e0b\u4e00\u6761\u7b26\u5408\u8bb0\u5f55\u7684\u6570\u636e<\/p>\n<\/li>\n

                  4. \n

                    \u4e3a\u641c\u7d22\u5b57\u6bb5\u5efa\u7d22\u5f15<\/p>\n<\/li>\n

                  5. \n

                    \u4f7f\u7528 ENUM \u800c\u4e0d\u662f VARCHAR\u3002\u5982\u679c\u4f60\u6709\u4e00\u4e2a\u5b57\u6bb5\uff0c\u6bd4\u5982\u201c\u6027\u522b\u201d\uff0c\u201c\u56fd\u5bb6\u201d\uff0c\u201c\u6c11\u65cf\u201d\uff0c\u201c\u72b6\u6001\u201d\u6216\u201c\u90e8\u95e8\u201d\uff0c\u4f60\u77e5\u9053\u8fd9\u4e9b\u5b57\u6bb5\u7684\u53d6\u503c\u662f\u6709\u9650\u800c\u4e14\u56fa\u5b9a\u7684\uff0c\u90a3\u4e48\uff0c\u4f60\u5e94\u8be5\u4f7f\u7528 ENUM \u800c\u4e0d\u662fVARCHAR<\/p>\n<\/li>\n

                  6. \n

                    Prepared StatementsPrepared Statements\u5f88\u50cf\u5b58\u50a8\u8fc7\u7a0b\uff0c\u662f\u4e00\u79cd\u8fd0\u884c\u5728\u540e\u53f0\u7684SQL\u8bed\u53e5\u96c6\u5408\uff0c\u6211\u4eec\u53ef\u4ee5\u4ece\u4f7f\u7528 prepared statements \u83b7\u5f97\u5f88\u591a\u597d\u5904\uff0c\u65e0\u8bba\u662f\u6027\u80fd\u95ee\u9898\u8fd8\u662f\u5b89\u5168\u95ee\u9898\u3002<\/p>\n

                    Prepared Statements \u53ef\u4ee5\u68c0\u67e5\u4e00\u4e9b\u4f60\u7ed1\u5b9a\u597d\u7684\u53d8\u91cf\uff0c\u8fd9\u6837\u53ef\u4ee5\u4fdd\u62a4\u4f60\u7684\u7a0b\u5e8f\u4e0d\u4f1a\u53d7\u5230\u201cSQL\u6ce8\u5165\u5f0f\u201d\u653b\u51fb<\/p>\n<\/li>\n

                  7. \n

                    \u5782\u76f4\u5206\u8868<\/p>\n<\/li>\n

                  8. \n

                    \u9009\u62e9\u6b63\u786e\u7684\u5b58\u50a8\u5f15\u64ce<\/p>\n<\/li>\n<\/ol>\n

                    \u4e8c\u5341\u4e8c\u3001key\u548cindex\u7684\u533a\u522b<\/strong><\/p>\n

                      \n
                    1. \n

                      key \u662f\u6570\u636e\u5e93\u7684\u7269\u7406\u7ed3\u6784\uff0c\u5b83\u5305\u542b\u4e24\u5c42\u610f\u4e49\u548c\u4f5c\u7528\uff0c\u4e00\u662f\u7ea6\u675f\uff08\u504f\u91cd\u4e8e\u7ea6\u675f\u548c\u89c4\u8303\u6570\u636e\u5e93\u7684\u7ed3\u6784\u5b8c\u6574\u6027\uff09\uff0c\u4e8c\u662f\u7d22\u5f15\uff08\u8f85\u52a9\u67e5\u8be2\u7528\u7684\uff09\u3002\u5305\u62ecprimary key, unique key, foreign key \u7b49<\/p>\n<\/li>\n

                    2. \n

                      index\u662f\u6570\u636e\u5e93\u7684\u7269\u7406\u7ed3\u6784\uff0c\u5b83\u53ea\u662f\u8f85\u52a9\u67e5\u8be2\u7684\uff0c\u5b83\u521b\u5efa\u65f6\u4f1a\u5728\u53e6\u5916\u7684\u8868\u7a7a\u95f4\uff08mysql\u4e2d\u7684innodb\u8868\u7a7a\u95f4\uff09\u4ee5\u4e00\u4e2a\u7c7b\u4f3c\u76ee\u5f55\u7684\u7ed3\u6784\u5b58\u50a8\u3002\u7d22\u5f15\u8981\u5206\u7c7b\u7684\u8bdd\uff0c\u5206\u4e3a\u524d\u7f00\u7d22\u5f15\u3001\u5168\u6587\u672c\u7d22\u5f15\u7b49\uff1b<\/p>\n<\/li>\n<\/ol>\n

                      \u4e8c\u5341\u4e09\u3001Mysql \u4e2d MyISAM \u548c InnoDB \u7684\u533a\u522b\u6709\u54ea\u4e9b\uff1f<\/strong><\/p>\n

                      \u533a\u522b\uff1a<\/strong><\/p>\n

                        \n
                      1. \n

                        InnoDB\u652f\u6301\u4e8b\u52a1\uff0cMyISAM\u4e0d\u652f\u6301<\/p>\n

                        \u5bf9\u4e8eInnoDB\u6bcf\u4e00\u6761SQL\u8bed\u8a00\u90fd\u9ed8\u8ba4\u5c01\u88c5\u6210\u4e8b\u52a1\uff0c\u81ea\u52a8\u63d0\u4ea4\uff0c\u8fd9\u6837\u4f1a\u5f71\u54cd\u901f\u5ea6\uff0c\u6240\u4ee5\u6700\u597d\u628a\u591a\u6761SQL\u8bed\u8a00\u653e\u5728begin\u548ccommit\u4e4b\u95f4\uff0c\u7ec4\u6210\u4e00\u4e2a\u4e8b\u52a1\uff1b<\/p>\n<\/li>\n

                      2. \n

                        InnoDB\u652f\u6301\u5916\u952e\uff0c\u800cMyISAM\u4e0d\u652f\u6301\u3002\u5bf9\u4e00\u4e2a\u5305\u542b\u5916\u952e\u7684InnoDB\u8868\u8f6c\u4e3aMYISAM\u4f1a\u5931\u8d25\uff1b<\/p>\n<\/li>\n

                      3. \n

                        InnoDB\u662f\u805a\u96c6\u7d22\u5f15\uff0c\u6570\u636e\u6587\u4ef6\u662f\u548c\u7d22\u5f15\u7ed1\u5728\u4e00\u8d77\u7684\uff0c\u5fc5\u987b\u8981\u6709\u4e3b\u952e\uff0c\u901a\u8fc7\u4e3b\u952e\u7d22\u5f15\u6548\u7387\u5f88\u9ad8\u3002<\/p>\n

                        \u4f46\u662f\u8f85\u52a9\u7d22\u5f15\u9700\u8981\u4e24\u6b21\u67e5\u8be2\uff0c\u5148\u67e5\u8be2\u5230\u4e3b\u952e\uff0c\u7136\u540e\u518d\u901a\u8fc7\u4e3b\u952e\u67e5\u8be2\u5230\u6570\u636e\u3002\u56e0\u6b64\u4e3b\u952e\u4e0d\u5e94\u8be5\u8fc7\u5927\uff0c\u56e0\u4e3a\u4e3b\u952e\u592a\u5927\uff0c\u5176\u4ed6\u7d22\u5f15\u4e5f\u90fd\u4f1a\u5f88\u5927\u3002<\/p>\n

                        \u800cMyISAM\u662f\u975e\u805a\u96c6\u7d22\u5f15\uff0c\u6570\u636e\u6587\u4ef6\u662f\u5206\u79bb\u7684\uff0c\u7d22\u5f15\u4fdd\u5b58\u7684\u662f\u6570\u636e\u6587\u4ef6\u7684\u6307\u9488\u3002\u4e3b\u952e\u7d22\u5f15\u548c\u8f85\u52a9\u7d22\u5f15\u662f\u72ec\u7acb\u7684\u3002<\/p>\n<\/li>\n

                      4. \n

                        InnoDB\u4e0d\u4fdd\u5b58\u8868\u7684\u5177\u4f53\u884c\u6570\uff0c\u6267\u884cselect count(*) from table\u65f6\u9700\u8981\u5168\u8868\u626b\u63cf\u3002\u800cMyISAM\u7528\u4e00\u4e2a\u53d8\u91cf\u4fdd\u5b58\u4e86\u6574\u4e2a\u8868\u7684\u884c\u6570\uff0c\u6267\u884c\u4e0a\u8ff0\u8bed\u53e5\u65f6\u53ea\u9700\u8981\u8bfb\u51fa\u8be5\u53d8\u91cf\u5373\u53ef\uff0c\u901f\u5ea6\u5f88\u5feb\uff1b<\/p>\n<\/li>\n

                      5. \n

                        Innodb\u4e0d\u652f\u6301\u5168\u6587\u7d22\u5f15\uff0c\u800cMyISAM\u652f\u6301\u5168\u6587\u7d22\u5f15\uff0c\u67e5\u8be2\u6548\u7387\u4e0aMyISAM\u8981\u9ad8\uff1b<\/p>\n<\/li>\n<\/ol>\n

                        \u5982\u4f55\u9009\u62e9\uff1a<\/strong><\/p>\n

                          \n
                        1. \n

                          \u662f\u5426\u8981\u652f\u6301\u4e8b\u52a1\uff0c\u5982\u679c\u8981\u8bf7\u9009\u62e9innodb\uff0c\u5982\u679c\u4e0d\u9700\u8981\u53ef\u4ee5\u8003\u8651MyISAM\uff1b<\/p>\n<\/li>\n

                        2. \n

                          \u5982\u679c\u8868\u4e2d\u7edd\u5927\u591a\u6570\u90fd\u53ea\u662f\u8bfb\u67e5\u8be2\uff0c\u53ef\u4ee5\u8003\u8651MyISAM\uff0c\u5982\u679c\u65e2\u6709\u8bfb\u5199\u4e5f\u633a\u9891\u7e41\uff0c\u8bf7\u4f7f\u7528InnoDB<\/p>\n<\/li>\n

                        3. \n

                          \u7cfb\u7edf\u5954\u6e83\u540e\uff0cMyISAM\u6062\u590d\u8d77\u6765\u66f4\u56f0\u96be\uff0c\u80fd\u5426\u63a5\u53d7\uff1b<\/p>\n<\/li>\n

                        4. \n

                          MySQL5.5\u7248\u672c\u5f00\u59cbInnodb\u5df2\u7ecf\u6210\u4e3aMysql\u7684\u9ed8\u8ba4\u5f15\u64ce(\u4e4b\u524d\u662fMyISAM)\uff0c\u8bf4\u660e\u5176\u4f18\u52bf\u662f\u6709\u76ee\u5171\u7779\u7684\uff0c\u5982\u679c\u4f60\u4e0d\u77e5\u9053\u7528\u4ec0\u4e48\uff0c\u90a3\u5c31\u7528InnoDB\uff0c\u81f3\u5c11\u4e0d\u4f1a\u5dee\u3002<\/p>\n<\/li>\n<\/ol>\n

                          \u4e8c\u5341\u56db\u3001\u6570\u636e\u5e93\u8868\u521b\u5efa\u6ce8\u610f\u4e8b\u9879<\/strong><\/p>\n

                          1\u3001\u5b57\u6bb5\u540d\u53ca\u5b57\u6bb5\u914d\u5236\u5408\u7406\u6027<\/strong><\/p>\n

                          \n
                        5. \n

                          \u5254\u9664\u5173\u7cfb\u4e0d\u5bc6\u5207\u7684\u5b57\u6bb5\uff1b<\/p>\n<\/li>\n

                        6. \n

                          \u5b57\u6bb5\u547d\u540d\u8981\u6709\u89c4\u5219\u53ca\u76f8\u5bf9\u5e94\u7684\u542b\u4e49\uff08\u4e0d\u8981\u4e00\u90e8\u5206\u82f1\u6587\uff0c\u4e00\u90e8\u5206\u62fc\u97f3\uff0c\u8fd8\u6709\u7c7b\u4f3ca.b.c\u8fd9\u6837\u4e0d\u660e\u542b\u4e49\u7684\u5b57\u6bb5\uff09\uff1b<\/p>\n<\/li>\n

                        7. \n

                          \u5b57\u6bb5\u547d\u540d\u5c3d\u91cf\u4e0d\u8981\u4f7f\u7528\u7f29\u5199\uff08\u5927\u591a\u6570\u7f29\u5199\u90fd\u4e0d\u80fd\u660e\u786e\u5b57\u6bb5\u542b\u4e49\uff09\uff1b<\/p>\n<\/li>\n

                        8. \n

                          \u5b57\u6bb5\u4e0d\u8981\u5927\u5c0f\u5199\u6df7\u7528\uff08\u60f3\u8981\u5177\u6709\u53ef\u8bfb\u6027\uff0c\u591a\u4e2a\u82f1\u6587\u5355\u8bcd\u53ef\u4f7f\u7528\u4e0b\u5212\u7ebf\u5f62\u5f0f\u8fde\u63a5\uff09\uff1b<\/p>\n<\/li>\n

                        9. \n

                          \u5b57\u6bb5\u540d\u4e0d\u8981\u4f7f\u7528\u4fdd\u7559\u5b57\u6216\u8005\u5173\u952e\u5b57\uff1b<\/p>\n<\/li>\n

                        10. \n

                          \u4fdd\u6301\u5b57\u6bb5\u540d\u548c\u7c7b\u578b\u7684\u4e00\u81f4\u6027\uff1b<\/p>\n<\/li>\n

                        11. \n

                          \u614e\u91cd\u9009\u62e9\u6570\u5b57\u7c7b\u578b\uff1b<\/p>\n<\/li>\n

                        12. \n

                          \u7ed9\u6587\u672c\u5b57\u6bb5\u7559\u8db3\u4f59\u91cf\uff1b<\/p>\n<\/li>\n<\/ul>\n

                          2\u3001\u7cfb\u7edf\u7279\u6b8a\u5b57\u6bb5\u5904\u7406\u53ca\u5efa\u6210\u540e\u5efa\u8bae<\/strong><\/p>\n

                          \n
                        13. \n

                          \u6dfb\u52a0\u5220\u9664\u6807\u8bb0\uff08\u4f8b\u5982\u64cd\u4f5c\u4eba\u3001\u5220\u9664\u65f6\u95f4\uff09\uff1b<\/p>\n<\/li>\n

                        14. \n

                          \u5efa\u7acb\u7248\u672c\u673a\u5236\uff1b<\/p>\n<\/li>\n<\/ul>\n

                          3\u3001\u8868\u7ed3\u6784\u5408\u7406\u6027\u914d\u7f6e<\/strong><\/p>\n

                          \n
                        15. \n

                          \u591a\u578b\u5b57\u6bb5\u7684\u5904\u7406\uff0c\u5c31\u662f\u8868\u4e2d\u662f\u5426\u5b58\u5728\u5b57\u6bb5\u80fd\u591f\u5206\u89e3\u6210\u66f4\u5c0f\u72ec\u7acb\u7684\u51e0\u90e8\u5206\uff08\u4f8b\u5982\uff1a\u4eba\u53ef\u4ee5\u5206\u4e3a\u7537\u4eba\u548c\u5973\u4eba\uff09\uff1b<\/p>\n<\/li>\n

                        16. \n

                          \u591a\u503c\u5b57\u6bb5\u7684\u5904\u7406\uff0c\u53ef\u4ee5\u5c06\u8868\u5206\u4e3a\u4e09\u5f20\u8868\uff0c\u8fd9\u6837\u4f7f\u5f97\u68c0\u7d22\u548c\u6392\u5e8f\u66f4\u52a0\u6709\u8c03\u7406\uff0c\u4e14\u4fdd\u8bc1\u6570\u636e\u7684\u5b8c\u6574\u6027\uff01<\/p>\n<\/li>\n<\/ul>\n

                          4\u3001\u5176\u5b83\u5efa\u8bae<\/strong><\/p>\n

                          \n
                        17. \n

                          \u5bf9\u4e8e\u5927\u6570\u636e\u5b57\u6bb5\uff0c\u72ec\u7acb\u8868\u8fdb\u884c\u5b58\u50a8\uff0c\u4ee5\u4fbf\u5f71\u54cd\u6027\u80fd\uff08\u4f8b\u5982\uff1a\u7b80\u4ecb\u5b57\u6bb5\uff09\uff1b<\/p>\n<\/li>\n

                        18. \n

                          \u4f7f\u7528varchar\u7c7b\u578b\u4ee3\u66ffchar\uff0c\u56e0\u4e3avarchar\u4f1a\u52a8\u6001\u5206\u914d\u957f\u5ea6\uff0cchar\u6307\u5b9a\u957f\u5ea6\u662f\u56fa\u5b9a\u7684\uff1b<\/p>\n<\/li>\n

                        19. \n

                          \u7ed9\u8868\u521b\u5efa\u4e3b\u952e\uff0c\u5bf9\u4e8e\u6ca1\u6709\u4e3b\u952e\u7684\u8868\uff0c\u5728\u67e5\u8be2\u548c\u7d22\u5f15\u5b9a\u4e49\u4e0a\u6709\u4e00\u5b9a\u7684\u5f71\u54cd\uff1b<\/p>\n<\/li>\n

                        20. \n

                          \u907f\u514d\u8868\u5b57\u6bb5\u8fd0\u884c\u4e3anull\uff0c\u5efa\u8bae\u8bbe\u7f6e\u9ed8\u8ba4\u503c\uff08\u4f8b\u5982\uff1aint\u7c7b\u578b\u8bbe\u7f6e\u9ed8\u8ba4\u503c\u4e3a0\uff09\u5728\u7d22\u5f15\u67e5\u8be2\u4e0a\uff0c\u6548\u7387\u7acb\u663e\uff1b<\/p>\n<\/li>\n

                        21. \n

                          \u5efa\u7acb\u7d22\u5f15\uff0c\u6700\u597d\u5efa\u7acb\u5728\u552f\u4e00\u548c\u975e\u7a7a\u7684\u5b57\u6bb5\u4e0a\uff0c\u5efa\u7acb\u592a\u591a\u7684\u7d22\u5f15\u5bf9\u540e\u671f\u63d2\u5165\u3001\u66f4\u65b0\u90fd\u5b58\u5728\u4e00\u5b9a\u7684\u5f71\u54cd\uff08\u8003\u8651\u5b9e\u9645\u60c5\u51b5\u6765\u521b\u5efa\uff09\uff1b<\/p>\n<\/li>\n<\/ul>\n

                          <\/p>\n","protected":false},"excerpt":{"rendered":"

                          \u4e00\u3001\u4e3a\u4ec0\u4e48\u7528\u81ea\u589e\u5217\u4f5c\u4e3a\u4e3b\u952e 1\u3001\u5982\u679c\u6211\u4eec\u5b9a\u4e49\u4e86\u4e3b\u952e(PRIMARY KEY)\uff0c\u90a3\u4e48InnoDB\u4f1a\u9009\u62e9\u4e3b\u952e\u4f5c\u4e3a\u805a […]<\/p>\n","protected":false},"author":1,"featured_media":1071,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[90],"tags":[],"class_list":["post-1070","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-90"],"_links":{"self":[{"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/posts\/1070"}],"collection":[{"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/comments?post=1070"}],"version-history":[{"count":1,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/posts\/1070\/revisions"}],"predecessor-version":[{"id":1075,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/posts\/1070\/revisions\/1075"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/media\/1071"}],"wp:attachment":[{"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/media?parent=1070"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/categories?post=1070"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tra56.com\/wp-json\/wp\/v2\/tags?post=1070"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}