{"id":293,"date":"2022-06-12T10:49:37","date_gmt":"2022-06-12T02:49:37","guid":{"rendered":"https:\/\/frogvps.com\/?p=293"},"modified":"2022-06-12T10:49:37","modified_gmt":"2022-06-12T02:49:37","slug":"mysql%e7%9a%84%e6%95%b0%e6%8d%ae%e7%b1%bb%e5%9e%8b%e4%bb%8b%e7%bb%8d","status":"publish","type":"post","link":"https:\/\/frogvps.com\/?p=293","title":{"rendered":"MYSQL\u7684\u6570\u636e\u7c7b\u578b\u4ecb\u7ecd"},"content":{"rendered":"\n<p>MYSQL\u5728\u521b\u5efa\u8868\u7684\u65f6\u5019\u901a\u5e38\u9700\u8981\u6307\u5b9a\u5b57\u6bb5\u7684\u6570\u636e\u7c7b\u578b\uff0c\u7528\u4e8e\u5b58\u653e\u6570\u636e\u3002\u6570\u636e\u7c7b\u578b\u5927\u81f4\u5206\u4e3a\uff0c\u6570\u503c\u578b\u3001\u5b57\u7b26\u578b\u548c\u65f6\u95f4\u65e5\u671f\u578b\u3002<\/p>\n\n\n\n<p>\u9009\u62e9\u6b63\u786e\u7684\u6570\u636e\u7c7b\u578b\u5bf9\u4e8e\u83b7\u5f97\u9ad8\u6027\u80fd\u81f3\u5173\u91cd\u8981\uff1a<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>\u66f4\u5c0f\u7684\u901a\u5e38\u66f4\u597d\uff0c\u5c3d\u91cf\u4f7f\u7528\u53ef\u6b63\u786e\u5b58\u50a8\u6570\u636e\u7684\u6700\u5c0f\u6570\u636e\u7c7b\u578b<\/li><li>\u7b80\u5355\u5c31\u597d\uff0c\u7b80\u5355\u6570\u636e\u7c7b\u578b\u7684\u64cd\u4f5c\u901a\u5e38\u9700\u8981\u66f4\u5c11\u7684CPU\u5468\u671f<\/li><li>\u5c3d\u91cf\u907f\u514dNULL\uff0c\u5305\u542b\u4e3aNULL\u7684\u5217\uff0c\u5bf9MySQL\u66f4\u96be\u4f18\u5316<\/li><\/ol>\n\n\n\n<h2 class=\"wp-block-heading\">\u6574\u6570\u578b<\/h2>\n\n\n\n<p>tinyint(m) 1\u4e2a\u5b57\u8282 \u8303\u56f4(-128~127)<br>smallint(m) 2\u4e2a\u5b57\u8282 \u8303\u56f4(-32768~32767)<br>mediumint(m) 3\u4e2a\u5b57\u8282 \u8303\u56f4(-8388608~8388607)<br>int(m) 4\u4e2a\u5b57\u8282 \u8303\u56f4(-2147483648~2147483647)<br>bigint(m) 8\u4e2a\u5b57\u8282 \u8303\u56f4(+-9.22*10\u768418\u6b21\u65b9)<\/p>\n\n\n\n<p>\u4e0a\u8ff0\u6570\u636e\u7c7b\u578b\uff0c\u5982\u679c\u52a0\u4fee\u9970\u7b26unsigned\u540e\uff0c\u5219\u6700\u5927\u503c\u7ffb\u500d\u3002\u4f8b\u5982\uff1atinyint unsigned\u7684\u53d6\u503c\u8303\u56f4\u4e3a(0~255)<\/p>\n\n\n\n<p>int(m)\u91cc\u7684m\u662f\u8868\u793aSELECT\u67e5\u8be2\u7ed3\u679c\u96c6\u4e2d\u7684\u663e\u793a\u5bbd\u5ea6\uff0c\u5e76\u4e0d\u5f71\u54cd\u5b9e\u9645\u7684\u53d6\u503c\u8303\u56f4\uff0c\u89c4\u5b9a\u4e86MySQL\u7684\u4e00\u4e9b<br>\u4ea4\u4e92\u5de5\u5177\uff08\u4f8b\u5982MySQL\u547d\u4ee4\u884c\u5ba2\u6237\u7aef\uff09\u7528\u6765\u663e\u793a\u5b57\u7b26\u7684\u4e2a\u6570\u3002\u5bf9\u4e8e\u5b58\u50a8\u548c\u8ba1\u7b97\u6765\u8bf4\uff0cInt(1)\u548cInt(20)\u662f\u76f8\u540c\u7684\u3002<\/p>\n\n\n\n<p>BOOL\uff0cBOOLEAN\uff1a\u5e03\u5c14\u578b\uff0c\u662fTINYINT(1)\u7684\u540c\u4e49\u8bcd\u3002zero\u503c\u88ab\u89c6\u4e3a\u5047\uff0c\u975ezero\u503c\u89c6\u4e3a\u771f\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u6d6e\u70b9\u578b<\/h2>\n\n\n\n<p>\u5b58\u653e\u7684\u8fd1\u4f3c\u503c\u3002<\/p>\n\n\n\n<p>float(m,d) \u5355\u7cbe\u5ea6\u6d6e\u70b9\u578b 8\u4f4d\u7cbe\u5ea6(4\u5b57\u8282) m\u603b\u4e2a\u6570\uff0cd\u5c0f\u6570\u4f4d<br>double(m,d) \u53cc\u7cbe\u5ea6\u6d6e\u70b9\u578b16\u4f4d\u7cbe\u5ea6(8\u5b57\u8282) m\u603b\u4e2a\u6570\uff0cd\u5c0f\u6570\u4f4d<\/p>\n\n\n\n<p>\u6ce8\u610f: \u5c0f\u6570\u70b9\u4e0d\u5360\u7528\u603b\u4e2a\u6570<\/p>\n\n\n\n<p>\u5047\u8bbe\u4e00\u4e2a\u5b57\u6bb5\u5b9a\u4e49\u4e3afloat(6,3)\uff0c\u5982\u679c\u63d2\u5165\u4e00\u4e2a\u6570123.45678,\u5b9e\u9645\u6570\u636e\u5e93\u91cc\u5b58\u7684\u662f123.457\uff0c\u4f46\u603b\u4e2a\u6570\u8fd8\u4ee5\u5b9e\u9645\u4e3a\u51c6\uff0c\u53736\u4f4d\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5b9a\u70b9\u6570<\/h2>\n\n\n\n<p>\u5728\u6570\u636e\u5e93\u4e2d\u5b58\u653e\u7684\u662f\u7cbe\u786e\u503c,\u5b58\u4e3a\u5341\u8fdb\u5236\u3002<\/p>\n\n\n\n<p>decimal(m,d) \u8868\u793a\uff1a\u6700\u591a m \u4f4d\u6570\u5b57\uff0c\u5176\u4e2d d \u4e2a\u5c0f\u6570\uff0c\u5c0f\u6570\u70b9\u4e0d\u7b97\u5728\u957f\u5ea6\u5185\u3002<\/p>\n\n\n\n<p>\u4f8b\u5982\uff1a<\/p>\n\n\n\n<p>DECIMAL(6,2) \u8868\u793a\u4e00\u5171\u80fd\u5b586\u4f4d\u6570\u5b57\uff0c\u672b\u5c3e2\u4f4d\u662f\u5c0f\u6570\uff0c\u5b57\u6bb5\u6700\u5927\u503c\u4e3a9999.99\u3002<\/p>\n\n\n\n<p>\u5b58\u50a8\u540c\u6837\u8303\u56f4\u7684\u503c\uff0c\u6d6e\u70b9\u7c7b\u578b\u901a\u5e38\u6bd4decimal\u4f7f\u7528\u66f4\u5c11\u7684\u7a7a\u95f4\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u5b57\u7b26\u4e32<\/h2>\n\n\n\n<p>char(n) \u56fa\u5b9a\u957f\u5ea6\uff0c\u6700\u591a255\u4e2a\u5b57\u7b26\uff0c\u6ce8\u610f\u4e0d\u662f\u5b57\u8282<br>varchar(n) \u53ef\u53d8\u957f\u5ea6\uff0c\u6700\u591a65535\u4e2a\u5b57\u7b26<br>tinytext \u53ef\u53d8\u957f\u5ea6\uff0c\u6700\u591a255\u4e2a\u5b57\u7b26<br>text \u53ef\u53d8\u957f\u5ea6\uff0c\u6700\u591a65535\u4e2a\u5b57\u7b26<br>mediumtext \u53ef\u53d8\u957f\u5ea6\uff0c\u6700\u591a2\u768424\u6b21\u65b9-1\u4e2a\u5b57\u7b26<br>longtext \u53ef\u53d8\u957f\u5ea6\uff0c\u6700\u591a2\u768432\u6b21\u65b9-1\u4e2a\u5b57\u7b26<br>BINARY(M) \u56fa\u5b9a\u957f\u5ea6\uff0c\u53ef\u5b58\u4e8c\u8fdb\u5236\u6216\u5b57\u7b26\uff0c\u957f\u5ea6\u4e3a0-M\u5b57\u8282<br>VARBINARY(M) \u53ef\u53d8\u957f\u5ea6\uff0c\u53ef\u5b58\u4e8c\u8fdb\u5236\u6216\u5b57\u7b26\uff0c\u5141\u8bb8\u957f\u5ea6\u4e3a0-M\u5b57\u8282<br>\u5185\u5efa\u7c7b\u578b\uff1aENUM\u679a\u4e3e\uff0cSET\u96c6\u5408<\/p>\n\n\n\n<p><strong>char\u548cvarchar\u6709\u4ec0\u4e48\u533a\u522b\uff1a<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>char(n) \u82e5\u5b58\u5165\u5b57\u7b26\u6570\u5c0f\u4e8en\uff0c\u5219\u4ee5\u7a7a\u683c\u8865\u4e8e\u5176\u540e\uff0c\u67e5\u8be2\u4e4b\u65f6\u518d\u5c06\u7a7a\u683c\u53bb\u6389\uff0c\u6240\u4ee5char\u7c7b\u578b\u5b58\u50a8\u7684\u5b57\u7b26\u4e32\u672b\u5c3e\u4e0d\u80fd\u6709\u7a7a\u683c\uff0cvarchar\u4e0d\u9650\u4e8e\u6b64\u3002<\/li><li>char(n) \u56fa\u5b9a\u957f\u5ea6\uff0cchar(4)\u4e0d\u7ba1\u662f\u5b58\u5165\u51e0\u4e2a\u5b57\u7b26\uff0c\u90fd\u5c06\u5360\u75284\u4e2a\u5b57\u8282\uff0cvarchar\u662f\u5b58\u5165\u7684\u5b9e\u9645\u5b57\u7b26\u6570+1\u4e2a\u5b57\u8282\uff0c\u6240\u4ee5varchar(4)\uff0c\u5b58\u51653\u4e2a\u5b57\u7b26\u5c06\u5360\u75284\u4e2a\u5b57\u8282\u3002<\/li><li>char\u7c7b\u578b\u7684\u5b57\u7b26\u4e32\u68c0\u7d22\u901f\u5ea6\u8981\u6bd4varchar\u7c7b\u578b\u7684\u5feb\u3002<\/li><\/ol>\n\n\n\n<p><strong>varchar \u548c text\u6709\u4ec0\u4e48\u533a\u522b\uff1a<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>varchar\u53ef\u6307\u5b9an\uff0ctext\u4e0d\u80fd\u6307\u5b9a\uff0c\u5185\u90e8\u5b58\u50a8varchar\u662f\u5b58\u5165\u7684\u5b9e\u9645\u5b57\u7b26\u6570+1\u4e2a\u5b57\u8282\uff0ctext\u662f\u5b9e\u9645\u5b57\u7b26\u6570+2\u4e2a\u5b57\u8282\u3002<\/li><li>text\u7c7b\u578b\u4e0d\u80fd\u6709\u9ed8\u8ba4\u503c\u3002<\/li><li>varchar\u53ef\u76f4\u63a5\u521b\u5efa\u7d22\u5f15\uff0ctext\u521b\u5efa\u7d22\u5f15\u8981\u6307\u5b9a\u524d\u591a\u5c11\u4e2a\u5b57\u7b26\u3002varchar\u67e5\u8be2\u901f\u5ea6\u5feb\u4e8etext\u3002<\/li><\/ol>\n\n\n\n<p><strong>\u8fd0\u7ef4\u9762\u8bd5\u9898: VARCHAR(50) \u80fd\u5b58\u653e\u51e0\u4e2a UTF8 \u7f16\u7801\u7684\u6c49\u5b57\uff1f<\/strong><\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\u5b58\u653e\u7684\u6c49\u5b57\u4e2a\u6570\u4e0eMYSQL\u7248\u672c\u76f8\u5173\u3002\nMYSQL 4.0\u4ee5\u4e0b\u7248\u672c\uff0cvarchar(50) \u6307\u7684\u662f 50 \u5b57\u8282\uff0c\u5982\u679c\u5b58\u653e UTF8 \u683c\u5f0f\u7f16\u7801\u7684\u6c49\u5b57\u65f6\uff08\u6bcf\u4e2a\u6c49\u5b573\u5b57\u8282\uff09\uff0c\u53ea\u80fd\u5b58\u653e16 \u4e2a\u3002\nMYSQL 5.0\u4ee5\u4e0a\u7248\u672c\uff0cvarchar(50) \u6307\u7684\u662f 50 \u5b57\u7b26\uff0c\u65e0\u8bba\u5b58\u653e\u7684\u662f\u6570\u5b57\u3001\u5b57\u6bcd\u8fd8\u662f UTF8 \u7f16\u7801\u7684\u6c49\u5b57\uff0c\u90fd\u53ef\u4ee5\u5b58\u653e 50 \u4e2a\u3002<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">\u4e8c\u8fdb\u5236\u6570\u636eBLOB<\/h2>\n\n\n\n<p>BLOB\u548ctext\u5b58\u50a8\u65b9\u5f0f\u4e0d\u540c\uff0cTEXT\u4ee5\u6587\u672c\u65b9\u5f0f\u5b58\u50a8\uff0c\u82f1\u6587\u5b58\u50a8\u533a\u5206\u5927\u5c0f\u5199\uff0c\u800cBlob\u4ee5\u4e8c\u8fdb\u5236\u65b9\u5f0f\u5b58\u50a8\uff0c\u4e0d\u5206\u5927\u5c0f\u5199\u3002<br>BLOB\u5b58\u50a8\u7684\u6570\u636e\u53ea\u80fd\u6574\u4f53\u8bfb\u51fa\u3002<br>TEXT\u53ef\u4ee5\u6307\u5b9a\u5b57\u7b26\u96c6\uff0cBLOB\u4e0d\u7528\u6307\u5b9a\u5b57\u7b26\u96c6\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u65e5\u671f\u65f6\u95f4\u7c7b\u578b<\/h2>\n\n\n\n<p>date \u65e5\u671f &#8216;2008-12-2&#8217;<br>time \u65f6\u95f4 &#8217;12:25:36&#8242;<br>datetime \u65e5\u671f\u65f6\u95f4 &#8216;2008-12-2 22:06:44&#8217;<br>timestamp \u81ea\u52a8\u5b58\u50a8\u8bb0\u5f55\u4fee\u6539\u65f6\u95f4<br>YEAR(2), YEAR(4)\uff1a\u5e74\u4efd<\/p>\n\n\n\n<p><strong>timestamp<\/strong> \u5b57\u6bb5\u91cc\u7684\u65f6\u95f4\u6570\u636e\u4f1a\u968f\u5176\u4ed6\u5b57\u6bb5\u4fee\u6539\u7684\u65f6\u5019\u81ea\u52a8\u5237\u65b0\uff0c\u5b58\u653e\u8fd9\u6761\u8bb0\u5f55\u6700\u540e\u88ab\u4fee\u6539\u7684\u65f6\u95f4\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u4fee\u9970\u7b26<\/h2>\n\n\n\n<p><strong>\u9002\u7528\u6240\u6709\u7c7b\u578b\u7684\u4fee\u9970\u7b26\uff1a<\/strong><\/p>\n\n\n\n<p>NULL \u6570\u636e\u5217\u53ef\u5305\u542bNULL\u503c\uff08\u9ed8\u8ba4\u503c\uff09<br>NOT NULL \u6570\u636e\u5217\u4e0d\u5141\u8bb8\u5305\u542bNULL\u503c\uff08\u76f8\u5f53\u4e8e\u7f51\u7ad9\u6ce8\u518c\u8868\u4e2d\u7684 * \u4e3a\u5fc5\u586b\u9009\u9879\uff09<br>DEFAULT \u9ed8\u8ba4\u503c<br>PRIMARY KEY \u4e3b\u952e\uff0c\u6240\u6709\u8bb0\u5f55\u4e2d\u6b64\u5b57\u6bb5\u7684\u503c\u4e0d\u80fd\u91cd\u590d\uff0c\u4e14\u4e0d\u80fd\u4e3aNULL<br>UNIQUE KEY \u552f\u4e00\u952e\uff0c\u6240\u6709\u8bb0\u5f55\u4e2d\u6b64\u5b57\u6bb5\u7684\u503c\u4e0d\u80fd\u91cd\u590d\uff0c\u4f46\u53ef\u4ee5\u4e3aNULL<br>CHARACTER SET name \u6307\u5b9a\u4e00\u4e2a\u5b57\u7b26\u96c6<\/p>\n\n\n\n<p><strong>\u9002\u7528\u6570\u503c\u578b\u7684\u4fee\u9970\u7b26\uff1a<\/strong><\/p>\n\n\n\n<p>AUTO_INCREMENT \u81ea\u52a8\u9012\u589e\uff0c\u9002\u7528\u4e8e\u6574\u6570\u7c7b\u578b, \u5fc5\u987b\u4f5c\u7528\u4e8e\u67d0\u4e2a key \u7684\u5b57\u6bb5,\u6bd4\u5982primary key<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>mysql&gt; SHOW VARIABLES LIKE \"auto_incre%\";\n+--------------------------+-------+\n| Variable_name            | Value |\n+--------------------------+-------+\n| auto_increment_increment | 1     |\n| auto_increment_offset    | 1     |\n+--------------------------+-------+\n# auto_increment_offset \u5b9a\u4e49\u521d\u59cb\u503c\n# auto_increment_increment \u5b9a\u4e49\u6b65\u8fdb<\/code><\/pre>\n\n\n\n<p>UNSIGNED \u65e0\u7b26\u53f7<\/p>\n","protected":false},"excerpt":{"rendered":"<p>MYSQL\u5728\u521b\u5efa\u8868\u7684\u65f6\u5019\u901a\u5e38\u9700\u8981\u6307\u5b9a\u5b57\u6bb5\u7684\u6570\u636e\u7c7b\u578b\uff0c\u7528\u4e8e\u5b58\u653e\u6570\u636e\u3002\u6570\u636e\u7c7b\u578b\u5927\u81f4\u5206\u4e3a\uff0c\u6570\u503c\u578b\u3001\u5b57\u7b26\u578b\u548c\u65f6\u95f4\u65e5\u671f\u578b\u3002 \u9009\u62e9\u6b63\u786e\u7684\u6570\u636e\u7c7b\u578b\u5bf9\u4e8e\u83b7\u5f97\u9ad8\u6027\u80fd\u81f3\u5173\u91cd\u8981\uff1a \u66f4\u5c0f\u7684\u901a\u5e38\u66f4\u597d\uff0c\u5c3d\u91cf\u4f7f\u7528\u53ef\u6b63\u786e\u5b58\u50a8\u6570\u636e\u7684\u6700\u5c0f\u6570\u636e\u7c7b\u578b \u7b80\u5355\u5c31\u597d\uff0c\u7b80\u5355\u6570\u636e\u7c7b\u578b\u7684\u64cd\u4f5c&#8230;<\/p>\n","protected":false},"author":1,"featured_media":283,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[35],"tags":[36],"topic":[],"class_list":["post-293","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-35","tag-mysql"],"_links":{"self":[{"href":"https:\/\/frogvps.com\/index.php?rest_route=\/wp\/v2\/posts\/293","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/frogvps.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/frogvps.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/frogvps.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/frogvps.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=293"}],"version-history":[{"count":2,"href":"https:\/\/frogvps.com\/index.php?rest_route=\/wp\/v2\/posts\/293\/revisions"}],"predecessor-version":[{"id":295,"href":"https:\/\/frogvps.com\/index.php?rest_route=\/wp\/v2\/posts\/293\/revisions\/295"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/frogvps.com\/index.php?rest_route=\/wp\/v2\/media\/283"}],"wp:attachment":[{"href":"https:\/\/frogvps.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=293"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/frogvps.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=293"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/frogvps.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=293"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/frogvps.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftopic&post=293"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}