{"id":991,"date":"2017-10-19T15:12:50","date_gmt":"2017-10-19T07:12:50","guid":{"rendered":"http:\/\/www.5x44.cn\/?p=991"},"modified":"2017-10-25T14:57:57","modified_gmt":"2017-10-25T06:57:57","slug":"mysql5-7%e5%ad%97%e7%ac%a6%e4%b8%b2%e7%b1%bb%e5%9e%8b%e6%80%bb%e8%a7%88","status":"publish","type":"post","link":"https:\/\/www.5x44.cn\/?p=991","title":{"rendered":"MYSQL5.7\u5b57\u7b26\u4e32\u7c7b\u578b\u603b\u89c8"},"content":{"rendered":"<p><a href=\"https:\/\/dev.mysql.com\/doc\/refman\/5.7\/en\/string-type-overview.html\">https:\/\/dev.mysql.com\/doc\/refman\/5.7\/en\/string-type-overview.html<\/a><\/p>\n<p>\u5b57\u7b26\u4e32\u7c7b\u578b\u5217\u7684\u5b9a\u4e49\u53ef\u4ee5\u6307\u5b9a\u5b57\u7b26\u96c6\u6216\u5b57\u7b26\u7684\u6392\u5e8f\u65b9\u5f0f\u3002\u8fd9\u4e2a\u5c5e\u6027\u53ef\u4ee5\u5e94\u7528\u5230CHAR,VARCHAR,TEXT,ENUM\u548cSET\u6570\u636e\u7c7b\u578b\uff1a<\/p>\n<ul>\n<li>CHARACTER SET\u5c5e\u6027\u6307\u5b9a\u5b57\u7b26\u96c6\uff0c\u800cCOLLATE\u5c5e\u6027\u6307\u5b9a\u4e86\u5b57\u7b26\u7684\u6392\u5e8f\u65b9\u5f0f\u3002\u5982\uff1a\n<pre>CREATE TABLE t\r\n(\r\n    c1 VARCHAR(20) CHARACTER SET utf8,\r\n    c2 TEXT CHARACTER SET latin1 COLLATE latin1_general_cs\r\n);\r\n<\/pre>\n<p>\u8be5\u8868\u4e2d\u7684C1\u5217\u7684\u5b57\u7b26\u96c6\u662fUTF8\uff0c\u4f7f\u7528\u9ed8\u8ba4\u7684\u6392\u5e8f\u89c4\u5219\uff1bc2\u5217\u7684\u5b57\u7b26\u96c6\u4f7f\u7528latin1\u548c\u5927\u5c0f\u5199\u654f\u611f\u7684\u6392\u5e8f\u89c4\u5219\u3002<br \/>\n<strong>CHARSET\u548cCHARACTER SET\u540c\u610f<\/strong><\/li>\n<li>\u4e3a\u5b57\u7b26\u4e32\u7c7b\u578b\u6570\u636e\u6307\u5b9aCHARACTER SET binary\u5c5e\u6027\uff0c\u4f1a\u5bfc\u81f4\u5217\u88ab\u521b\u5efa\u6210\u76f8\u5e94\u7684\u4e8c\u8fdb\u5236\u5b57\u7b26\u4e32\u7c7b\u578b\uff1aCHAR\u53d8\u4e3aBINARY\uff0cVARCHAR\u53d8\u4e3aVARBINARY\uff0cTEXT\u53d8\u4e3aBLOB\u3002\u5bf9\u4e8eENUM\u548cSET\u7c7b\u578b\u8fd9\u4e2a\u64cd\u4f5c\u4e0d\u751f\u6548\u3002<\/li>\n<li>BINARY\u662f\u8868\u9ed8\u8ba4\u5b57\u7b26\u96c6\u548c\u4e8c\u8fdb\u5236\u5b57\u7b26\u96c6\u6392\u5e8f\u7684\u7f29\u5199\u3002\u5b83\u7684\u6bd4\u8f83\u548c\u6392\u5e8f\u662f\u57fa\u4e8e\u5b57\u7b26\u7684\u6570\u5b57\u4ee3\u7801\u503c\u3002<\/li>\n<li>ASCII\u5c5e\u6027\u662fCHARACTER SET latin1\u7684\u7f29\u5199\u3002<\/li>\n<li>UNICODE\u5c5e\u6027\u662fCHARACTER SET ucs2\u7684\u7f29\u5199\u3002<\/li>\n<\/ul>\n<p>\u5217\u7684\u5b57\u7b26\u6bd4\u8f83\u548c\u6392\u5e8f\u662f\u57fa\u4e8e\u5206\u914d\u5230\u5217\u4e0a\u7684\u6392\u5e8f\u6bd4\u8f83\u65b9\u6cd5\u3002\u7528\u4e8eCHAR\uff0cVARCHAR\uff0cTEXT\uff0cENUM\u548cSET\u6570\u636e\u7c7b\u578b\uff0c\u4f60\u53ef\u4ee5\u5b9a\u4e49\u4e00\u4e2a\u5217\u4f7f\u7528\u4e8c\u8fdb\u5236\uff08_bin\uff09\u6392\u5e8f\u89c4\u5219\u6216BINARY\u5c5e\u6027\u7684\u5217\uff0c\u89c4\u5b9a\u6bd4\u8f83\u548c\u6392\u5e8f\u4f7f\u7528\u5b57\u7b26\u7684\u4ee3\u7801\u503c\uff0c\u800c\u4e0d\u662f\u5b57\u5178\u987a\u5e8f\u3002<\/p>\n<ul>\n<li>[NATIONAL]CHAR[(M)] [CHARACTER SET <strong>charset_name<\/strong>] [COLIATE <strong>collation_name<\/strong>]\uff1a\u5b9a\u957f\u5b57\u7b26\u4e32\uff0c\u4e00\u76f4\u662f\u53cb\u4fa7\u586b\u5145\u7a7a\u683c\u6765\u8fbe\u5230\u957f\u5ea6\u7528\u4e8e\u5b58\u50a8\u3002M\u63cf\u8ff0\u4e86\u5217\u80fd\u5b58\u50a8\u5b57\u7b26\u7684\u957f\u5ea6\u3002\u8303\u56f4\u662f0\uff5e255\u3002\u5982\u679cM\u88ab\u5ffd\u7565\uff0c\u957f\u5ea6\u9ed8\u8ba4\u662f1\u3002\u586b\u5145\u7684\u7a7a\u683c\u5728\u4f7f\u7528\u5217\u4e2d\u7684\u503c\u65f6\uff0c\u4f1a\u88ab\u79fb\u9664\uff0c\u9664\u975e<code>PAD_CHAR_TO_FULL_LENGTH<\/code>\u7684SQL\u6a21\u5f0f\u88ab\u5f00\u542f\u3002CHAR\u662fCHARACTER\u7684\u7f29\u5199\u3002<code>NATIONAL CHAR<\/code>\uff08\u5b83\u7b49\u4ef7\u4e8eNCHAR\uff09\u662f\u6807\u51c6SQL\u7528\u4e8e\u5b9a\u4e49\u4e00\u4e2a\u5e26\u6709\u9884\u7f6e\u5b57\u7b26\u96c6\u7684CHAR\u5217\u3002MYSQL\u4f7f\u7528UTF8\u505a\u4e3a\u9884\u7f6e\u5b57\u7b26\u96c6\u3002<code>CHAR BYTE<\/code>\u7c7b\u578b\u662f<code>BINARY<\/code>\u7c7b\u578b\u7684\u53e6\u4e00\u79cd\u5199\u6cd5\u3002\u8fd9\u7528\u4e8e\u517c\u5bb9\u4ee5\u540e\u7684\u4e00\u4e9b\u529f\u80fd\u3002MYSQL\u5141\u8bb8\u521b\u5efa\u5217\u7684\u7c7b\u578b\u4e3a<code>CHAR\uff080\uff09<\/code>\u3002\u8fd9\u7528\u4e8e\u517c\u5bb9\u4f9d\u8d56\u67d0\u4e9b\u5217\u5b58\u5728\u4f46\u4e0d\u4f7f\u7528\u5b83\u7684\u503c\u7684\u8001\u5e94\u7528\u5f88\u6709\u7528\u5904\u3002char(0)\u53ef\u4ee5\u5bb9\u7eb3NULL\u503c\u548c&#8221;\uff08\u7a7a\u5b57\u7b26\u4e32\uff09\u3002<\/li>\n<li>[NATIONAL] VARCHAR(M) [CHARACTER SET charset_name] [COLLATE collation_name]\uff1a\u53d8\u957f\u5b57\u7b26\u4e32\u3002M\u63cf\u672f\u4e86\u5217\u6700\u5927\u5bb9\u7eb3\u5b57\u7b26\u7684\u957f\u5ea6\u3002M\u7684\u8303\u56f4\u662f0\uff5e65535\u3002VARCHAR\u7684\u6700\u5927\u957f\u5ea6\u5bb9\u6613\u53d7\u5230\u6700\u5927\u884c\u6570\uff0865535\u5b57\u8282\uff0c\u8fd9\u4e2a\u6570\u5b57\u5171\u4eab\u5230\u6240\u6709\u7684\u5217\uff09\u548c\u5b57\u7b26\u96c6\u7684\u5f71\u54cd\u3002\u4f8b\u5982\uff1aUTF8\u5b57\u7b26\u53ef\u80fd\u6bcf\u4e2a\u5b57\u7b26\u9700\u8981\u6700\u591a\u4e09\u4e2a\u5b57\u8282\uff0c\u6240\u4ee5\u4f7f\u7528UTF8\u7684\u5b57\u6bb5\u6700\u5927\u53ef\u4ee5\u5b58\u50a821844\u5b57\u7b26\u3002MYSQL\u4f7f\u75281\u52302\u4e2a\u5b57\u8282\u957f\u5ea6\u5b58\u50a8VARCHAR\u524d\u7f00\u52a0\u6570\u636e\u7684\u5b58\u50a8\u5f62\u5f0f\u3002\u524d\u7f00\u6307\u793a\u4e86\u5b57\u7b26\u7528\u4e86\u51e0\u4e2a\u5b57\u8282\u5b58\u50a8\u3002\u5982\u679c\u503c\u4e0d\u9700\u8981\u8d85\u8fc7255\u5b57\u8282\uff0c\u90a3\u4e48VARCHAR\u5217\u4f7f\u7528\u4e00\u4e2a\u957f\u5ea6\u7684\u5b57\u8282\u3002\u5982\u679c\u503c\u53ef\u80fd\u8d85\u8fc7255\u5b57\u8282\uff0c\u90a3\u4e48\u4f7f\u7528\u4e24\u4e2a\u957f\u5ea6\u5b57\u8282\u3002VARCHAR\u662fCHARACTER VARYING\u7684\u7f29\u5199\u3002NATIONAL VARCHAR\u662f\u6807\u51c6 SQL\u4f7f\u7528\u9884\u5b9a\u4e49\u5b57\u7b26\u96c6\u5b9a\u4e49\u4e00\u4e2aVARCHAR\u5217\u3002MYSQL\u4f7f\u7528UTF8\u505a\u4e3a\u9884\u5b9a\u4e49\u5b57\u7b26\u96c6\u3002<\/li>\n<li>BINARY\uff08M\uff09\uff1aBINARY\u7c7b\u578b \u7c7b\u4f3c\u4e8eCHAR\u7c7b\u578b\uff0c\u4f46\u662f\u4ee5\u4e8c\u8fdb\u5236\u5b57\u8282\u5b58\u50a8\u800c\u4e0d\u662f\u975e\u4e8c\u8fdb\u5236\u5b57\u7b26\u3002M\u63cf\u8ff0\u4e86\u5217\u7684\u957f\u5ea6\uff0c\u5355\u4f4d\u662f\u5b57\u8282\u3002<\/li>\n<li>VARBINARY\uff08M\uff09\uff1aVARBINARY\u7c7b\u578b\u7c7b\u4f3c\u4e8eVARCHAR\u7c7b\u578b \uff0c\u4f46\u662f\u540c\u6837\u4ee5\u4e8c\u8fdb\u5236\u5b58\u50a8\u800c\u4e0d\u662f\u975e\u4e8c\u8fdb\u5236\u5b57\u7b26\u3002M\u63cf\u8ff0\u4e86\u5217\u7684\u6700\u5927\u957f\u5ea6\uff0c\u5355\u4f4d\u662f\u5b57\u8282\u3002<\/li>\n<li>TINYBLOB\uff1aBLOB\u5217\u7684\u6700\u5927\u957f\u5ea6\u662f255\uff082<sup>8<\/sup>-1 \uff09\u4e2a\u5b57\u8282\u3002\u6bcf\u4e00\u4e2aTINYBLOB\u503c\u88ab\u5b58\u50a8\u6210\u4e00\u4e2a\u5b57\u8282\u524d\u7f00\u7528\u6765\u6307\u793a\u6570\u636e\u503c\u9700\u8981\u591a\u5927\u7a7a\u95f4\u5b58\u50a8\u7684\u503c\u3002<\/li>\n<li>TINYTEXT [CHARACTER SET charset_name][COLLATE collation_name]\uff1aTEXT\u5217\u7684\u6700\u5927\u957f\u5ea6\u662f255\uff082<sup>8<\/sup>-1 \uff09\u5b57\u7b26\u3002\u5982\u679c\u503c\u5305\u542b\u591a\u5b57\u8282\uff0c\u90a3\u4e48\u4f1a\u5f71\u54cd\u6700\u5927\u7684\u957f\u5ea6\u3002\u6bcf\u4e00\u4e2aTINYTEXT\u503c\u88ab\u5b58\u50a8\u6210\u4e00\u4e2a\u5b57\u8282\u524d\u7f00\u7528\u6765\u6307\u793a\u6570\u636e\u503c\u9700\u8981\u591a\u5927\u7a7a\u95f4\u5b58\u50a8\u7684\u503c\u3002<\/li>\n<li>BLOB[(M)]\uff1aBLOB\u5217\u7684\u6700\u5927\u957f\u5ea6\u662f65535\uff082<sup>16<\/sup>-1\uff09\u5b57\u8282\u3002\u6bcf\u4e00\u4e2aBLOB\u503c\u4f7f\u75282\u5b57\u8282\u957f\u5ea6\u7684\u524d\u7f00\u6307\u793a\u88ab\u5b58\u50a8\u7684\u503c\uff0c\u7528\u591a\u5c11\u5b57\u8282\u5b58\u50a8\u3002M\u662f\u53ef\u9009\u957f\u5ea6\uff0c\u6307\u5b9a\u4e86\u8be5\u503c\uff0cMYSQL\u5efa\u7acbBLOB\u7c7b\u578b\u5217\uff0c\u6700\u5c0fM\u5b57\u8282\u957f\u5ea6\u3002<\/li>\n<li>TEXT[(M)] [CHARACTER SET charset_name] [COLLATE collation_name]\uff1aTEXT\u5217\u6700\u5927\u957f\u5ea6\u662f65535\uff082<sup>16<\/sup>-1\uff09\u5b57\u7b26\u3002\u5982\u679c\u5305\u542b\u591a\u5b57\u8282\u5b57\u7b26\uff0c\u5b9e\u9645\u6700\u5927\u957f\u5ea6\u8981\u5c0f\u4e8e\u8fd9\u4e2a\u503c\u3002\u6bcf\u4e00\u4e2aTEXT\u503c\u4f7f\u75282\u5b57\u8282\u957f\u5ea6\u7684\u524d\u7f00\u6307\u793a\u5b58\u50a8\u503c\u7684\u5927\u5c0f\u3002M\u6307\u5b9a\u4e86TEXT\u7c7b\u578b\u7684\u6700\u5c0f\u5b57\u7b26\u6570\u3002<\/li>\n<li>MEDIUMBLOB\uff1aMEDIUMBLOB\u5217\u7684\u6700\u5927\u957f\u5ea6\u662f16777215\uff082<sup>24 <\/sup>-1)\u5b57\u8282\u3002\u6bcf\u4e00\u4e2aMEDIUMBLOB\u503c\u4f7f\u75283\u5b57\u8282\u957f\u5ea6\u7684\u524d\u7f00\u6307\u793a\u503c\u7684\u5927\u5c0f\u3002<\/li>\n<li>MEDIUMTEXT [CHARACTER SET charset_name] [COLLATE collation_name]\uff1a\u4e00\u4e2aMEDIUMTEXT\u5217\u7684\u6700\u5927\u957f\u5ea6\u662f16777215(2<sup>24 <\/sup>-1)\u5b57\u7b26\u3002\u5982\u679c\u5305\u542b\u591a\u5b57\u8282\u5b57\u7b26\u5b9e\u9645\u5b57\u7b26\u6570\u8981\u5c11\u4e8e\u8fd9\u4e2a\u503c\u3002MEDIUMTEXT\u7684\u503c\u4f7f\u75283\u5b57\u8282\u957f\u5ea6\u7684\u524d\u7f00\u6307\u793a\u88ab\u5b58\u50a8\u503c\u7684\u5927\u5c0f\u3002<\/li>\n<li>LONGBLOB\uff1a\u6700\u5927\u957f\u5ea64,294,967,295 or 4GB (2<sup>32<\/sup> \u2212 1) \u5b57\u8282\u3002LONGBLOB\u7684\u6700\u5927\u6709\u6548\u957f\u5ea6\u4f9d\u8d56\u4e8e\u5728client\/server\u534f\u8bae\u4e2d\u914d\u7f6e\u7684\u6700\u5927\u5305\u5927\u5c0f\u548c\u5185\u5b58\u5927\u5c0f\u3002\u6bcf\u4e2aLONGBLOB\u7684\u503c\u4f7f\u75284\u5b57\u8282\u957f\u5ea6\u7684\u524d\u7f00\u6307\u793a\u88ab\u5b58\u50a8\u503c\u7684\u5927\u5c0f\uff08\u5355\u4f4d\u5b57\u8282\uff09\u3002<\/li>\n<li>LONGTEXT [CHARACTER SET charset_name][COLLATE collation_name]\uff1a\u6700\u5927\u957f\u5ea6 4,294,967,295 or 4GB (2<sup>32<\/sup> \u2212 1)\u5b57\u7b26\u3002\u5982\u679c\u5305\u542b\u591a\u5b57\u8282\u5b57\u7b26\u5b9e\u9645\u5b57\u7b26\u6570\u8981\u5c11\u4e8e\u8fd9\u4e2a\u503c\u3002LONGTEXT\u5217\u7684\u6709\u6548\u6700\u5927\u957f\u5ea6\u4f9d\u8d56\u4e8e\u5728client\/server\u534f\u8bae\u4e2d\u914d\u7f6e\u7684\u6700\u5927\u5305\u5927\u5c0f\u548c\u5185\u5b58\u5927\u5c0f\u3002\u6bcf\u4e2aLONGTEXT\u7684\u503c\u4f7f\u75284\u5b57\u8282\u957f\u5ea6\u7684\u524d\u7f00\u6307\u793a\u88ab\u5b58\u50a8\u503c\u7684\u5927\u5c0f\uff08\u5355\u4f4d\u5b57\u8282\uff09\u3002<\/li>\n<li>ENUM(&#8216;value1&#8217;, &#8216;value2&#8242;,&#8230;) [CHARACTER SET charset_name] [COLLATE collation_name]\uff1a\u679a\u4e3e\u503c\u3002\u53ea\u53ef\u4ee5\u6709\u4e00\u4e2a\u503c\u7684\u5b57\u7b26\u4e32\u5bf9\u8c61\uff0c\u8fd9\u4e2a\u503c\u53ef\u4ee5\u5728\u5217\u8868\u4e2d\u9009\u62e9\uff08&#8217;value1&#8217;, &#8216;value2&#8217;,&#8230;,NULL\u6216\u6307\u5b9a&#8221;\u9519\u8bef\u503c\u3002\uff09ENUM\u503c\u53ef\u4ee5\u5728\u5185\u90e8\u88ab\u63cf\u7ed8\u6210\u4e00\u4e2a\u6574\u6570\u3002ENUM\u5217\u6700\u5927\u53ef\u4ee5\u670965535\u4e2a\u4e0d\u540c\u5143\u7d20\uff08\u5b9e\u9645\u6781\u9650\u5c0f\u4e8e3000\uff09\u3002\u4e00\u4e2a\u8868\u6700\u591a\u53ef\u4ee5\u6709\u4e0d\u8d85\u8fc7255\u4e2aENUM\u548cSET\u5b9a\u4e49\u3002\uff08 A table can have no more than 255 unique element list definitions among its <a class=\"link\" title=\"11.4.4\u00a0The ENUM Type\" href=\"https:\/\/dev.mysql.com\/doc\/refman\/5.7\/en\/enum.html\"><code class=\"literal\">ENUM<\/code><\/a> and <a class=\"link\" title=\"11.4.5\u00a0The SET Type\" href=\"https:\/\/dev.mysql.com\/doc\/refman\/5.7\/en\/set.html\"><code class=\"literal\">SET<\/code><\/a> columns considered as a group.\uff09<\/li>\n<li>SET(&#8216;value1&#8217;, &#8216;value2&#8242;,&#8230;) [CHARACTER SET charset_name] [COLLATE collation_name]\uff1a\u6570\u636e\u96c6\u7c7b\u578b\u3002\u53ef\u4ee5\u67090\u4e2a\u6216\u591a\u4e2a\u503c\u7684\u5b57\u7b26\u4e32\u5bf9\u8c61\uff0c\u6bcf\u4e00\u4e2a\u88ab\u9009\u62e9\u7684\u503c\u5fc5\u987b\u662f\u5728\u5217\u8868\u4e2d\u7684\u503c\uff08&#8217;value1&#8217;,&#8217;value2&#8217;&#8230;\uff09\uff0c\u6570\u636e\u96c6\u7684\u503c\u5728\u5185\u90e8\u88ab\u63cf\u8ff0\u6210\u4e00\u4e2a\u6574\u6570\u3002\u4e00\u4e2a\u96c6\u5217\u6700\u591a\u53ef\u4ee5\u670964\u4e2a\u552f\u4e00\u6210\u5458\u3002\u4e00\u4e2a\u8868\u6700\u591a\u53ef\u4ee5\u6709\u4e0d\u8d85\u8fc7255\u4e2aENUM\u548cSET\u5b9a\u4e49\u3002<\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>https:\/\/dev.mysql.com\/doc\/refman\/5.7\/en\/string-type-overview.html \u5b57\u7b26\u4e32\u7c7b\u578b\u5217\u7684\u5b9a\u4e49\u53ef\u4ee5\u6307\u5b9a\u5b57&#8230;<\/p>\n<p class=\"read-more\"><a class=\"btn btn-default\" href=\"https:\/\/www.5x44.cn\/?p=991\"> 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-991","post","type-post","status-publish","format-standard","hentry","category-mysql"],"_links":{"self":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts\/991","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=991"}],"version-history":[{"count":9,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts\/991\/revisions"}],"predecessor-version":[{"id":1000,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=\/wp\/v2\/posts\/991\/revisions\/1000"}],"wp:attachment":[{"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=991"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=991"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.5x44.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=991"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}