<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[Snooda]]></title> 
<link>http://www.snooda.com/index</link> 
<description><![CDATA[Snooda's Blog]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[Snooda]]></copyright>
<item>
<link>http://www.snooda.com/read/</link>
<title><![CDATA[mysql的varchar和char长度的含义（中文长度）]]></title> 
<author>snooda &lt;admin@snooda.com&gt;</author>
<category><![CDATA[数据库]]></category>
<pubDate>Mon, 07 Dec 2015 11:22:14 +0000</pubDate> 
<guid>http://www.snooda.com/read/</guid> 
<description>
<![CDATA[ 
	&nbsp;&nbsp;&nbsp;&nbsp;mysql中经常用到的字段类型就是varchar和char。一般还会指定长度用来规定最长可以支持多长的内容。那么问题就来了。对于utf8字符集来讲。一个字符所占的空间是1-6字节不等的。那么varchar(100)是指的字节数还是字符数呢？<br/><br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;可以通过mysql官方文档来看：<br/>&nbsp;&nbsp;&nbsp;&nbsp;http://dev.mysql.com/doc/refman/5.0/en/char.html<br/>&nbsp;&nbsp;&nbsp;&nbsp;<br/><br/>The CHAR and VARCHAR types are declared with a length that indicates the maximum number of characters you want to store. For example, CHAR(30) can hold up to 30 characters.<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;即支持的是30个字符（characters），而不是30字节（bytes）<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;经测试，结果也是符合文档的。varchar(30)可以存储30个汉字<br/><br/><br/>&nbsp;&nbsp;&nbsp;&nbsp;附加问题：如果传入了超出长度的内容，会有什么结果。<br/><br/>If strict SQL mode is not enabled and you assign a value to a CHAR or VARCHAR column that exceeds the column's maximum length, the value is truncated to fit and a warning is generated.<br/><br/>&nbsp;&nbsp;&nbsp;&nbsp; 文档中提到。默认情况下会截断而不返回错误。如果需要返回错误，需要开启strict mode<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>Tags - <a href="http://www.snooda.com/tags/mysql/" rel="tag">mysql</a> , <a href="http://www.snooda.com/tags/varchar/" rel="tag">varchar</a>
]]>
</description>
</item><item>
<link>http://www.snooda.com/read/#blogcomment</link>
<title><![CDATA[[评论] mysql的varchar和char长度的含义（中文长度）]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://www.snooda.com/read/#blogcomment</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>