<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>海边拾贝 &#187; MySQL</title>
	<atom:link href="http://www.seebit.org/tag/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.seebit.org</link>
	<description>www.seebit.org</description>
	<lastBuildDate>Tue, 03 May 2011 16:03:52 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>MySQL中修理特殊不可见uft8字符</title>
		<link>http://www.seebit.org/2009/12/mysql-trim-special-utf8-character/</link>
		<comments>http://www.seebit.org/2009/12/mysql-trim-special-utf8-character/#comments</comments>
		<pubDate>Wed, 09 Dec 2009 00:35:09 +0000</pubDate>
		<dc:creator>Tony Zhu</dc:creator>
				<category><![CDATA[技术随笔]]></category>
		<category><![CDATA[MySQL]]></category>

		<guid isPermaLink="false">http://www.seebit.org/?p=259</guid>
		<description><![CDATA[工作中有一个中文字库表，是前辈从其他地方导入的。最近使用的时候发现有些词，比如“清白”，明明只有两个字，却只能用LIKE &#8216;%清白%&#8217;查出，直接=&#8217;清白&#8217;找不到。 第一反应，前后可能有空格。于是在PHPMyadmin中用MySQL的trim函数过滤了一下 update 字库 set Vocabulary = trim(Vocabulary) 但返回的affected rows数居然是0 可以肯定不知道是哪个UTF8不可见字符混了进去，直接看又看不见，想个办法让它显型。于是用到了MySQL的hex函数，把字符串的hex输出来对比一下： select hex('清白'), hex(Vocabulary), Vocabulary from 字库 where Vocabulary like '%清白%' 这下一眼就看出正常字符串前多了个hex为“EFBBBF”的字符，将这个十六进制数扔到windows自带的计算器中换成十进制为15711167，真凶确定，删之： update 字库 set Vocabulary = REPLACE(Vocabulary, char(15711167),'') affected rows居然有3000多，怪不得感觉老有些常用词检索不出来呢…… 保险起见，再用了一次trim update 字库 set Vocabulary = trim(Vocabulary) 又冒出3个affected rows。 工作继续。]]></description>
			<content:encoded><![CDATA[<p>工作中有一个中文字库表，是前辈从其他地方导入的。最近使用的时候发现有些词，比如“清白”，明明只有两个字，却只能用LIKE &#8216;%清白%&#8217;查出，直接=&#8217;清白&#8217;找不到。</p>
<p>第一反应，前后可能有空格。于是在PHPMyadmin中用MySQL的trim函数过滤了一下</p>
<pre>update 字库 set Vocabulary = trim(Vocabulary)</pre>
<p>但返回的affected rows数居然是0</p>
<p>可以肯定不知道是哪个UTF8不可见字符混了进去，直接看又看不见，想个办法让它显型。于是用到了MySQL的hex函数，把字符串的hex输出来对比一下：</p>
<pre>select hex('清白'), hex(Vocabulary), Vocabulary from 字库 where Vocabulary like '%清白%'</pre>
<p>这下一眼就看出正常字符串前多了个hex为“EFBBBF”的字符，将这个十六进制数扔到windows自带的计算器中换成十进制为15711167，真凶确定，删之：</p>
<pre>update 字库 set Vocabulary = REPLACE(Vocabulary, char(15711167),'')</pre>
<p>affected rows居然有3000多，怪不得感觉老有些常用词检索不出来呢……</p>
<p>保险起见，再用了一次trim</p>
<pre>update 字库 set Vocabulary = trim(Vocabulary)</pre>
<p>又冒出3个affected rows。</p>
<p>工作继续。</p>
]]></content:encoded>
			<wfw:commentRss>http://www.seebit.org/2009/12/mysql-trim-special-utf8-character/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

