{"id":5,"date":"2009-01-23T16:28:19","date_gmt":"2009-01-23T08:28:19","guid":{"rendered":"http:\/\/www.magki.com\/blog\/?p=5"},"modified":"2009-01-23T16:30:41","modified_gmt":"2009-01-23T08:30:41","slug":"mysql-type-and-length-of-the-field","status":"publish","type":"post","link":"http:\/\/www.ijony.com\/blog\/2009\/01\/mysql-type-and-length-of-the-field.html","title":{"rendered":"MySQL \u7684\u5b57\u6bb5\u7c7b\u578b\u53ca\u957f\u5ea6"},"content":{"rendered":"<h4>\u6570\u503c\u7c7b\u578b<\/h4>\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<th style=\"text-align: left\">\u5217\u7c7b\u578b<\/th>\n<th style=\"text-align: left\">\u9700\u8981\u7684\u5b58\u50a8\u91cf<\/th>\n<\/tr>\n<tr>\n<td>TINYINT<\/td>\n<td>1 \u5b57\u8282<\/td>\n<\/tr>\n<tr>\n<td>SMALLINT<\/td>\n<td>2 \u5b57\u8282<\/td>\n<\/tr>\n<tr>\n<td>MEDIUMINT<\/td>\n<td>3 \u5b57\u8282<\/td>\n<\/tr>\n<tr>\n<td>INT<\/td>\n<td>4 \u5b57\u8282<\/td>\n<\/tr>\n<tr>\n<td>INTEGER<\/td>\n<td>4 \u5b57\u8282<\/td>\n<\/tr>\n<tr>\n<td>BIGINT<\/td>\n<td>8 \u5b57\u8282<\/td>\n<\/tr>\n<tr>\n<td>FLOAT(X)<\/td>\n<td>4 \u5b57\u8282\uff08\u5982\u679c X &lt; = 24 \u6216 8 \u5982\u679c 25 &lt; = X &lt; = 53\uff09<\/td>\n<\/tr>\n<tr>\n<td>FLOAT<\/td>\n<td>4 \u5b57\u8282<\/td>\n<\/tr>\n<tr>\n<td>DOUBLE<\/td>\n<td>8 \u5b57\u8282<\/td>\n<\/tr>\n<tr>\n<td>DOUBLE PRECISION<\/td>\n<td>8 \u5b57\u8282<\/td>\n<\/tr>\n<tr>\n<td>REAL<\/td>\n<td>8 \u5b57\u8282<\/td>\n<\/tr>\n<tr>\n<td>DECIMAL(M,D)<\/td>\n<td>M \u5b57\u8282 \uff08D+2 , \u5982\u679cM &lt; D\uff09<\/td>\n<\/tr>\n<tr>\n<td>NUMERIC(M,D)<\/td>\n<td>M \u5b57\u8282 \uff08D+2 , \u5982\u679cM &lt; D\uff09<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><!--more--><\/p>\n<h4>\u65e5\u671f\u548c\u65f6\u95f4\u7c7b\u578b<\/h4>\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<th style=\"text-align: left\">\u5217\u7c7b\u578b<\/th>\n<th style=\"text-align: left\">\u9700\u8981\u7684\u5b58\u50a8\u91cf<\/th>\n<\/tr>\n<tr>\n<td>DATE<\/td>\n<td>3 \u5b57\u8282<\/td>\n<\/tr>\n<tr>\n<td>DATETIME<\/td>\n<td>8 \u5b57\u8282<\/td>\n<\/tr>\n<tr>\n<td>TIMESTAMP<\/td>\n<td>4 \u5b57\u8282<\/td>\n<\/tr>\n<tr>\n<td>TIME<\/td>\n<td>3 \u5b57\u8282<\/td>\n<\/tr>\n<tr>\n<td>YEAR<\/td>\n<td>1 \u5b57\u8282<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h4><\/h4>\n<h4>\u4e32\u7c7b\u578b<\/h4>\n<table border=\"0\" cellspacing=\"0\" cellpadding=\"0\">\n<tbody>\n<tr>\n<th style=\"text-align: left\">\u5217\u7c7b\u578b<\/th>\n<th style=\"text-align: left\">\u9700\u8981\u7684\u5b58\u50a8\u91cf<\/th>\n<\/tr>\n<tr>\n<td>CHAR(M)<\/td>\n<td>M \u5b57\u8282\uff0c1 &lt;= M &lt;= 255<\/td>\n<\/tr>\n<tr>\n<td>VARCHAR(M)<\/td>\n<td>L+1 \u5b57\u8282, \u5728\u6b64 L &lt;= M \u548c 1 &lt;= M &lt;= 255<\/td>\n<\/tr>\n<tr>\n<td>TINYBLOB, TINYTEXT<\/td>\n<td>L+1 \u5b57\u8282, \u5728\u6b64 L &lt; 2 ^ 8<\/td>\n<\/tr>\n<tr>\n<td>BLOB, TEXT<\/td>\n<td>L+2 \u5b57\u8282, \u5728\u6b64 L &lt; 2 ^ 16<\/td>\n<\/tr>\n<tr>\n<td>MEDIUMBLOB, MEDIUMTEXT<\/td>\n<td>L+3 \u5b57\u8282, \u5728\u6b64 L &lt; 2 ^ 24<\/td>\n<\/tr>\n<tr>\n<td>LONGBLOB, LONGTEXT<\/td>\n<td>L+4 \u5b57\u8282, \u5728\u6b64 L &lt; 2 ^ 32<\/td>\n<\/tr>\n<tr>\n<td>ENUM(&#8216;value1&#8242;,&#8217;value2&#8217;,&#8230;)<\/td>\n<td>1 \u6216 2 \u4e2a\u5b57\u8282, \u53d6\u51b3\u4e8e\u679a\u4e3e\u503c\u7684\u6570\u76ee\uff08\u6700\u5927\u503c65535\uff09<\/td>\n<\/tr>\n<tr>\n<td>SET(&#8216;value1&#8242;,&#8217;value2&#8217;,&#8230;)<\/td>\n<td>1\uff0c2\uff0c3\uff0c4\u62168\u4e2a\u5b57\u8282, \u53d6\u51b3\u4e8e\u96c6\u5408\u6210\u5458\u7684\u6570\u91cf\uff08\u6700\u591a64\u4e2a\u6210\u5458\uff09<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><strong>\u9644\uff1aMySQL \u6570\u636e\u8868\u7c7b\u578b\u8bf4\u660e <\/strong><\/p>\n<p><strong>1. MyISAM \u8868<\/strong> MyISAM \u5b58\u50a8\u683c\u5f0f\u81ea\u7248\u672c3.23 \u4ee5\u6765\u662f MySQL \u4e2d\u7684\u7f3a\u7701\u7c7b\u578b\uff0c\u5b83\u6709\u4e0b\u5217\u7279\u70b9\uff1a<br \/>\n\u25a0 \u5982\u679c\u64cd\u4f5c\u7cfb\u7edf\u81ea\u8eab\u5141\u8bb8\u66f4\u5927\u7684\u6587\u4ef6\uff0c\u90a3\u4e48\u6587\u4ef6\u6bd4 ISAM \u5b58\u50a8\u65b9\u6cd5\u7684\u5927\u3002<br \/>\n\u25a0 \u6570\u636e\u4ee5\u4f4e\u5b57\u8282\u4f18\u5148\u7684\u673a\u5668\u72ec\u7acb\u683c\u5f0f\u5b58\u50a8\u3002\u8fd9\u8868\u793a\u53ef\u5c06\u8868\u4ece\u4e00\u79cd\u673a\u5668\u62f7\u8d1d\u5230\u53e6\u4e00\u79cd\u673a\u5668\uff0c\u5373\u4f7f\u5b83\u4eec\u7684\u4f53\u7cfb\u7ed3\u6784\u4e0d\u540c\u4e5f\u53ef\u4ee5\u62f7\u8d1d\u3002<br \/>\n\u25a0 \u6570\u503c\u7d22\u5f15\u503c\u5360\u7684\u5b58\u50a8\u7a7a\u95f4\u8f83\u5c11\uff0c\u56e0\u4e3a\u5b83\u4eec\u662f\u6309\u9ad8\u5b57\u8282\u4f18\u5148\u5b58\u50a8\u7684\u3002\u7d22\u5f15\u503c\u5728\u4f4e\u4f4d\u5b57\u8282\u4e2d\u53d8\u5316\u5f88\u5feb\uff0c\u56e0\u6b64\u9ad8\u4f4d\u5b57\u8282\u66f4\u5bb9\u6613\u6bd4\u8f83\u3002<br \/>\n\u25a0 AUTO_INCREMENT \u5904\u7406\u6bd4 ISAM \u7684\u8868\u66f4\u597d\u3002<br \/>\n\u25a0 \u51cf\u5c11\u4e86\u51e0\u4e2a\u7d22\u5f15\u9650\u5236\u3002\u4f8b\u5982\uff0c\u53ef\u5bf9\u542b NULL \u503c\u7684\u5217\u8fdb\u884c\u7d22\u5f15\uff0c\u8fd8\u53ef\u4ee5\u5bf9 BLOB \u548c TEXT \u7c7b\u578b\u7684\u5217\u8fdb\u884c\u7d22\u5f15\u3002<br \/>\n\u25a0 \u4e3a\u4e86\u6539\u5584\u8868\u7684\u5b8c\u6574\u6027\u68c0\u67e5\uff0c\u6bcf\u4e2a\u8868\u90fd\u5177\u6709\u4e00\u4e2a\u6807\u5fd7\uff0c\u5728 myisamchk \u5bf9\u8868\u8fdb\u884c\u8fc7\u68c0\u67e5\u540e\uff0c\u8bbe\u7f6e\u8be5\u6807\u5fd7\u3002\u53ef\u5229\u7528 myisamchk &#8211; fast \u8df3\u8fc7\u5bf9\u81ea\u524d\u6b21\u68c0\u67e5\u4ee5\u6765\u5c1a\u672a\u88ab\u4fee\u6539\u8fc7\u8868\u7684\u68c0\u67e5\uff0c\u8fd9\u6837\u4f7f\u6b64\u7ba1\u7406\u4efb\u52a1\u66f4\u5feb\u3002\u8868\u4e2d\u8fd8\u6709\u4e00\u4e2a\u6307\u793a\u8868\u662f\u5426\u6b63\u5e38\u5173\u95ed\u7684\u6807\u5fd7\u3002\u5982\u679c\u670d\u52a1\u5668\u5173\u95ed\u4e0d\u6b63\u5e38\uff0c\u6216\u673a\u5668\u5d29\u6e83\uff0c\u6b64\u6807\u5fd7\u53ef\u7528\u6765\u68c0\u6d4b\u51fa\u670d\u52a1\u5668\u8d77\u52a8\u65f6\u9700\u8981\u68c0\u67e5\u7684\u8868\u3002<\/p>\n<p><strong>2.  ISAM \u8868<\/strong> ISAM \u5b58\u50a8\u683c\u5f0f\u662f MySQL3.23 \u6240\u7528\u7684\u6700\u65e7\u7684\u683c\u5f0f\uff0c\u4f46\u5f53\u524d\u4ecd\u7136\u53ef\u7528\u3002\u901a\u5e38\uff0c\u76f8\u5bf9\u4e8e ISAM \u8868\u6765\u8bf4\uff0c\u5b81\u53ef\u4f7f\u7528 MyISAM \u8868\uff0c\u56e0\u4e3a\u5b83\u4eec\u7684\u9650\u5236\u8f83\u5c11\u3002\u5bf9 ISAM \u8868\u7684\u652f\u6301\u968f\u7740\u6b64\u5b58\u50a8\u683c\u5f0f\u88ab MyISAM \u8868\u683c\u5f0f\u6240\u652f\u6301\u5f88\u6709\u53ef\u80fd\u4f1a\u9010\u6e10\u6d88\u5931\u3002<\/p>\n<p><strong>3.  HEAP \u8868<\/strong> HEAP \u5b58\u50a8\u683c\u5f0f\u5efa\u7acb\u5229\u7528\u5b9a\u957f\u884c\u7684\u5185\u5b58\u4e2d\u7684\u8868\uff0c\u8fd9\u4f7f\u8868\u8fd0\u884c\u5f97\u975e\u5e38\u5feb\u3002\u5728\u670d\u52a1\u5668\u505c\u6b62\u65f6\uff0c\u5b83\u4eec\u5c06\u4f1a\u6d88\u5931\u3002\u5728\u8fd9\u79cd\u610f\u4e49\u4e0a\uff0c\u8fd9\u4e9b\u8868\u662f\u4e34\u65f6\u7684\u3002\u4f46\u662f\uff0c\u4e0e\u7528 CREATE TEMPORARY TABLE \u6240\u521b\u5efa\u7684\u4e34\u65f6\u8868\u76f8\u6bd4\uff0cHEAP \u8868\u662f\u5176\u4ed6\u5ba2\u6237\u673a\u53ef\u89c1\u7684\u3002HEAP \u8868\u6709\u51e0\u4e2a\u9650\u5236\uff0c\u8fd9\u4e9b\u9650\u5236\u5bf9 MyISAM \u6216 ISAM \u8868\u6ca1\u6709\uff0c\u5982\u4e0b\u6240\u793a\uff1a<br \/>\n\u25a0 \u7d22\u5f15\u4ec5\u7528\u4e8e\u201c=\u201d\u548c\u201c&lt; = &gt;\u201d\u6bd4\u8f83\u3002<br \/>\n\u25a0 \u7d22\u5f15\u5217\u4e2d\u4e0d\u80fd\u6709 NULL \u503c\u3002<br \/>\n\u25a0 \u4e0d\u80fd\u4f7f\u7528 BLOB \u548c TEXT \u5217\u3002<br \/>\n\u25a0 \u4e0d\u80fd\u4f7f\u7528 AUTO_INCREMENT \u5217\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u6570\u503c\u7c7b\u578b \u5217\u7c7b\u578b \u9700\u8981\u7684\u5b58\u50a8\u91cf TINYINT 1 \u5b57\u8282 SMALLINT 2 \u5b57\u8282 MEDIUMINT 3  [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[4],"tags":[11],"_links":{"self":[{"href":"http:\/\/www.ijony.com\/blog\/wp-json\/wp\/v2\/posts\/5"}],"collection":[{"href":"http:\/\/www.ijony.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.ijony.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.ijony.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.ijony.com\/blog\/wp-json\/wp\/v2\/comments?post=5"}],"version-history":[{"count":0,"href":"http:\/\/www.ijony.com\/blog\/wp-json\/wp\/v2\/posts\/5\/revisions"}],"wp:attachment":[{"href":"http:\/\/www.ijony.com\/blog\/wp-json\/wp\/v2\/media?parent=5"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.ijony.com\/blog\/wp-json\/wp\/v2\/categories?post=5"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.ijony.com\/blog\/wp-json\/wp\/v2\/tags?post=5"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}