{"id":978,"date":"2017-10-17T14:52:06","date_gmt":"2017-10-17T06:52:06","guid":{"rendered":"http:\/\/www.5x44.cn\/?p=978"},"modified":"2017-10-18T15:55:53","modified_gmt":"2017-10-18T07:55:53","slug":"mysql5-7%e6%95%b0%e5%ad%97%e7%b1%bb%e5%9e%8b%e6%80%bb%e8%a7%88","status":"publish","type":"post","link":"https:\/\/www.5x44.cn\/?p=978","title":{"rendered":"mysql5.7\u6570\u5b57\u7c7b\u578b\u603b\u89c8"},"content":{"rendered":"<p><a href=\"https:\/\/dev.mysql.com\/doc\/refman\/5.7\/en\/numeric-type-overview.html\">https:\/\/dev.mysql.com\/doc\/refman\/5.7\/en\/numeric-type-overview.html<\/a><\/p>\n<p>\u5982\u679c\u5728\u5b9a\u4e49\u7684\u5217\u4e0a\u6307\u5b9a\u4e86ZEROFILL\uff0c\u90a3\u4e48MYSQL\u4f1a\u81ea\u52a8\u7684\u6dfb\u52a0UNSIGNED\u5c5e\u6027\uff08\u6709UNSIGNED\u5c5e\u6027\u540c\u6837\u4e5f\u6709SIGNED\u51fd\u6027\uff0cSIGNED\u662f\u9ed8\u8ba4\u5c5e\u6027\uff09\u3002<\/p>\n<p>SERIAL\u662f<em>BIGINT UNSIGNED NOT NULL AUTO_INCREMENT UNIQUE<\/em>\u7684\u522b\u540d\u3002<\/p>\n<p>\u5728\u5b9a\u4e49\u4e00\u4e2a\u6574\u578b\u5217\u65f6\u4f7f\u7528SERIAL DEFAULT VALUE\u4ee3\u8868<em>NOT NULL AUTO_INCREMENT UNIQUE<\/em>\u3002<\/p>\n<p>M\u6307\u5b9a\u4e86\u6700\u5927\u7684\u6574\u6570\u663e\u793a\u5bbd\u5ea6\uff0c\u8fd9\u4e2a\u6700\u5927\u663e\u793a\u5bbd\u5ea6\u662f255\u3002\u663e\u793a\u5bbd\u5ea6\u548c\u53d6\u503c\u8303\u56f4\u65e0\u5173\u3002\u5bf9\u4e8e\u6d6e\u70b9\u578b\u548c\u56fa\u5b9a\u5c0f\u6570\u70b9\u7684\u7c7b\u578b\uff0cM\u6307\u5b9a\u7684\u662f\u6570\u5b57\u7684\u603b\u5bbd\u5ea6\u3002<\/p>\n<div class=\"warning\">\n<div class=\"admon-title\">Warning<\/div>\n<p>When you use subtraction between integer values where one is of type <code class=\"literal\">UNSIGNED<\/code>, the result is unsigned unless the <a class=\"link\" href=\"https:\/\/dev.mysql.com\/doc\/refman\/5.7\/en\/sql-mode.html#sqlmode_no_unsigned_subtraction\"><code class=\"literal\">NO_UNSIGNED_SUBTRACTION<\/code><\/a> SQL mode is enabled. See <a class=\"xref\" title=\"12.10\u00a0Cast Functions and Operators\" href=\"https:\/\/dev.mysql.com\/doc\/refman\/5.7\/en\/cast-functions.html\">Section\u00a012.10, \u201cCast Functions and Operators\u201d<\/a>.<\/p>\n<ul>\n<li>BIT[(M)]\uff1a\u4e8c\u8fdb\u5236\u4f4d\u7c7b\u578b\u3002M\u6307\u5b9a\u4e86\u6bcf\u4e2a\u6570\u7684\u4f4d\u6570\uff0c\u4ece1\u523064.\u9ed8\u8ba4\u503c\u662f1\u3002<\/li>\n<li>TINYINT[(M)][UNSIGNED][ZEROFILL]\uff1a\u975e\u5e38\u5c0f\u7684\u6574\u6570\u3002\u6709\u7b26\u53f7\u6570\u7684\u8303\u56f4\u662f-128~127\u3002\u65e0\u7b26\u53f7\u6570\u7684\u8303\u56f4\u662f0~255.<\/li>\n<li>BOOL\uff0cBOOLEAN\uff1a\u8fd9\u4e9b\u548cTINYINT(1)\u540c\u4e49\u3002\u96f6\u503c\u88ab\u8ba4\u4e3a\u662ffalse\uff0c\u975e\u96f6\u503c\u88ab\u8ba4\u4e3a\u662ftrue\uff1a\n<pre>mysql&gt; select if(1,'true','false');\r\n+----------------------+\r\n| if(1,'true','false') |\r\n+----------------------+\r\n| true                 |\r\n+----------------------+\r\n1 row in set (0.00 sec)\r\n\r\nmysql&gt; select if(1,'false','true');\r\n+----------------------+\r\n| if(1,'false','true') |\r\n+----------------------+\r\n| false                |\r\n+----------------------+\r\n1 row in set (0.00 sec)\r\n\r\nmysql&gt; select if(0,'true','false');\r\n+----------------------+\r\n| if(0,'true','false') |\r\n+----------------------+\r\n| false                |\r\n+----------------------+\r\n1 row in set (0.00 sec)<\/pre>\n<p>\u4f46\u662fTRUE\u548cFALSE\u4ec5\u4ec5\u4ee3\u88681\u548c0\u3002<\/li>\n<li>SMALLINT[(M)][UNSIGNED][ZEROFILL]:\u5c0f\u6574\u6570\uff0c\u6709\u7b26\u53f7\u53d6\u503c\u8303\u56f4\u662f-32768\u523032767\u3002\u65e0\u7b26\u53f7\u53d6\u503c\u8303\u56f4\u662f0\u523065535\u3002<\/li>\n<li>MEDIUMINT[(M)][UNSIGNED][ZEROFILL]\uff1a\u6bd4SMALLINT\u53d6\u503c\u8303\u56f4\u8981\u5927\u7684\u6574\u6570\uff0c\u6709\u7b26\u53f7\u53d6\u503c\u8303\u56f4-8388608\u52308388607\uff0c\u65e0\u7b26\u53f7\u53d6\u503c\u8303\u56f4\u662f0\u523016777215\u3002<\/li>\n<li>INT[(M)][UNSIGNED][ZEROFILL]\uff1a\u6574\u578b\uff0c\u6709\u7b26\u53f7\u53d6\u503c\u8303\u56f4-2147483648\u5230214748647\uff0c\u65e0\u7b26\u53f7\u53d6\u503c\u8303\u56f40\u52304294967295\u3002<\/li>\n<li>INTEGER[(M)][UNSIGNED][ZEROFILL]\uff1a\u548cINT\u7c7b\u578b\u4e00\u6837\u3002<\/li>\n<li>BIGINT[(M)][UNSIGNED][ZEROFILL]:\u5927\u6574\u6570\uff0c\u6709\u7b26\u53f7\u7684\u53d6\u503c\u8303\u56f4\u662f-9223372036854775808\u52309223372036854775807\u3002\u65e0\u7b26\u53f7\u7684\u8303\u56f4\u662f0\u523018446744073709551615\u3002\n<pre>\u5bf9\u4e8eBIGINT\u7c7b\u578b\u7684\u5217\u8981\u77e5\u9053\u4ee5\u4e0b\u51e0\u70b9\uff1a\r\n\uff08\u4e00\uff09\u6240\u6709\u7684\u7b97\u6570\u8fd0\u7b97\u4f7f\u7528\u7684\u90fd\u662f\u6709\u7b26\u53f7\u7684BIGINT\u6216DOUBLE\u503c\uff0c\u6240\u4ee5\u9664\u975e\u662f\u4f7f\u7528\u4f4d\u64cd\u4f5c\u51fd\u6570\u5426\u5219\u4f60\u4e0d\u5e94\u8be5\u4f7f\u7528\u65e0\u7b26\u53f7\u7684BIGINT\u5927\u4e8e9223372036854775807 (63 bits)\uff0c\u5982\u679c\u4f60\u8fd9\u4e48\u505a\u4e86\u7ed3\u679c\u4e2d\u7684\u6700\u540e\u51e0\u4e2a\u6570\u5b57\u53ef\u80fd\u662f\u9519\u7684\uff0c\u56e0\u4e3a\u5728BIGINT\u8f6c\u6362\u6210DOUBLE\u65f6\u4f1a\u6709\u7cbe\u5ea6\u635f\u5931\u3002MYSQL\u80fd\u5904\u7406BIGINT\u5728\u5982\u4e0b\u51e0\u79cd\u60c5\u51b5\u3002\r\n\uff081\uff09\u4f7f\u7528\u6574\u6570\u5b58\u50a8\u4e00\u4e2a\u5f88\u5927\u7684\u65e0\u7b26\u53f7\u503c\u3002\r\n\uff082\uff09\u5728MIN(col name)\u6216MAX(col name)\uff0c\u8fd9\u4e2aCOL NAME\u662f\u4e00\u4e2aBIGINT\u5217\u3002\r\n\uff083\uff09\u4e24\u8fb9\u90fd\u662f\u6574\u6570\u65f6\u4f7f\u7528\u7b97\u6570\u8fd0\u7b97\u7b26\u53f7\uff08+\uff0c-\uff0c*\u7b49\u7b49\uff09\r\n\uff08\u4e8c\uff09\u4f60\u53ef\u4ee5\u628a\u4e00\u4e2a\u5b57\u7b26\u4e32\u5b58\u50a8\u5230BIGINT\u5217\u4e2d\u3002\u5728\u8fd9\u65f6\uff0cMYSQL\u6267\u884c\u4e00\u4e2a\u5b57\u7b26\u4e32\u5230\u6570\u503c\u7684\u8f6c\u6362\uff0c\u8fd9\u4e2a\u8f6c\u6362\u5e76\u4e0d\u4f1a\u6d89\u53ca\u5230\u4e2d\u95f4\u8f6c\u6362\u6210\u53cc\u7cbe\u5ea6\u518d\u8f6c\u6210\u6574\u578b\u3002\r\n\uff08\u4e09\uff09\u5f53\u7b97\u6570\u8fd0\u7b97\u7b26\uff08+\uff0c-\uff0c*\uff09\u4e24\u8fb9\u90fd\u662f\u6574\u578b\u65f6\uff0c\u4f7f\u7528BIGINT\u7b97\u6570\u8fd0\u7b97\u3002\u8fd9\u610f\u5473\u7740\u5982\u679c\u4f60\u5c06\u4e24\u4e2a\u5927\u6574\u6570\u76f8\u4e58\uff08\u6216\u8005\u4ece\u67d0\u4e2a\u51fd\u6570\u8fd4\u56de\u6574\u6570\uff09\uff0c\u5f53\u8be5\u503c\u53ef\u80fd\u5927\u4e8e9223372036854775807\u65f6\uff0c\u4f60\u53ef\u80fd\u5f97\u5230\u4e00\u4e2a\u610f\u60f3\u4e0d\u5230\u7684\u7ed3\u679c\u3002\r\n<\/pre>\n<\/li>\n<li>\n<pre>\u00a0DECIMAL[(M[,D])][UNSIGNED][ZEROFILL]:\u8fd9\u662f\u4e00\u4e2a\u5b9a\u70b9\u503c\u3002M\u662f\u6570\u5b57\u7684\u603b\u957f\u5ea6\uff0cD\u662f\u5c0f\u6570\u70b9\u540e\u9762\u6709\u51e0\u4f4d\u3002\u5c0f\u6570\u70b9\u548c\u6b63\u8d1f\u53f7\u4e0d\u8ba1\u7b97\u5728\u603b\u957f\u5ea6M\u4e2d\u3002\u5982\u679cD\u662f0\uff0c\u6570\u503c\u6ca1\u6709\u5c0f\u6570\u70b9\u540e\u9762\u7684\u4f4d\u6570\u3002M\u7684\u6700\u5927\u503c\u662f65\u3002\u6700\u5927\u652f\u6301\u7684D\u503c\u662f30\u3002\u5982\u679cD\u88ab\u5ffd\u7565\uff0c\u9ed8\u8ba4\u662f0\u3002\u5982\u679cM\u88ab\u5ffd\u7565\uff0c\u9ed8\u8ba4\u503c\u662f10\u3002\u5982\u679c\u6307\u5b9a\u4e86UNSIGNED\uff0c\u4e0d\u5141\u8bb8\u8d1f\u6570\u3002\u6240\u6709\u5728DECIMAL\u5217\u4e0a\u7684\u57fa\u672c\u8ba1\u7b97\uff08+\uff0c-\uff0c*\uff0c\/\uff09\u7cbe\u5ea6\u662f65\u4f4d\u6570\u5b57\u3002<\/pre>\n<\/li>\n<li>\n<pre><\/pre>\n<p>DEC[(M[,D])] [UNSIGNED] [ZEROFILL], NUMERIC[(M[,D])] [UNSIGNED] [ZEROFILL], FIXED[(M[,D])][UNSIGNED][ZEROFILL] \uff1a\u8fd9\u4e9b\u7c7b\u578b\u548cDECIMAL\u6709\u76f8\u540c\u610f\u4e49\u3002FIXED\u53ef\u517c\u5bb9\u4e8e\u5176\u4ed6\u6570\u636e\u5e93\u7cfb\u7edf\u3002<\/li>\n<li>FLOAT[(M,D)][UNSIGNED][ZEROFILL]\uff1a\u5c0f\u5355\u7cbe\u5ea6\u6570\u3002\u53d6\u503c\u8303\u56f4\u662f-3.402823466E+38\u5230-1.175494351E-38\uff0c0\uff0c1.175494351E-38\u52303.402823466E+38\u3002\u8fd9\u4e9b\u662f\u57fa\u4e8eIEEE\u6807\u51c6\u7684\u7406\u8bba\u6781\u9650\u3002\u5b9e\u9645\u4e0a\u8981\u6839\u636e\u4f60\u7684\u7cfb\u7edf\u786c\u4ef6\u53ef\u80fd\u4f1a\u7a0d\u5fae\u5c0f\u4e00\u70b9\u3002M\u662f\u603b\u4f4d\u6570\uff0cD\u662f\u5c0f\u6570\u70b9\u540e\u7684\u4f4d\u6570\u3002\u5982\u679cM\u548cD\u90fd\u88ab\u5ffd\u7565\uff0c\u503c\u4ee5\u786c\u4ef6\u6781\u9650\u5b58\u50a8\u3002\u5355\u7cbe\u5ea6\u6570\u5927\u7ea6\u662f7\u4f4d\u6709\u6548\u6570\u5b57\u3002\u5982\u679c\u6307\u5b9a\u4e86UNSIGNED\uff0c\u90a3\u4e48\u4e0d\u53ef\u4ee5\u8d4b\u4e88\u8d1f\u503c\u3002\u4f7f\u7528FLOAT\u53ef\u80fd\u4f1a\u7ed9\u4f60\u4ee3\u6765\u4e00\u4e9b\u610f\u60f3\u4e0d\u5230\u7684\u95ee\u9898\uff0c\u56e0\u4e3aMYSQL\u4f7f\u7528\u6d6e\u70b9\u53cc\u7cbe\u5ea6\u5728\u6240\u6709\u7684\u8fd0\u7b97\u4e2d\u3002<\/li>\n<li>DOUBLE[(M,D)][UNSIGNED][ZEROFILL]\uff1a\u6b63\u5e38\u5927\u5c0f\u7684\u53cc\u7cbe\u5ea6\u6570\u3002\u503c\u7684\u8303\u56f4\u662f -1.7976931348623157E+308 \u5230 -2.2250738585072014E-308, 0, and 2.2250738585072014E-308 \u5230 1.7976931348623157E+308\u3002\u8fd9\u4e9b\u662fIEEE\u6807\u51c6\u7684\u7406\u8bba\u6781\u9650\u3002\u5b9e\u9645\u8303\u56f4\u6839\u636e\u786c\u4ef6\u53ef\u80fd\u8981\u7a0d\u5fae\u5c0f\u4e00\u4e9b\u3002M\u662f\u603b\u4f4d\u6570\uff0cD\u662f\u5c0f\u6570\u4f4d\u3002\u5982\u679cM\u548cD\u88ab\u5ffd\u7565\uff0c\u503c\u4ee5\u786c\u4ef6\u7684\u6781\u9650\u5927\u5c0f\u5b58\u50a8\u3002\u4e00\u4e2a\u6d6e\u70b9\u53cc\u7cbe\u5ea6\u503c\u5927\u7ea615\u4f4d\u3002UNSIGNED\u88ab\u6307\u5b9a\uff0c\u90a3\u4e48\u4e0d\u80fd\u8d4b\u4e88\u8d1f\u503c\u3002<\/li>\n<li>DOUBLE PRECISION[(M,D)][UNSIGNED][ZEROFILL], REAL[(M,D)][UNSIGNED][ZEROFILL]\uff1a\u8fd9\u4e9b\u7c7b\u578b\u548cDOUBLE\u540c\u4e49\u3002\u4f8b\u5916\uff1a\u5982\u679c<a href=\"https:\/\/dev.mysql.com\/doc\/refman\/5.7\/en\/sql-mode.html#sqlmode_real_as_float\">REAL AS FLOAT<\/a>\u7684SQL\u6a21\u5f0f\u5f00\u542f\uff0c\u90a3\u4e48REAL\u5c31\u4f1a\u505a\u4e3aFLOAT\u800c\u4e0d\u662fDOUBLE\u3002<\/li>\n<li>FLOAT(p)[UNSIGNED][ZEROFILL]\uff1a\u5355\u7cbe\u5ea6\u6570\u3002p\u6307\u5b9a\u4e86\u7cbe\u5ea6\u4f4d\u6570\uff08\u4e8c\u8fdb\u5236\uff0c\u4e4b\u524d\u7684M\u548cD\u662f\u5341\u8fdb\u5236\u4f4d\u6570\uff09\uff0c\u4f46\u662fMYSQL\u4ec5\u5728\u51b3\u5b9a\u662f\u5426\u4f7f\u7528FLOAT\u6216DOUBLE\u505a\u4e3a\u7ed3\u679c\u6570\u636e\u7c7b\u578b\u65f6\u624d\u4f1a\u6709\u7528\u3002\u5982\u679cp\u662f0\u523024\uff0c\u6570\u636e\u7c7b\u578b\u4e3a\u6ca1\u6709\u6307\u5b9aM\u548cD\u7684FLOAT\u7c7b\u578b\u3002\u5982\u679c\u662f25\u523053\uff0c\u90a3\u4e48\u7c7b\u578b\u662fDOUBLE\u3002\u7ed3\u679c\u7684\u53d6\u503c\u8303\u56f4\u8fd8\u662f\u548c\u4e0a\u9762\u63cf\u8ff0FLOAT\u548cDOUBLE\u7684\u4e00\u6837\u3002<\/li>\n<\/ul>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/dev.mysql.com\/doc\/refman\/5.7\/en\/numeric-type-overview.html \u5982\u679c\u5728\u5b9a\u4e49\u7684\u5217\u4e0a\u6307\u5b9a\u4e86ZE&#8230;<\/p>\n<p class=\"read-more\"><a class=\"btn btn-default\" href=\"https:\/\/www.5x44.cn\/?p=978\"> Read More<span class=\"screen-reader-text\">  Read More<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[37],"tags":[],"class_list":["post-978","post","type-post","status-publish","format-standard","hentry","category-mysql"],"_links":{"self":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts\/978","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=978"}],"version-history":[{"count":6,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts\/978\/revisions"}],"predecessor-version":[{"id":984,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts\/978\/revisions\/984"}],"wp:attachment":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=978"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=978"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=978"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}