{"id":1024,"date":"2022-10-05T19:39:25","date_gmt":"2022-10-05T11:39:25","guid":{"rendered":"http:\/\/www.licaneku.fun\/?p=1024"},"modified":"2022-10-05T19:39:25","modified_gmt":"2022-10-05T11:39:25","slug":"mysql%e8%bf%9b%e9%98%b6%e6%95%b4%e7%90%86%e4%b9%8b%e7%b4%a2%e5%bc%95%e6%a6%82%e5%bf%b5","status":"publish","type":"post","link":"http:\/\/www.licaneku.fun\/?p=1024","title":{"rendered":"Mysql\u8fdb\u9636\u6574\u7406\u4e4b\u7d22\u5f15\u6982\u5ff5"},"content":{"rendered":"<p>\u6570\u636e\u672c\u8eab\u4e4b\u5916\uff0c\u6570\u636e\u5e93\u8fd8\u7ef4\u62a4\u7740\u4e00\u4e2a\u6ee1\u8db3\u7279\u5b9a\u67e5\u627e\u7b97\u6cd5\u7684\u6570\u636e\u7ed3\u6784\uff0c\u8fd9\u4e9b\u6570\u636e\u7ed3\u6784\u4ee5\u67d0\u79cd\u65b9\u5f0f\u6307\u5411\u6570\u636e\uff0c \u8fd9\u6837\u5c31\u53ef\u4ee5\u5728\u8fd9\u4e9b\u6570\u636e\u7ed3\u6784\u7684\u57fa\u7840\u4e0a\u5b9e\u73b0\u9ad8\u7ea7\u67e5\u627e\u7b97\u6cd5\uff0c\u8fd9\u79cd\u6570\u636e\u7ed3\u6784\u5c31\u662f<strong>\u7d22\u5f15<\/strong>\u3002<strong style=\"color:red\">\u5e76\u4e14\u4e00\u822c\u6765\u8bf4\u7d22\u5f15\u672c\u8eab\u4e5f\u5f88\u5927\uff0c\u4e0d\u53ef\u80fd\u5168\u90e8\u5b58\u50a8\u5728\u5185\u5b58\u4e2d\uff0c\u56e0\u6b64\u7d22\u5f15\u5f80\u5f80\u4ee5\u7d22\u5f15\u6587\u4ef6\u5f62\u5f0f\u5b58\u50a8\u78c1\u76d8\u4e0a<\/strong><\/p>\n<p>\u78c1\u76d8\u5757\u548c\u6570\u636e\u9875\uff1a<\/p>\n<ul>\n<li>\u6570\u636e\u5e93<strong>\u7d22\u5f15\u662f\u5b58\u50a8\u5728\u78c1\u76d8\u4e0a\u7684<\/strong>\uff0c\u5982\u679c\u6570\u636e\u5f88\u5927\uff0c\u5fc5\u7136\u5bfc\u81f4\u7d22\u5f15\u7684\u5927\u5c0f\u4e5f\u4f1a\u5f88\u5927\uff0c\u8d85\u8fc7\u51e0\u4e2aG\uff08\u597d\u6bd4\u65b0\u534e\u5b57\u5178\u5b57\u6570\u591a\u5fc5\u7136\u5bfc\u81f4\u76ee\u5f55\u539a\uff09<\/li>\n<li>\u5f53\u6211\u4eec\u5229\u7528\u7d22\u5f15\u67e5\u8be2\u65f6\u5019\uff0c\u662f\u4e0d\u53ef\u80fd\u5c06\u5168\u90e8\u51e0\u4e2aG\u7684\u7d22\u5f15\u90fd\u52a0\u8f7d\u8fdb\u5185\u5b58\u7684\uff0c\u4e3a\u4e86\u964d\u4f4e\u5185\u5b58\u5f00\u9500\uff0cInnoDB\u5728\u628a\u78c1\u76d8\u6570\u636e\u8bfb\u5165\u5230\u5185\u5b58\u65f6\u4f1a\u4ee5\u9875\uff08Page\uff09\u4e3a\u57fa\u672c\u5355\u4f4d\u3002\uff08\u4e00\u6b21I\/O\u64cd\u4f5c\uff09<\/li>\n<li>\u6bcf\u4e00\u4e2a\u78c1\u76d8\u5757\u5728MySQL\u4e2d\u662f\u4e00\u4e2a\u9875\uff0c\u9875\u5927\u5c0f\u662f\u56fa\u5b9a\u7684\uff0cMySQL InnoDB\u7684\u9ed8\u8ba4\u7684\u9875\u5927\u5c0f\u662f16k\uff0c\u6bcf\u4e2a\u7d22\u5f15\u4f1a\u5206\u914d\u5728\u9875\u4e0a\u7684\u6570\u91cf\u662f\u7531\u7d22\u5f15\u5b57\u6bb5\u7684\u5927\u5c0f\u51b3\u5b9a\u3002\u5f53\u7d22\u5f15\u5b57\u6bb5\u503c\u7684\u957f\u5ea6\u8d8a\u957f\uff0c\u6bcf\u4e00\u9875\u4e0a\u7684\u6570\u91cf\u5c31\u4f1a\u8d8a\u5c11\uff0c\u56e0\u6b64\u5728\u4e00\u5b9a\u6570\u636e\u91cf\u7684\u60c5\u51b5\u4e0b\uff0c\u7d22\u5f15\u7684\u6df1\u5ea6\u4f1a\u8d8a\u6df1\uff0c\u5f71\u54cd\u7d22\u5f15\u7684\u67e5\u627e\u6548\u7387\u3002<\/li>\n<\/ul>\n<h2>\u7d22\u5f15\u7684\u597d\u5904<\/h2>\n<p>\u7c7b\u4f3c\u5927\u5b66\u56fe\u4e66\u9986\u5efa\u4e66\u76ee\u7d22\u5f15\uff0c\u63d0\u9ad8\u6570\u636e\u68c0\u7d22\u7684\u6548\u7387\uff0c\u964d\u4f4e\u6570\u636e\u5e93\u7684IO\u6210\u672c<\/p>\n<p>\u901a\u8fc7\u7d22\u5f15\u5217\u5bf9\u6570\u636e\u8fdb\u884c\u6392\u5e8f\uff0c\u964d\u4f4e\u6570\u636e\u6392\u5e8f\u7684\u6210\u672c\uff0c\u964d\u4f4e\u4e86CPU\u7684\u6d88\u8017<\/p>\n<h2>\u7d22\u5f15\u7684\u52a3\u52bf<\/h2>\n<p><strong>\u7a7a\u95f4\u4e0a\u7684\u4ee3\u4ef7\uff1a<\/strong><\/p>\n<p>\u5b9e\u9645\u4e0a\u7d22\u5f15\u4e5f\u662f\u4e00\u5f20\u8868\uff0c\u8be5\u8868\u4fdd\u5b58\u4e86\u4e3b\u952e\u4e0e\u7d22\u5f15\u5b57\u6bb5\uff0c\u5e76\u6307\u5411\u5b9e\u4f53\u8868\u7684\u8bb0\u5f55\uff0c\u6240\u4ee5\u7d22\u5f15\u5217\u4e5f\u662f\u8981\u5360\u7528\u7a7a\u95f4\u7684\u3002<\/p>\n<p><strong>\u65f6\u95f4\u4e0a\u7684\u4ee3\u4ef7\uff1a<\/strong><\/p>\n<p>\u7d22\u5f15\u662f\u5bf9\u6570\u636e\u7684\u6392\u5e8f\uff0c\u90a3\u4e48\u5f53\u5bf9\u8868\u4e2d\u7684\u6570\u636e\u8fdb\u884c\u589e\u3001\u5220\u3001\u6539\u64cd\u4f5c\u65f6\uff0c\u90fd\u9700\u8981\u53bb\u7ef4\u62a4\u4fee\u6539\u5185\u5bb9\u6d89\u53ca\u5230\u7684B+\u6811\u7d22\u5f15\u3002\u6240\u4ee5\u5728\u8fdb\u884c\u589e\u3001\u5220\u3001\u6539\u64cd\u4f5c\u65f6\u53ef\u80fd\u9700\u8981\u989d\u5916\u7684\u65f6\u95f4\u8fdb\u884c\u4e00\u4e9b\u8bb0\u5f55\u79fb\u52a8\uff0c\u9875\u9762\u5206\u88c2\u3001\u9875\u9762\u56de\u6536\u7b49\u64cd\u4f5c\u6765\u7ef4\u62a4\u597d\u6392\u5e8f\u3002<\/p>\n<h3>\u805a\u7c07\u7d22\u5f15\u548c\u975e\u805a\u7c07\u7d22\u5f15<\/h3>\n<p><strong>\u805a\u7c07\u7d22\u5f15<\/strong>\u5e76\u4e0d\u662f\u4e00\u79cd\u5355\u72ec\u7684\u7d22\u5f15\u7c7b\u578b\uff0c\u800c<strong>\u662f\u4e00\u79cd\u6570\u636e\u5b58\u50a8\u65b9\u5f0f<\/strong>\u3002\u672f\u8bed\u2018\u805a\u7c07\u2019\u8868\u793a<strong>\u6570\u636e\u8ddf\u7d22\u5f15\u653e\u5728\u4e00\u8d77\u5c31\u662f\u805a\u7c07\u7d22\u5f15<\/strong>\u3002<\/p>\n<h3>\u805a\u7c07\u7d22\u5f15\u548c\u975e\u805a\u7c07\u7d22\u5f15\u7684\u533a\u522b<\/h3>\n<p><strong>\u7b80\u5355\u6765\u8bf4\u805a\u7c07\u7d22\u5f15\u548c\u975e\u805a\u7c07\u7d22\u5f15\u7684\u533a\u522b<\/strong><\/p>\n<p>\u805a\u7c07\u7d22\u5f15\uff1a<\/p>\n<p>\u5c06\u6570\u636e\u5b58\u50a8\u4e0e\u7d22\u5f15\u653e\u5230\u4e86\u4e00\u5757\u3001\u5e76\u4e14\u662f\u6309\u7167\u4e00\u5b9a\u7684\u987a\u5e8f\u7ec4\u7ec7\u7684\uff0c\u627e\u5230\u7d22\u5f15\u4e5f\u5c31\u627e\u5230\u4e86\u6570 \u636e\uff0c\u6570\u636e\u7684\u7269\u7406\u5b58\u653e\u987a\u5e8f\u4e0e\u7d22\u5f15\u987a\u5e8f\u662f\u4e00\u81f4\u7684\uff0c\u5373\uff1a\u53ea\u8981\u7d22\u5f15\u662f\u76f8\u90bb\u7684\uff0c\u90a3\u4e48\u5bf9\u5e94\u7684\u6570\u636e\u4e00\u5b9a\u4e5f\u662f\u76f8\u90bb\u5730\u5b58\u653e\u5728\u78c1\u76d8\u4e0a\u7684\u3002<\/p>\n<p>\u975e\u805a\u7c07\u7d22\u5f15\uff1a<\/p>\n<p>\u53f6\u5b50\u8282\u70b9\u4e0d\u5b58\u50a8\u6570\u636e\u3001\u5b58\u50a8\u7684\u662f\u4e3b\u952e\u7d22\u5f15\uff0c\u4e5f\u5c31\u662f\u8bf4\u6839\u636e\u7d22\u5f15\u67e5\u627e\u5230\u4e3b\u952e\u7d22\u5f15\u7684\u4f4d\u7f6e \u518d\u6839\u636e\u4e3b\u952e\u7d22\u5f15\u5bf9\u5e94\u7684\u6570\u636e\u7269\u7406\u5730\u5740\u53bb\u78c1\u76d8\u67e5\u627e\u6570\u636e\uff0c\u8fd9\u4e2a\u5c31\u6709\u70b9\u7c7b\u4f3c\u4e00\u672c\u6811\u7684\u76ee\u5f55\uff0c\u6bd4\u5982\u6211\u4eec\u8981\u627e\u7b2c\u4e09\u7ae0\u7b2c\u4e00\u8282\uff0c\u90a3\u6211\u4eec\u5148\u5728\u8fd9\u4e2a \u76ee\u5f55\u91cc\u9762\u627e\uff0c\u627e\u5230\u5bf9\u5e94\u7684\u9875\u7801\u540e\u518d\u53bb\u5bf9\u5e94\u7684\u9875\u7801\u770b\u6587\u7ae0\u3002<\/p>\n<h3>\u805a\u7c07\u7d22\u5f15\u7684\u597d\u5904<\/h3>\n<p>1\u3001\u67e5\u8be2\u901a\u8fc7\u805a\u7c07\u7d22\u5f15\u53ef\u4ee5\u76f4\u63a5\u83b7\u53d6\u6570\u636e\uff0c\u76f8\u6bd4\u975e\u805a\u7c07\u7d22\u5f15\u9700\u8981\u7b2c\u4e8c\u6b21\u67e5\u8be2\uff08\u975e\u8986\u76d6\u7d22\u5f15\u7684\u60c5\u51b5\u4e0b\uff09\u6548\u7387\u8981\u9ad8<\/p>\n<p>2\u3001\u805a\u7c07\u7d22\u5f15\u5bf9\u4e8e\u8303\u56f4\u67e5\u8be2\u7684\u6548\u7387\u5f88\u9ad8\uff0c\u56e0\u4e3a\u5176\u6570\u636e\u662f\u6309\u7167\u5927\u5c0f\u6392\u5217\u7684\uff0c\u4e0d\u7528\u4ece\u591a\u4e2a\u6570\u636e\u5757\u4e2d\u53d6\u6570\u636e\uff0c\u6240\u4ee5\u8282\u7701\u4e86\u5927\u91cf\u7684io\u64cd\u4f5c\u3002<\/p>\n<p>3\u3001\u805a\u7c07\u7d22\u5f15\u9002\u5408\u7528\u5728\u6392\u5e8f\u7684\u573a\u5408\uff0c\u975e\u805a\u7c07\u7d22\u5f15\u4e0d\u9002\u5408.<\/p>\n<h3>\u805a\u7c07\u7d22\u5f15\u7684\u5f0a\u5904<\/h3>\n<p>1\u3001\u5bf9\u4e8eMySQL\u6570\u636e\u5e93\u76ee\u524d\u53ea\u6709<strong>innodb<\/strong>\u6570\u636e\u5f15\u64ce\u652f\u6301\u805a\u7c07\u7d22\u5f15\uff0c\u800cMyisam\u5e76\u4e0d\u652f\u6301\u805a\u7c07\u7d22\u5f15\u3002<\/p>\n<p>2\u3001 \u7531\u4e8e\u6570\u636e\u7269\u7406\u5b58\u50a8\u6392\u5e8f\u65b9\u5f0f\u53ea\u80fd\u6709\u4e00\u79cd\uff0c\u6240\u4ee5\u6bcf\u4e2aMySQL\u7684\u8868\u53ea\u80fd\u6709\u4e00\u4e2a\u805a\u7c07\u7d22\u5f15\u3002<\/p>\n<p>3\u3001\u4e3a\u4e86\u5145\u5206\u5229\u7528\u805a<strong>\u7c07<\/strong>\u7d22\u5f15\u7684\u805a\u7c07\u7684\u7279\u6027\uff0c\u6240\u4ee5innodb\u8868\u7684\u4e3b\u952e\u5217<strong>\u5c3d\u91cf\u9009\u7528\u6709\u5e8f\u7684\u987a\u5e8fid<\/strong>\uff0c\u800c\u4e0d\u5efa\u8bae\u7528\u65e0\u5e8f\u7684id\uff0c\u6bd4\u5982uuid\u8fd9\u79cd\u3002\u3010\u5148\u53bb\u601d\u8003\u4e3a\u4ec0\u4e48\uff1f\uff1f\uff1f\u3011<\/p>\n<h3>\u4e3b\u952e\u7d22\u5f15<\/h3>\n<p>\u8bbe\u5b9a\u4e3a<strong>\u4e3b\u952e\u540e<\/strong>\u6570\u636e\u5e93\u4f1a\u81ea\u52a8\u5efa\u7acb\u7d22\u5f15\uff0c<strong style=\"color:red\">innodb\u9ed8\u8ba4\u8bbe\u5b9a\u4e3a\u805a\u7c07\u7d22\u5f15<\/strong><\/p>\n<p>\u521b\u5efa\u65b9\u5f0f\u4e24\u79cd\uff1a<\/p>\n<p>1\u3001\u5efa\u8868\u7684\u65f6\u5019\u6307\u5b9a<\/p>\n<pre><code class=\"language-sql line-numbers\">CREATE TABLE customer (\n  id INT(10) UNSIGNED  AUTO_INCREMENT ,\n  customer_no VARCHAR(200),\n  customer_name VARCHAR(200),\n  PRIMARY KEY(id) \n);\n<\/code><\/pre>\n<p>2\u3001\u5efa\u8868\u7684\u65f6\u5019\u4e0d\u6307\u5b9a\uff0c\u540e\u9762\u901a\u8fc7\u547d\u4ee4\u4fee\u6539<\/p>\n<pre><code class=\"language-sql line-numbers\">CREATE TABLE customer2 (\n  id INT(10) UNSIGNED   ,\n  customer_no VARCHAR(200),\n  customer_name VARCHAR(200) \n);\n\n#\u5355\u72ec\u5efa\u4e3b\u952e\u7d22\u5f15\uff1a\nALTER TABLE customer2 add PRIMARY KEY customer2(id);  \n\n<\/code><\/pre>\n<p>\u5220\u9664\u4e3b\u952e\u7d22\u5f15<\/p>\n<pre><code class=\"language-sql line-numbers\">ALTER TABLE customer2 drop PRIMARY KEY ; \n<\/code><\/pre>\n<p>\u4fee\u6539\u4e3b\u952e\u7d22\u5f15\uff1a<\/p>\n<p><strong>\u5fc5\u987b\u5148\u5220\u9664\u6389(drop)\u539f\u7d22\u5f15\uff0c\u518d\u65b0\u5efa(add)\u7d22\u5f15<\/strong><\/p>\n<h3>\u552f\u4e00\u7d22\u5f15<\/h3>\n<p><strong style='color:red'>\u7d22\u5f15\u5217\u7684\u503c\u5fc5\u987b\u552f\u4e00<\/strong>\uff0c\u4f46\u5141\u8bb8\u6709\u7a7a\u503c<\/p>\n<p>\u521b\u5efa\u65b9\u5f0f\u4e24\u79cd\uff1a<\/p>\n<p>1\u3001\u5efa\u8868\u7684\u65f6\u5019\u6307\u5b9a<\/p>\n<pre><code class=\"language-sql line-numbers\">CREATE TABLE customer (\n  id INT(10) UNSIGNED  AUTO_INCREMENT ,\n  customer_no VARCHAR(200),\n  customer_name VARCHAR(200),\n  PRIMARY KEY(id),\n  UNIQUE (customer_no)\n);\n<\/code><\/pre>\n<p>2\u3001\u5efa\u8868\u7684\u65f6\u5019\u4e0d\u6307\u5b9a\uff0c\u540e\u9762\u901a\u8fc7\u547d\u4ee4\u4fee\u6539<\/p>\n<pre><code class=\"language-sql line-numbers\">CREATE TABLE customer2 (\n  id INT(10) UNSIGNED  AUTO_INCREMENT ,\n  customer_no VARCHAR(200),\n  customer_name VARCHAR(200),\n  PRIMARY KEY(id)\n);\n#\u5355\u72ec\u5efa\u552f\u4e00\u7d22\u5f15\u3010\u4e24\u79cd\u65b9\u5f0f\u90fd\u53ef\u4ee5\u3011\nCREATE UNIQUE INDEX idx_customer_no ON customer2(customer_no);  \nALTER TABLE customer2 add  UNIQUE   customer2(customer_no);  \n<\/code><\/pre>\n<p>\u5220\u9664\u7d22\u5f15\uff1a<\/p>\n<pre><code class=\"language-sql line-numbers\">DROP INDEX idx_customer_no on customer ;\n<\/code><\/pre>\n<h3>\u666e\u901a\u7d22\u5f15<\/h3>\n<p><strong style=\"color:red\">\u7d22\u5f15\u5217\u7684\u503c\u53ef\u4ee5\u91cd\u590d<\/strong><\/p>\n<p>\u521b\u5efa\u65b9\u5f0f\u4e24\u79cd<\/p>\n<p>1\u3001\u5efa\u7acb\u8868\u7684\u65f6\u5019\u6307\u5b9a<\/p>\n<pre><code class=\"language-sql line-numbers\">CREATE TABLE customer (\n  id INT(10) UNSIGNED  AUTO_INCREMENT ,\n  customer_no VARCHAR(200),\n  customer_name VARCHAR(200),\n  PRIMARY KEY(id),\n  KEY (customer_name)\n);\n<\/code><\/pre>\n<p>2\u3001\u5efa\u8bae\u8868\u7684\u65f6\u5019\u4e0d\u6307\u5b9a\uff0c\u540e\u9762\u901a\u8fc7\u547d\u4ee4\u4fee\u6539<\/p>\n<pre><code class=\"language-sql line-numbers\">CREATE TABLE customer2 (\n  id INT(10) UNSIGNED  AUTO_INCREMENT ,\n  customer_no VARCHAR(200),\n  customer_name VARCHAR(200),\n  PRIMARY KEY(id)\n);\n#\u5355\u72ec\u5efa\u666e\u901a\u7d22\u5f15\u3010\u4e24\u79cd\u65b9\u5f0f\u90fd\u53ef\u4ee5\u3011\nCREATE  INDEX idx_customer_name ON customer2(customer_name);    \nALTER TABLE customer2 add   index  customer2(customer_name);  \n<\/code><\/pre>\n<p>\u5220\u9664\u7d22\u5f15<\/p>\n<pre><code class=\"language-sql line-numbers\">DROP INDEX idx_customer_name on customer ;\n<\/code><\/pre>\n<h3>\u5355\u503c\u7d22\u5f15<\/h3>\n<p><strong style=\"color:red\">\u5373\u4e00\u4e2a\u7d22\u5f15\u53ea\u5305\u542b\u5355\u4e2a\u5217\uff0c\u4e00\u4e2a\u8868\u53ef\u4ee5\u6709\u591a\u4e2a\u5355\u5217\u7d22\u5f15<\/strong><\/p>\n<p>\u6bd4\u5982\u4e0a\u9762\u6240\u521b\u5efa\u7684\u666e\u901a\u7d22\u5f15\u5c31\u662f\u4e00\u4e2a\u5355\u503c\u7d22\u5f15\u7684\u4ee3\u8868<\/p>\n<h3>\u590d\u5408\u7d22\u5f15<\/h3>\n<p><strong style=\"color:red\">\u5373\u4e00\u4e2a\u7d22\u5f15\u5305\u542b\u591a\u4e2a\u5217<\/strong><\/p>\n<p>\u521b\u5efa\u65b9\u5f0f\u4e24\u79cd<\/p>\n<p>1\u3001\u5efa\u7acb\u8868\u7684\u65f6\u5019\u6307\u5b9a<\/p>\n<pre><code class=\"language-sql line-numbers\">CREATE TABLE customer (\n  id INT(10) UNSIGNED  AUTO_INCREMENT ,\n  customer_no VARCHAR(200),\n  customer_name VARCHAR(200),\n  PRIMARY KEY(id),\n  KEY (customer_name),\n  UNIQUE (customer_no),\n  KEY (customer_no,customer_name)\n);\n\n<\/code><\/pre>\n<p>2\u3001\u5efa\u8bae\u8868\u7684\u65f6\u5019\u4e0d\u6307\u5b9a\uff0c\u540e\u9762\u901a\u8fc7\u547d\u4ee4\u4fee\u6539<\/p>\n<pre><code class=\"language-sql line-numbers\">CREATE TABLE customer2 (\n  id INT(10) UNSIGNED  AUTO_INCREMENT ,\n  customer_no VARCHAR(200),\n  customer_name VARCHAR(200),\n  PRIMARY KEY(id),\n    KEY (customer_name),\n  UNIQUE (customer_no)\n);\n\n\u5355\u72ec\u5efa\u7d22\u5f15\uff1a\nCREATE INDEX idx_customer_no_name ON customer(customer_no,customer_name); \n\n<\/code><\/pre>\n<p>\u5220\u9664\u7d22\u5f15<\/p>\n<pre><code class=\"language-sql line-numbers\">DROP INDEX idx_customer_no_name  on customer ;\n<\/code><\/pre>\n<h3>\u57fa\u672c\u7528\u6cd5<\/h3>\n<p>1.\u521b\u5efa\u7d22\u5f15\u3010\u4e24\u79cd\u65b9\u5f0f\u3011<\/p>\n<ol>\n<li><strong>\u65b9\u5f0f\u4e00\uff1a<\/strong><\/li>\n<\/ol>\n<p>\u200b      CREATE [UNIQUE ] INDEX indexName ON mytable(column name)\uff1b<\/p>\n<p>\u200b      2. <strong>\u65b9\u5f0f\u4e8c\uff1a<\/strong><\/p>\n<p>\u200b               ALTER mytable ADD [UNIQUE ] INDEX [indexName](columnname\uff09<\/p>\n<p>\u200b               <strong>\u6dfb\u52a0\u4e3b\u952e\u7d22\u5f15<\/strong>\uff1a<\/p>\n<p>\u200b               ALTER TABLE tbl_name ADD <strong>PRIMARY KEY<\/strong> (column_list)<\/p>\n<p>\u200b               <strong>\u6dfb\u52a0\u552f\u4e00\u7d22\u5f15\uff1a<\/strong><\/p>\n<p>\u200b               ALTER TABLE tbl_name ADD <strong>UNIQUE<\/strong> index_name (column_list)<\/p>\n<p>\u200b               <strong>\u6dfb\u52a0\u666e\u901a\u7d22\u5f15\uff1a<\/strong><\/p>\n<p>\u200b               ALTER TABLE tbl_name ADD <strong>INDEX<\/strong> index_name (column_list)<\/p>\n<p>2.\u5220\u9664\u7d22\u5f15<\/p>\n<p>\u200b               DROP INDEX [indexName] ON mytable;<\/p>\n<p>3.\u67e5\u770b\u7d22\u5f15<\/p>\n<p>\u200b               SHOW INDEX FROM table_name<\/p>\n<h2>\u54ea\u4e9b\u60c5\u51b5\u9700\u8981\u521b\u5efa\u7d22\u5f15<\/h2>\n<ol>\n<li>\u4e3b\u952e\u81ea\u52a8\u5efa\u7acb\u552f\u4e00\u7d22\u5f15<\/li>\n<li>\u9891\u7e41\u4f5c\u4e3a\u67e5\u8be2\u6761\u4ef6\u7684\u5b57\u6bb5\u5e94\u8be5\u521b\u5efa\u7d22\u5f15<\/li>\n<li>\u4e24\u4e2a\u8868\u4e4b\u95f4\u5b58\u5728\u5916\u952e\u5173\u8054\uff0c\u90a3\u8fd9\u4e2a\u5916\u952e\u4e5f\u5e94\u8be5\u5efa\u7acb\u7d22\u5f15<\/li>\n<li>\u5355\u952e\u7d22\u5f15\u4e0e\u7ec4\u5408\u7d22\u5f15\u76f8\u5bf9\u6bd4\uff0c\u7ec4\u5408\u7d22\u5f15\u6027\u4ef7\u6bd4\u66f4\u9ad8<\/li>\n<li>\u67e5\u8be2\u4e2d\u6392\u5e8f\u7684\u5b57\u6bb5\uff0c\u6392\u5e8f\u5b57\u6bb5\u82e5\u901a\u8fc7\u7d22\u5f15\u53bb\u8bbf\u95ee\u5c06\u5927\u5927\u63d0\u9ad8\u6392\u5e8f\u901f\u5ea6<\/li>\n<\/ol>\n<h2>\u54ea\u4e9b\u60c5\u51b5\u4e0d\u8981\u521b\u5efa\u7d22\u5f15<\/h2>\n<ol>\n<li>\u8868\u8bb0\u5f55\u592a\u5c11<\/li>\n<li>\u7ecf\u5e38\u589e\u5220\u6539\u7684\u8868\u6216\u8005\u5b57\u6bb5<\/li>\n<li>Where\u6761\u4ef6\u91cc\u7528\u4e0d\u5230\u7684\u5b57\u6bb5\u4e0d\u521b\u5efa\u7d22\u5f15<\/li>\n<li>\u8fc7\u6ee4\u6027\u4e0d\u597d\u7684\u4e0d\u9002\u5408\u5efa\u7d22\u5f15<\/li>\n<li>\u4e0d\u8981\u5b9a\u4e49\u5197\u4f59\u7d22\u5f15<\/li>\n<\/ol>\n<blockquote><p>\n  \u9488\u5bf9\u4e8e\u7b2c\u4e94\u6761\uff1a<\/p>\n<p>  <strong>\u7d22\u5f15\u7684\u9009\u62e9\u6027<\/strong>\u662f\u6307\u7d22\u5f15\u5217\u4e2d\u4e0d\u540c\u503c\u7684\u6570\u76ee\u548c\u8868\u7684\u8bb0\u5f55\u6570\u7684\u6bd4\u503c\u3002\u5047\u5982\u8868\u91cc\u9762\u67091000\u6761\u6570\u636e\uff0c\u8868\u7d22\u5f15\u5217\u6709980\u4e2a\u4e0d\u540c\u7684\u503c\uff0c\u8fd9\u65f6\u5019\u7d22\u5f15\u7684\u9009\u62e9\u6027\u5c31\u662f980\/1000=0.98 \u3002\u7d22\u5f15\u7684\u9009\u62e9\u6027\u8d8a\u63a5\u8fd11\uff0c\u8fd9\u4e2a\u7d22\u5f15\u7684\u6548\u7387\u5f88\u9ad8\u3002<\/p>\n<p>  \u6027\u522b\u53ef\u4ee5\u8ba4\u4e3a\u662f3\u79cd\uff0c\u7537\uff0c\u5973\uff0c\u5176\u4ed6\u3002\u5982\u679c\u521b\u5efa\u7d22\u5f15\uff0c\u67e5\u8be2\u8bed\u53e5 \u6027\u522b=\u2018\u7537&#8217;\u7684\u6570\u636e\uff0c\u7d22\u5f15\u7684\u9009\u62e9\u6027\u5c31\u662f3\/1000=0.003\u3002\u7d22\u5f15\u7684\u9009\u62e9\u6027\u503c\u5f88\u4f4e\uff0c\u5bf9\u67e5\u8be2\u63d0\u5347\u4e0d\u5927\uff0c\u6240\u4ee5\u6027\u522b\u5efa\u7d22\u5f15\u610f\u4e49\u4e0d\u5927\u3002\n<\/p><\/blockquote>\n","protected":false},"excerpt":{"rendered":"<p>\u6570\u636e\u672c\u8eab\u4e4b\u5916\uff0c\u6570\u636e\u5e93\u8fd8\u7ef4\u62a4\u7740\u4e00\u4e2a&#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":1022,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[24],"tags":[],"class_list":["post-1024","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-24"],"_links":{"self":[{"href":"http:\/\/www.licaneku.fun\/index.php?rest_route=\/wp\/v2\/posts\/1024","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.licaneku.fun\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.licaneku.fun\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.licaneku.fun\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.licaneku.fun\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1024"}],"version-history":[{"count":1,"href":"http:\/\/www.licaneku.fun\/index.php?rest_route=\/wp\/v2\/posts\/1024\/revisions"}],"predecessor-version":[{"id":1025,"href":"http:\/\/www.licaneku.fun\/index.php?rest_route=\/wp\/v2\/posts\/1024\/revisions\/1025"}],"wp:featuredmedia":[{"embeddable":true,"href":"http:\/\/www.licaneku.fun\/index.php?rest_route=\/wp\/v2\/media\/1022"}],"wp:attachment":[{"href":"http:\/\/www.licaneku.fun\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1024"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.licaneku.fun\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1024"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.licaneku.fun\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1024"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}