{"id":128,"date":"2022-02-23T16:10:37","date_gmt":"2022-02-23T08:10:37","guid":{"rendered":"https:\/\/blog.zjia.me\/?p=128"},"modified":"2026-06-19T17:28:55","modified_gmt":"2026-06-19T09:28:55","slug":"mysql%e7%9a%84%e5%ad%97%e6%ae%b5%e9%95%bf%e5%ba%a6","status":"publish","type":"post","link":"https:\/\/blog.ttwow.top\/?p=128","title":{"rendered":"Mysql\u7684\u5b57\u6bb5\u957f\u5ea6"},"content":{"rendered":"<h2>varchar(n)\uff0cn\u8868\u793a\u4ec0\u4e48\uff1f<br \/>\nMySQL5.0.3\u4e4b\u524dvarchar(n)\u8fd9\u91cc\u7684n\u8868\u793a\u5b57\u8282\u6570<br \/>\nMySQL5.0.3\u4e4b\u540evarchar(n)\u8fd9\u91cc\u7684n\u8868\u793a\u5b57\u7b26\u6570\uff0c\u6bd4\u5982varchar\uff08200\uff09\uff0c\u4e0d\u7ba1\u662f\u82f1\u6587\u8fd8\u662f\u4e2d\u6587\u90fd\u53ef\u4ee5\u5b58\u653e200\u4e2a<\/h2>\n<h2>\u53c2\u8003\uff1a<a href=\"https:\/\/blog.csdn.net\/zgdwxp\/article\/details\/90675967\">https:\/\/blog.csdn.net\/zgdwxp\/article\/details\/90675967<\/a><\/h2>\n<h2>CHAR\u548cVARCHAR<\/h2>\n<h2>CHAR(4)\uff0c\u6700\u591a\u5b58\u50a84\u4e2a\u5b57\u7b26\uff0c\u4e0d\u8db34\u4e2a\u5c3e\u90e8\u7528\u7a7a\u683c\u586b\u6ee1\u3002\u5b58\u50a8\u5b57\u8282\u6570 = \u6570\u636e\u503c\u7684\u5b57\u8282\u548c + \u8865\u4f4d\u7a7a\u683c\u6570<br \/>\nVARCHAR(4)\uff0c\u6700\u591a\u5b58\u50a84\u4e2a\u5b57\u7b26\uff0c\u6709\u51e0\u4e2a\u5b57\u7b26\u5b58\u50a8\u51e0\u4e2a\u3002\u5b58\u50a8\u5b57\u8282\u6570 = \u6570\u636e\u503c\u7684\u5b57\u8282\u548c + 1\u5b57\u8282\uff08\u957f\u5ea6\u6807\u8bc6\uff09<\/h2>\n<h2>\u6574\u6570\u7c7b\u578b<\/h2>\n<p>\u6574\u6570\u662f\u5b9a\u957f\u7c7b\u578b\uff0c\u957f\u5ea6\u4e3a\u5b57\u8282\u6570<br \/>\n\u5e38\u89c1\u7684INT(4)\u53ea\u662f\u8bbe\u7f6e\u4e86\u663e\u793a\u5bbd\u5ea6\uff0c\u4e0d\u5f71\u54cd\u5b58\u50a8\u957f\u5ea6\u3002<br \/>\n\u5373\u4e0d\u7ba1TINYINT(1) TINYINT(2) TINYINT(3)TINYINT(4)<br \/>\n\u53ef\u4ee5\u63d2\u5165\u8868\u7684\u90fd\u662f-128-127\u7684\u6b63\u6574\u6570<\/p>\n<\/p>\n<hr \/>\n<h2>tinyint(1) \u548c tinyint(4) \u4e2d\u76841\u548c4\u5e76\u4e0d\u8868\u793a\u5b58\u50a8\u957f\u5ea6\uff0c\u53ea\u6709\u5b57\u6bb5\u6307\u5b9azerofill\u662f\u6709\u7528\uff0c<br \/>\n\u5982tinyint(4)\uff0c\u5982\u679c\u5b9e\u9645\u503c\u662f2\uff0c\u5982\u679c\u5217\u6307\u5b9a\u4e86zerofill\uff0c\u67e5\u8be2\u7ed3\u679c\u5c31\u662f0002\uff0c\u5de6\u8fb9\u75280\u6765\u586b\u5145\u3002<br \/>\n\u6ce8\u89e3\uff1a\u4e5f\u5c31\u662f\u8bf4\u53ea\u6709\u8981\u6c42\u7f16\u7801\u7b49\u7279\u6b8a\u683c\u5f0f\u5b57\u6bb5\u91c7\u7528zerofill<br \/>\n\u6ce8\u89e3\uff1a\u6709\u53ef\u80fd\u5b58\u50a8\u5927\u4e8e\u6700\u5927\u503c\u65f6\u5019\u4e0d\u62a5\u9519\uff0c\u4f46\u662f\u4e00\u5b9a\u662f\u62a5\u8b66\u544a<\/h2>\n<p>-\u65e0\u7b26\u53f7\u7684\uff08unsigned\uff09<br \/>\n-\u6709\u7b26\u53f7\u7684\uff08signed\uff09<\/p>\n<table>\n<thead>\n<tr>\n<th>\u7c7b\u578b<\/th>\n<th>\u5bb9\u91cf(Bytes)<\/th>\n<th>\u6700\u5c0f(signed)<\/th>\n<th>\u6700\u5927(signed)<\/th>\n<th>unsigned\u8303\u56f4<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>TINYINT<\/td>\n<td>1<\/td>\n<td>-128<\/td>\n<td>127<\/td>\n<td>0~255<\/td>\n<\/tr>\n<tr>\n<td>SMALLINT<\/td>\n<td>2<\/td>\n<td>-32768<\/td>\n<td>32767<\/td>\n<td>0~65,535<\/td>\n<\/tr>\n<tr>\n<td>MEDIUMINT<\/td>\n<td>3<\/td>\n<td>-8388608<\/td>\n<td>8388607<\/td>\n<td>0~16777215<\/td>\n<\/tr>\n<tr>\n<td>INT<\/td>\n<td>4<\/td>\n<td>-2147483648<\/td>\n<td>-2147483648<\/td>\n<td>0~4294967295<\/td>\n<\/tr>\n<tr>\n<td>BIGINT<\/td>\n<td>8<\/td>\n<td>-2<sup>63<\/sup> =9223372036854775808<\/td>\n<td>2<sup>63<\/sup>-1 =9223372036854775807<\/td>\n<td>0~18446744073709551615<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>\u65e5\u671f\u4e0e\u65f6\u95f4<\/h2>\n<table>\n<thead>\n<tr>\n<th><\/th>\n<th>\u63cf\u8ff0<\/th>\n<th>\u663e\u793a\u683c\u5f0f<\/th>\n<th>\u53d6\u503c\u8303\u56f4<\/th>\n<\/tr>\n<\/thead>\n<tbody>\n<tr>\n<td>YEAR<\/td>\n<td>\u5e74<\/td>\n<td>YYYY<\/td>\n<td>0000\u30011901~2155<\/td>\n<\/tr>\n<tr>\n<td>DATE<\/td>\n<td>\u6709\u65e5\u671f\u3001\u6ca1\u6709\u65f6\u95f4<\/td>\n<td>YYYY-MM-DD<\/td>\n<td>1000-01-01 ~ 9999-12-31<\/td>\n<\/tr>\n<tr>\n<td>TIME<\/td>\n<td>\u65f6\u5206\u79d2<\/td>\n<td>hh:mm:ss<\/td>\n<td>-838:59:59 ~ 838:59:597<\/td>\n<\/tr>\n<tr>\n<td>DATETIME<\/td>\n<td>\u5305\u542b\u65e5\u671f\u548c\u65f6\u95f4<\/td>\n<td>YYYY-MM-DD hh:mm:ss<\/td>\n<td>1000-01-01 00:00:00 ~ 9999-12-31 23:59:59<\/td>\n<\/tr>\n<tr>\n<td>TIMESTAMP<\/td>\n<td>\u5305\u542b\u65e5\u671f\u548c\u65f6\u95f4<\/td>\n<td>YYYY-MM-DD hh:mm:ss<\/td>\n<td>1970-01-01T00:00:01Z ~ 2038-01-19T03:14:07Z<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<h2>\u65f6\u95f4\u7c7b\u578b\u5c0f\u7ed3<\/h2>\n<p>\u65e5\u5e38\u4f7f\u7528\u4e2d\uff0c\u65f6\u95f4\u7c7b\u578b\u7684\u9009\u62e9\u662f\u4e00\u4e2a\u6bd4\u8f83\u5934\u75bc\u7684\u95ee\u9898\uff0c\u6709\u63d0\u5021DATETIME\u6216TIMESTAMP\uff0c\u6709\u53d7TIMESTAMP\u542f\u53d1\u3001\u5efa\u8bae\u76f4\u63a5\u5b58\u50a8INT\u6216BIGINT\u7684\u3002<br \/>\n\u6211\u4eec\u4ece\u4e0b\u9762\u51e0\u4e2a\u7ef4\u5ea6\u6bd4\u8f83\uff1a<\/p>\n<p>\u53d6\u503c\u8303\u56f4\uff1aDATETIME &gt; TIMESTAMP = INT<br \/>\n\u65f6\u95f4\u7cbe\u5ea6\uff1aDATETIME = TIMESTAMP &gt; INT<br \/>\n\u5b58\u50a8\u5f00\u9500\uff08\u540c\u7b49\u7cbe\u5ea6\uff09\uff1aDATETIME &gt; TIMESTAMP = INT<br \/>\n\u53ef\u81ea\u52a8\u66f4\u65b0\uff1aDATETIME\u548cTIMESTAMP\u652f\u6301ON UPDATE\uff0cINT\u4e0d\u652f\u6301<br \/>\n\u67e5\u8be2\u6027\u80fd\uff1a\u56e0\u4e3a\u5e95\u5c42\u90fd\u662f\u8f6c\u6362\u4e3a\u6574\u6570\u5b58\u50a8\uff0c\u4e0d\u8003\u8651\u5b58\u50a8\u7a7a\u95f4\u4f18\u5316\uff0c\u51e0\u79cd\u7c7b\u578b\u6027\u80fd\u51e0\u4e4e\u76f8\u540c\u3002<br \/>\n\u5982\u679c\u4e0d\u8003\u8651\u5b58\u50a8\u3001\u5bf9\u7ec6\u5fae\u7684\u6027\u80fd\u611f\u53d7\u4e0d\u5927\u3001\u5bf9\u65f6\u95f4\u8303\u56f4\u8981\u6c42\u8f83\u9ad8\uff0c\u5efa\u8bae\u9009\u62e9DATETIME\uff1b<br \/>\n\u5982\u679c\u8003\u8651\u5b58\u50a8\u3001\u4e14\u5bf9\u65f6\u95f4\u8303\u56f4\u8981\u6c42\u4e0d\u9ad8\uff0c\u5efa\u8bae\u9009\u62e9TIMESTAMP\u3002<br \/>\nINT\u7684\u4ee3\u7801\u5904\u7406\u6210\u672c\u8f83\u9ad8\uff0c\u4e0d\u5efa\u8bae\uff1bBIGINT\u867d\u7136\u53ef\u4ee5\u89e3\u51b3UNIX 2038\u95ee\u9898\uff0c\u4f46\u4ee3\u7801\u5904\u7406\u6210\u672c\u9ad8\uff0c\u800c\u4e14\u76f8\u4fe1MySQL\u672a\u6765\u4f1a\u63d0\u4f9b\u6807\u51c6\u89e3\u51b3\u65b9\u6848<\/p>\n","protected":false},"excerpt":{"rendered":"<p>varchar(n)\uff0cn\u8868\u793a\u4ec0\u4e48\uff1f MySQL5.0.3\u4e4b\u524dvarchar(n)\u8fd9\u91cc\u7684n\u8868\u793a\u5b57\u8282\u6570 MySQL [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[136],"tags":[58],"class_list":["post-128","post","type-post","status-publish","format-standard","hentry","category-notes-misc","tag-mysql"],"_links":{"self":[{"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=\/wp\/v2\/posts\/128","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=128"}],"version-history":[{"count":1,"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=\/wp\/v2\/posts\/128\/revisions"}],"predecessor-version":[{"id":1993,"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=\/wp\/v2\/posts\/128\/revisions\/1993"}],"wp:attachment":[{"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=128"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=128"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.ttwow.top\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=128"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}