<?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>ROY&#039;S BLOG</title>
	<atom:link href="http://roygu.com/feed" rel="self" type="application/rss+xml" />
	<link>http://roygu.com</link>
	<description>偏执狂：学习不分春夏秋冬，贵在坚持；奋斗可分鼠雀鲲鹏，人生贵搏。</description>
	<lastBuildDate>Sat, 28 Apr 2012 04:12:50 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>优化 MySQL 语句的十个建议</title>
		<link>http://roygu.com/2012/04/mysql/10-tips-for-optimizing-mysql-queries-that-dont-suck.html</link>
		<comments>http://roygu.com/2012/04/mysql/10-tips-for-optimizing-mysql-queries-that-dont-suck.html#comments</comments>
		<pubDate>Sat, 28 Apr 2012 03:21:30 +0000</pubDate>
		<dc:creator>校长</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[optimization]]></category>

		<guid isPermaLink="false">http://roygu.com/?p=1610</guid>
		<description><![CDATA[原文链接：20bits.com   编译：伯乐在线?- 唐小娟 Jaslabs的Justin Silverton列出了十条有关优化MySQL查询的语句，我不得不对此发表言论，因为这个清单非常非常糟糕。另外一个Mike也同样意识到了。所以在这个博客中，我要做两件事情，第一，指出为什么这个清单很糟糕，第二，列出我的清单，希望我的比较好些。继续看吧，无畏的读者们！ (译者注：作者借这个题目反讽另一篇同名的文章) 为什么那个清单很糟糕 1.他的力气没使对地方 我们要遵循的一个准则就是如果你要优化代码时，应该先找出瓶颈在哪。然而Silverton先生的力气没有用对地方。我认为60%的优化是基于清楚 理解SQL和数据库基础的。你需要知道join和子查询的区别，列索引，以及如何将数据规范化等等。另外的35%的优化是需要清楚数据库选择时的性能表 现，例如COUNT(*)可能很快也可能很慢，要看你选用什么数据库引擎。还有一些其他要考虑的因素，例如数据库在什么时候不用缓存，什么时候存在硬盘上 而不存在内存中，什么时候数据库创建临时表等等。剩下的5%就很少会有人碰到了，但Silverton先生恰好在这上面花了大量的时间。我从来就没用过 SQL_SAMLL_RESULT。 2.很好的问题，但是很糟糕的解决方法 Silverton先生提出了一些很好的问题。MySQL针对长度可变的列如TEXT或BLOB，将会使用动态行格式(dynamic row format)，这意味着排序将在硬盘上进行。我们的方法不是要回避这些数据类型，而是将这些数据类型从原来的表中分离开，放入另外一个表中。下面的 schema可以说明这个想法： 1 2 3 4 5 6 7 8 9 10 11 12 CREATE TABLE posts (      id int UNSIGNED NOT NULL AUTO_INCREMENT,      author_id int UNSIGNED NOT NULL,      created &#8230; <a href="http://roygu.com/2012/04/mysql/10-tips-for-optimizing-mysql-queries-that-dont-suck.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>原文链接：<a href="http://20bits.com/articles/10-tips-for-optimizing-mysql-queries-that-dont-suck/" rel="nofollow" target="_blank">20bits.com </a>  编译：<a href="http://www.jobbole.com/">伯乐</a>在线?- <a href="http://blog.jobbole.com/13876/" target="_blank">唐小娟</a></p>
<p>Jaslabs的Justin Silverton列出了十条有关优化MySQL查询的语句，我不得不对此发表言论，因为这个清单非常非常糟糕。另外一个Mike也同样意识到了。所以在这个博客中，我要做两件事情，第一，指出为什么这个清单很糟糕，第二，列出我的清单，希望我的比较好些。继续看吧，无畏的读者们！</p>
<p>(译者注：作者借这个题目反讽另一篇同名的文章)</p>
<p><strong>为什么那个清单很糟糕</strong></p>
<p><strong>1.他的力气没使对地方</strong></p>
<p>我们要遵循的一个准则就是如果你要优化代码时，应该先找出瓶颈在哪。然而Silverton先生的力气没有用对地方。我认为60%的优化是基于清楚 理解SQL和数据库基础的。你需要知道join和子查询的区别，列索引，以及如何将数据规范化等等。另外的35%的优化是需要清楚数据库选择时的性能表 现，例如COUNT(*)可能很快也可能很慢，要看你选用什么数据库引擎。还有一些其他要考虑的因素，例如数据库在什么时候不用缓存，什么时候存在硬盘上 而不存在内存中，什么时候数据库创建临时表等等。剩下的5%就很少会有人碰到了，但Silverton先生恰好在这上面花了大量的时间。我从来就没用过 SQL_SAMLL_RESULT。</p>
<p><strong>2.很好的问题，但是很糟糕的解决方法</strong></p>
<p>Silverton先生提出了一些很好的问题。MySQL针对长度可变的列如TEXT或BLOB，将会使用动态行格式(dynamic row format)，这意味着排序将在硬盘上进行。我们的方法不是要回避这些数据类型，而是将这些数据类型从原来的表中分离开，放入另外一个表中。下面的 schema可以说明这个想法：</p>
<div>
<div id="highlighter_123700">
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div>7</div>
<div>8</div>
<div>9</div>
<div>10</div>
<div>11</div>
<div>12</div>
</td>
<td>
<div>
<div><code>CREATE TABLE posts (</code></div>
<div><code>    </code> <code>id </code><code>int</code> <code>UNSIGNED NOT NULL AUTO_INCREMENT,</code></div>
<div><code>    </code> <code>author_id </code><code>int</code> <code>UNSIGNED NOT NULL,</code></div>
<div><code>    </code> <code>created timestamp NOT NULL,</code></div>
<div><code>    </code> <code>PRIMARY KEY(id)</code></div>
<div><code>);</code></div>
<div></div>
<div><code>CREATE TABLE posts_data (</code></div>
<div><code>    </code> <code>post_id </code><code>int</code> <code>UNSIGNED NOT NULL.</code></div>
<div><code>    </code> <code>body text,</code></div>
<div><code>    </code> <code>PRIMARY KEY(post_id)</code></div>
<div><code>);</code></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<p><strong>3. 有点匪夷所思……</strong></p>
<p>他的许多建议都是让人非常吃惊的，譬如“移除不必要的括号”。你这样写SELECT * FROM posts WHERE (author_id = 5 AND published = 1)，还是这样写SELECT * FROM posts WHERE author_id = 5 AND published = 1 ，都不重要。任何比较好的DBMS都会自动进行识别做出处理。这种细节就好像C语言中是i++快些还是++i快些。真的，如果你把精力都花在这上面了，那就不用写代码了。</p>
<p><img src="http://blog.jobbole.com/wp-content/uploads/2012/03/mysql.jpg" alt="mysql" /></p>
<p><strong>我的列表</strong></p>
<p>看看我的列表是不是更好吧。我先从最普遍的开始。</p>
<p><strong>1.建立基准，建立基准，建立基准！</strong></p>
<p>如果需要做决定的话，我们需要数据说话。什么样的查询是最糟的？瓶颈在哪？我什么情况下会写出糟糕的查询？基准测试可以让你模拟高压情况，然后借助 性能测评工具，可以让你发现数据库配置中的错误。这样的工具有supersmack, ab, SysBench。这些工具可以直接测试你的数据库(譬如supersmack)，或者模拟网络流量（譬如ab）。</p>
<p><strong>2.性能测试，性能测试，性能测试!</strong></p>
<p>那么，当你能够建立一些高压情况之后，你需要找出配置中的错误。这就是性能测评工具可以帮你做的了。它可以帮你发现配置中的瓶颈，不论是在内存中，CPU中，网络中，硬盘I/O，或者是以上皆有。</p>
<p>你要做的第一件事就是开启慢查询日志(slow query log)，装上mtop。这样你就能获取那些恶意的入侵者的信息了。有需要运行10秒的查询语句正在破坏你的应用程序吗？这些家伙会展示给你看他的查询语句是怎么写的。</p>
<p>在你发现那些很慢的查询语句后，你需要用MySQL自带的工具，如EXPLAIN，SHOW STATUS，SHOW PROCESSLIST。它们会告诉你资源都消耗在哪了，查询语句的缺陷在哪，譬如一个有三次join子查询的查询语句是否在内存中进行排序，还是在硬盘 上进行。当然你也应该使用测评工具如top，procinfo，vmstat等等获取更多系统性能信息。</p>
<p><strong>3.减小你的schema</strong></p>
<p>在你开始写查询语句之前，你需要设计schema。记住将一个表装入内存所需要的空间大概是行数*一行的大小。除非你觉得世界上的每个人都会在你的 网站注册2兆8000亿次的话，否则你不需要采用BITINT作为你的user_id。同样的，如果一个文本列是固定大小的话（譬如US邮编，通常 是”XXXXX-XXXX”的形式），采用VARCHAR的话会给每行增加多余的字节。</p>
<p>有些人对数据库规范化不以为意，他们说这样会形成相当复杂的schema。然而适当的规范化会减少化冗余数据。（适当的规范化）就意味着牺牲少许性 能，换取整体上更少的footprint，这种性能换取内存在计算机科学中是很常见的。最好的方法是IMO，就是开始先规范化，之后如果性能需要的话，再 反规范化。你的数据库将会更逻辑化，你也不用过早的进行优化。（译者注，这一段我不是很理解，可能翻译错了，欢迎纠正。）</p>
<p><strong>4.拆分你的表</strong></p>
<p>通常有些表只有一些列你是经常需要更新的。例如对于一个博客，你需要在许多不同地方显示标题（如最近的文章列表），只在某个特定页显示概要或者全文。水平垂直拆分是很有帮助的：</p>
<div>
<div id="highlighter_997809">
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div>7</div>
<div>8</div>
<div>9</div>
<div>10</div>
<div>11</div>
<div>12</div>
<div>13</div>
<div>14</div>
</td>
<td>
<div>
<div><code>CREATE TABLE posts (</code></div>
<div><code>    </code> <code>id </code><code>int</code> <code>UNSIGNED NOT NULL AUTO_INCREMENT,</code></div>
<div><code>    </code> <code>author_id </code><code>int</code> <code>UNSIGNED NOT NULL,</code></div>
<div><code>    </code> <code>title </code><code>var</code> <code>char(</code> <code>128</code> <code>),</code></div>
<div><code>    </code> <code>created timestamp NOT NULL,</code></div>
<div><code>    </code> <code>PRIMARY KEY(id)</code></div>
<div><code>);</code></div>
<div></div>
<div><code>CREATE TABLE posts_data (</code></div>
<div><code>    </code> <code>post_id </code><code>int</code> <code>UNSIGNED NOT NULL,</code></div>
<div><code>    </code> <code>teaser text,</code></div>
<div><code>    </code> <code>body text,</code></div>
<div><code>    </code> <code>PRIMARY KEY(post_id)</code></div>
<div><code>);</code></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<p>上面的schema是对读数据进行的优化。经常要访问的数据存在一个表中，那些不经常访问的数据放在另一个。被拆分后，不经常访问的数据占据更少的 内存。你也可以优化写数据，经常更新的数据放在一个表，不经常更新的放在另一个表。这可以使缓存更高效，因为MySQL不需要让没有更新过的数据移出缓 存。</p>
<p><strong>5.不要过度使用artificial primary key</strong></p>
<p>artificial primary key非常棒，因为他们使得schema更少的变化。如果我们将地理信息存在以美国邮编为基础的表中，如果邮编系统突然改变了，那我们就会有大麻烦了。另 一方面，采用natural key有时候也很棒，譬如我们需要join多对多的关系表时，我们不应该这样：</p>
<div>
<div id="highlighter_333251">
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
<div>7</div>
</td>
<td>
<div>
<div><code>CREATE TABLE posts_tags (</code></div>
<div><code>    </code> <code>relation_id </code><code>int</code> <code>UNSIGNED NOT NULL AUTO_INCREMENT,</code></div>
<div><code>    </code> <code>post_id </code><code>int</code> <code>UNSIGNED NOT NULL,</code></div>
<div><code>    </code> <code>tag_id </code><code>int</code> <code>UNSIGNED NOT NULL,</code></div>
<div><code>    </code> <code>PRIMARY KEY(relation_id),</code></div>
<div><code>    </code> <code>UNIQUE INDEX(post_id, tag_id)</code></div>
<div><code>);</code></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<p>artificial key完全是多余的，而且post-tag关系的数量将会受到整形数据的系统最大值的限制。</p>
<div>
<div id="highlighter_76879">
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
</td>
<td>
<div>
<div><code>CREATE TABLE posts_tags (</code></div>
<div><code>    </code> <code>post_id </code><code>int</code> <code>UNSIGNED NOT NULL,</code></div>
<div><code>    </code> <code>tag_id </code><code>int</code> <code>UNSIGNED NOT NULL,</code></div>
<div><code>    </code> <code>PRIMARY KEY(post_id, tag_id)</code></div>
<div><code>);</code></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<p><strong>6.学习索引</strong></p>
<p>你选择的索引的好坏很重要，不好的话可能破坏数据库。对那些还没有在数据库学习很深入的人来说，索引可以看作是就是hash排序。例如如果我们用查询语句SELECT * FROM users WHERE last_name = ‘Goldstein’，而last_name没有索引的话，那么DBMS将会查询每一行，看看是否等于“Goldstein”。索引通常是B-tree（还有其他的类型），可以加快比较的速度。</p>
<p>你需要给你要select,group,order,join的列加上索引。显然每个索引所需的空间正比于表的行数，所以越多的索引将会占用更多的 内存。而且写数据时，索引也会有影响，因为每次写数据时都会更新对应的索引。你需要取一个平衡点，取决每个系统和实施代码的需要。</p>
<p><strong>7.SQL不是C</strong></p>
<p>C是经典的过程语言，对于一个程序员来说，C语言也是个陷阱，使你错误的以为SQL也是一种过程语言（当然SQL也不是功能语言也不是面向对象的）。你不要想象对数据进行操作，而是要想象有一组数据，以及它们之间的关系。经常使用子查询时会出现错误的用法。</p>
<div>
<div id="highlighter_103846">
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
<div>6</div>
</td>
<td>
<div>
<div><code>SELECT a.id,</code></div>
<div><code>    </code> <code>(SELECT MAX(created)</code></div>
<div><code>    </code> <code>FROM posts</code></div>
<div><code>    </code> <code>WHERE author_id = a.id)</code></div>
<div><code>AS latest_post</code></div>
<div><code>FROM authors a</code></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<p>因为这个子查询是耦合的，子查询要使用外部查询的信息，我们应该使用join来代替。</p>
<div>
<div id="highlighter_675392">
<table border="0" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<td>
<div>1</div>
<div>2</div>
<div>3</div>
<div>4</div>
<div>5</div>
</td>
<td>
<div>
<div><code>SELECT a.id, MAX(p.created) AS latest_post</code></div>
<div><code>FROM authors a</code></div>
<div><code>INNER JOIN posts p</code></div>
<div><code>    </code> <code>ON (a.id = p.author_id)</code></div>
<div><code>GROUP BY a.id</code></div>
</div>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<p><strong>8.理解你的引擎</strong></p>
<p>MySQL有两种存储引擎：MyISAM和InnoDB。它们分别有自己的性能特点和考虑因素。总体来讲，MyISAM适合读数据很多的情况，InnoDB适合写数据很多的情况，但也有很多情况下正好相反。最大的区别是它们如何处理COUNT函数。</p>
<p>MyISAM缓存有表meta-data，如行数。这就意味着，COUNT(*)对于一个结构很好的查询是不需要消耗多少资源的。然后对于 InnoDB来说，就没有这种缓存。举个例子，我们要对一个查询来分页，假设你有这样一个语句SELECT * FROM users LIMIT 5,10，而运行SELECT COUNT(*) FROM users LIMIT 5,10 时，对于MyISAM很快完成，而对InnoDB就需要和第一个语句相同的时间。MySQL有个SQL_CALC_FOUND_ROWS选项，可以告诉 InnoDB运行查询语句时就计算行数，之后再从SELECT FOUND_ROWS()来获取。这是MySQL特有的。但使用InnoDB有时候是非常必要的，你可以获得一些功能（如行锁定，stord procedure等）。</p>
<p><strong>9.MySQL特定的快捷键</strong></p>
<p>MySQL提供了许多扩展，方便使用。譬如INSERT … SELECT, INSERT … ON DUPLICATE KEY UPDATE, 以及REPLACE。</p>
<p>我能用到它们时是毫不犹豫的，因为它们很方便，能在许多情况下发挥不错的效果。但是MySQL也有一些危险的关键字，应该少用。例如INSERT DELAYED,它告诉MySQL不需要立即插入数据(例如在写日志的时候)。但问题是如果在很高数据量的情况下，插入可能会被无限期延迟，导致插入队列 爆满。你也可以使用MySQL的索引提示来指出哪些索引是需要使用的。MySQL大部分时间运行是不错的，但如果schema设计不好的话或语句写得不好 的话，MySQL的表现可能很糟糕。</p>
<p><strong>10.到这里为止吧</strong></p>
<p>最后，如果你关心MySQL性能优化的话，请阅读Peter Zaitsev的关于<a href="http://www.mysqlperformanceblog.com/" rel="nofollow" target="_blank">MySQL性能</a>的博客，他写了许多关于数据库管理和优化的博客。</p>
]]></content:encoded>
			<wfw:commentRss>http://roygu.com/2012/04/mysql/10-tips-for-optimizing-mysql-queries-that-dont-suck.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL主从配置</title>
		<link>http://roygu.com/2012/04/mysql/mysql-set-up-master-slave-replication.html</link>
		<comments>http://roygu.com/2012/04/mysql/mysql-set-up-master-slave-replication.html#comments</comments>
		<pubDate>Fri, 27 Apr 2012 04:24:56 +0000</pubDate>
		<dc:creator>校长</dc:creator>
				<category><![CDATA[mysql]]></category>
		<category><![CDATA[master]]></category>
		<category><![CDATA[replication]]></category>
		<category><![CDATA[slave]]></category>

		<guid isPermaLink="false">http://roygu.com/?p=1588</guid>
		<description><![CDATA[在开始配置之前，我们先说说为什么要用数据库主从复制吧。 1. 分散负载：用主从复制最大的好处之一就是由主库执行所有插入操作，由从库承担起大部分的查询操作。简单地通过主从就能极大地提速你的应用。 2. 用从库备份数据：这个优点常常被遗忘。使用从库备份不会影响你的网站工作，特别是当数据量大到G级别的时候，由备份引起的锁表引导致网站延迟响应。更严重地可能会导致网站瞬间瘫痪。如果在从库上做这些就无关紧要了，你甚至可以停掉某个从库，并且暴力的复制var目录。 假设你有两台数据库服务器，计划如下部署： Master server ip: 10.0.0.1 Slave server ip: 10.0.0.2 Slave username: slaver Slave pw: 123456 Your data directory is: /usr/local/mysql/var/ 主库配置文件my.cnf [mysqld]节下面加上： 从库配置文件my.cnf [mysqld]节下面加上 # changes made to do slave server-id = 2 relay-log = &#8230; <a href="http://roygu.com/2012/04/mysql/mysql-set-up-master-slave-replication.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>在开始配置之前，我们先说说为什么要用数据库主从复制吧。<br />
1. 分散负载：用主从复制最大的好处之一就是由主库执行所有插入操作，由从库承担起大部分的查询操作。简单地通过主从就能极大地提速你的应用。<br />
2. 用从库备份数据：这个优点常常被遗忘。使用从库备份不会影响你的网站工作，特别是当数据量大到G级别的时候，由备份引起的锁表引导致网站延迟响应。更严重地可能会导致网站瞬间瘫痪。如果在从库上做这些就无关紧要了，你甚至可以停掉某个从库，并且暴力的复制var目录。</p>
<p>假设你有两台数据库服务器，计划如下部署：</p>
<blockquote><p>
Master server ip: 10.0.0.1<br />
Slave server ip: 10.0.0.2<br />
Slave username: slaver<br />
Slave pw: 123456<br />
Your data directory is: /usr/local/mysql/var/
</p></blockquote>
<p>主库配置文件my.cnf [mysqld]节下面加上：<br />
<pre class="src"><br />
# changes made to do master<br />
server-id = 1<br />
relay-log = /usr/local/mysql/var/mysql-relay-bin<br />
relay-log-index = /usr/local/mysql/var/mysql-relay-bin.index<br />
log-error = /usr/local/mysql/var/mysql.err<br />
master-info-file = /usr/local/mysql/var/mysql-master.info<br />
relay-log-info-file = /usr/local/mysql/var/mysql-relay-log.info<br />
datadir = /usr/local/mysql/var<br />
log-bin = /usr/local/mysql/var/mysql-bin<br />
# end master<br />
</pre></p>
<p>从库配置文件my.cnf [mysqld]节下面加上<br />
# changes made to do slave<br />
server-id = 2<br />
relay-log = /usr/local/mysql/var/mysql-relay-bin<br />
relay-log-index = /usr/local/mysql/var/mysql-relay-bin.index<br />
log-error = /usr/local/mysql/var/mysql.err<br />
master-info-file = /usr/local/mysql/var/mysql-master.info<br />
relay-log-info-file = /usr/local/mysql/var/mysql-relay-log.info<br />
datadir = /usr/local/mysql/var<br />
# end slave setup</p>
<p>在主库上创建用户：<br />
<pre class="src"><br />
mysql> grant replication slave on *.* to &#8216;slaver&#8217;@&#8217;10.0.0.2&#8242; identified by &#8217;123456&#8242;;<br />
</pre></p>
<blockquote><p>值得注意的是，grant replication slave是全局操作，不能对单个库操作。</p></blockquote>
<p>使用mysqldump工具，导出主库数据，配好之前先手动同步主从库的数据：</p>
<blockquote><p>
mysqldump -u root &#8211;all-databases &#8211;single-transaction &#8211;master-data=1 > masterdump.sql
</p></blockquote>
<p>然后在从库中导入：<br />
<pre class="src">mysql < masterdump.sql</pre></p>
<p>接下来要告库从库去复制哪个主库，以及连接主库的信息：<br />
<pre class="src">mysql> CHANGE MASTER TO MASTER_HOST=&#8217;10.0.0.1&#8242;, MASTER_USER=&#8217;slaver&#8217;, MASTER_PASSWORD=&#8217;123456&#8242;;</pre></p>
<p>紧接着开启从库同步：<br />
<pre class="src">mysql> start slave;</pre></p>
<p>可以通过下命的命令查看同步状态：<br />
<pre class="src">mysql> show slave status\G</pre></p>
<p>最后执行完成之后，刚添加的用户出现怪异现像，任何帐号都能登陆而且不用密码，最后百思不得其解，大量搜索之后发现“重启MySQL即可”，然后和然后的然后，就可以了。。。</p>
]]></content:encoded>
			<wfw:commentRss>http://roygu.com/2012/04/mysql/mysql-set-up-master-slave-replication.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>MySQL:在一次查询中进行批量更新</title>
		<link>http://roygu.com/2012/04/mysql/mysql-multi-update-in-one-query.html</link>
		<comments>http://roygu.com/2012/04/mysql/mysql-multi-update-in-one-query.html#comments</comments>
		<pubDate>Wed, 25 Apr 2012 01:42:23 +0000</pubDate>
		<dc:creator>校长</dc:creator>
				<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://roygu.com/?p=1584</guid>
		<description><![CDATA[为了提高工作效率以及节省人力时间，批量操作在现在的应用中越来越常见。 对于数据库来说，无非是“插删改查”，“查询”和“删除“自然不在话下，但是”删“的话我们一般遵循单查询批量1000这个上限，再多可能会影响数据库同步延迟。 而批量”插入“则可以通过拼SQL方式实现，即： 当然，我们要限制单条SQL的大小，一般来说10Ｍ吧。 但是对于批量“更新”呢？能不能单查询批量更新（这里的批量更新指的是Where之后只有单条结果的情况）呢？ 下面来看看批量“更新”的几种方案： 使用INSERT ... ON DUPLICATE KEY UPDATE 这种方法倒是简单，但是官方文档有提示在Multi Unique Index的时候慎用，官方文档原话如下： In general, you should try to avoid using an ON DUPLICATE KEY clause on tables with multiple unique indexes. 使用MySQL的Case语句,原型如下： 在更新时则这么用： 这种方式太过复杂，我想谁也不会在代码中这么用，所以不推荐使用。。。 新建临时表，把新数据放在临时表中，然后再逐条更新，示例代码（PHP）如下： 总结一下：对于少量的更新，我们仍将使用单查询更新一条记录的方式（指的是根据Unique字段查询的单条结果）。如果更新数据大到某张表（百万数据量）的一半时，我们将使用临时表方案，也就是这里说的第三种方案。]]></description>
			<content:encoded><![CDATA[<p>为了提高工作效率以及节省人力时间，批量操作在现在的应用中越来越常见。</p>
<p>对于数据库来说，无非是“插删改查”，“查询”和“删除“自然不在话下，但是”删“的话我们一般遵循单查询批量<code>1000</code>这个上限，再多可能会影响数据库同步延迟。</p>
<p>而批量”插入“则可以通过拼SQL方式实现，即：<br />
<pre class="src"><br />
INSERT INTO tbl_name (a,b,c) VALUES(1,2,3),(4,5,6),(7,8,9);<br />
</pre><br />
当然，我们要限制单条SQL的大小，一般来说10Ｍ吧。</p>
<p>但是对于批量“更新”呢？能不能单查询批量更新（这里的批量更新指的是<code>Where</code>之后只有单条结果的情况）呢？ 下面来看看批量“更新”的几种方案：</p>
<ol>
<li>使用<code>INSERT ... ON DUPLICATE KEY UPDATE</code><br />
<pre class="src"><br />
INSERT INTO table (id,Col1,Col2) VALUES (1,1,1),(2,2,3),(3,9,3),(4,10,12)<br />
ON DUPLICATE KEY UPDATE Col1=VALUES(Col1),Col2=VALUES(Col2);<br />
</pre><br />
这种方法倒是简单，但是官方文档有提示在Multi Unique Index的时候慎用，官方文档原话如下：</p>
<blockquote><p>In general, you should try to avoid using an ON DUPLICATE KEY clause on tables with multiple unique indexes. </p></blockquote>
</li>
<li>使用MySQL的Case语句,原型如下：<br />
<pre class="src"><br />
CASE case_value<br />
    WHEN when_value THEN statement_list<br />
    [WHEN when_value THEN statement_list] &#8230;<br />
    [ELSE statement_list]<br />
END CASE<br />
</pre></p>
<p>在更新时则这么用：<br />
<pre class="src"><br />
UPDATE table SET Col1 = CASE id<br />
                          WHEN 1 THEN 1<br />
                          WHEN 2 THEN 2<br />
                          WHEN 4 THEN 10<br />
                          ELSE Col1<br />
                        END CASE,<br />
                 Col2 = CASE id<br />
                          WHEN 3 THEN 3<br />
                          WHEN 4 THEN 12<br />
                          ELSE Col2<br />
                       END CASE<br />
             WHERE id IN (1, 2, 3, 4);<br />
</pre><br />
这种方式太过复杂，我想谁也不会在代码中这么用，所以不推荐使用。。。
</li>
<li>新建临时表，把新数据放在临时表中，然后再逐条更新，示例代码（PHP）如下：<br />
<pre class="src"><br />
// Reorder items<br />
function update_items_tempdb(&#038;$items)<br />
{<br />
    shuffle($items);<br />
    $table_name = uniqid(&#8216;tmp_test_&#8217;);<br />
    $sql = &#8220;CREATE TEMPORARY TABLE `$table_name` (&#8221;<br />
        .&#8221;  `id` int(10) unsigned NOT NULL AUTO_INCREMENT&#8221;<br />
        .&#8221;, `position` int(10) unsigned NOT NULL&#8221;<br />
        .&#8221;, PRIMARY KEY (`id`)&#8221;<br />
        .&#8221;) ENGINE = MEMORY&#8221;;<br />
    query($sql);<br />
    $i = 0;<br />
    $sql = &#8221;;<br />
    foreach ($items as &#038;$item)<br />
    {<br />
        $item->position = $i++;<br />
        $sql .= ($sql ? &#8216;, &#8216; : &#8221;).&#8221;({$item->id}, {$item->position})&#8221;;<br />
    }<br />
    if ($sql)<br />
    {<br />
        query(&#8220;INSERT INTO `$table_name` (id, position) VALUES $sql&#8221;);<br />
        $sql = &#8220;UPDATE `test`, `$table_name` SET `test`.position = `$table_name`.position&#8221;<br />
            .&#8221; WHERE `$table_name`.id = `test`.id&#8221;;<br />
        query($sql);<br />
    }<br />
    query(&#8220;DROP TABLE `$table_name`&#8221;);<br />
}<br />
</pre>
</ol>
<p>总结一下：对于少量的更新，我们仍将使用单查询更新一条记录的方式（指的是根据Unique字段查询的单条结果）。如果更新数据大到某张表（百万数据量）的一半时，我们将使用临时表方案，也就是这里说的第三种方案。</p>
]]></content:encoded>
			<wfw:commentRss>http://roygu.com/2012/04/mysql/mysql-multi-update-in-one-query.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Install virtualbox 4.1.8 OSE on Slackware 13.37 X86_64</title>
		<link>http://roygu.com/2012/04/linux/install-virtualbox-4-1-8-ose-on-slackware-13-37-x86_64.html</link>
		<comments>http://roygu.com/2012/04/linux/install-virtualbox-4-1-8-ose-on-slackware-13-37-x86_64.html#comments</comments>
		<pubDate>Mon, 16 Apr 2012 12:08:37 +0000</pubDate>
		<dc:creator>校长</dc:creator>
				<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://roygu.com/?p=1578</guid>
		<description><![CDATA[在Linux系统上编译安装软件总是记忆深刻的，因为这个过程往往是繁杂而痛苦的。我有两台电脑，一台式机一本本，台式机系统是Slackware 13.37 X86_64 ,本本系统是Windows 7，因为工作原因要用到Baidu Hi，Outlook，Lync等Windows专有软件，所以一直在两台电脑之前切来切去，一直感觉很麻烦，一直想在台式机上装一个虚拟机运行Win 7。今天下午终于腾出时间在我的Slackware上装好virtualbox了。现在把过程记录下来，在Slackware下面装软件可以说是幸福的，因为它有像freebsd一样的包管理系统。 1. 先到这里下载virtualbox http://slackbuilds.org/repository/13.37/system/virtualbox/ ，别急着动手且看下一步 2. 依赖iasl，所以先安装ACPICA http://slackbuilds.org/repository/13.37/development/acpica/ 3. virtualbox需要32位的库文件支持，而我装的是纯64位版的，所以需要安装32位的库文件：http://connie.slackware.com/~alien/multilib/13.37/ 把相应的*.txz下载下来并用upgradepkg &#8211;install-new *.txz安装 4. 依赖jdk，所以还要安装jdk，我装的是jdk-6u25 5. 最后安装virtualbox，成功后别急着运行 6. virtualbox运行还依赖virtualbox-kernel http://slackbuilds.org/repository/13.37/system/virtualbox-kernel/ ,装完这个重启便可 注意：slackbuilds.org站上找到包后，要下载Source Download列表中的每一个文件和Slack Build文件，否则会编译失败，编译成功后会生成/tmp/foo.tgz文件（slackware的包文件)，接着用installpkg foo.tgz便可成功安装。以上每步我都有生成包文件，如果环境与我一致，应该可以通用。 VirtualBox在安装了增强包之后就像打了鸡血一样，拖动窗口也不卡了，还可以和宿主机共享数据空间，还可以和宿主机共享粘贴板，并且分辩率随窗口大小而变化，真心感觉不错，赞一个！！！]]></description>
			<content:encoded><![CDATA[<p>在Linux系统上编译安装软件总是记忆深刻的，因为这个过程往往是繁杂而痛苦的。我有两台电脑，一台式机一本本，台式机系统是Slackware 13.37 X86_64 ,本本系统是Windows 7，因为工作原因要用到Baidu Hi，Outlook，Lync等Windows专有软件，所以一直在两台电脑之前切来切去，一直感觉很麻烦，一直想在台式机上装一个虚拟机运行Win 7。今天下午终于腾出时间在我的Slackware上装好virtualbox了。现在把过程记录下来，在Slackware下面装软件可以说是幸福的，因为它有像freebsd一样的包管理系统。</p>
<p>1. 先到这里下载virtualbox <a href="http://slackbuilds.org/repository/13.37/system/virtualbox/" title="virtualbox">http://slackbuilds.org/repository/13.37/system/virtualbox/</a> ，别急着动手且看下一步<br />
2. 依赖iasl，所以先安装ACPICA <a href="http://slackbuilds.org/repository/13.37/system/virtualbox/" title="acpica">http://slackbuilds.org/repository/13.37/development/acpica/</a><br />
3. virtualbox需要32位的库文件支持，而我装的是纯64位版的，所以需要安装32位的库文件：<a href="http://connie.slackware.com/~alien/multilib/13.37/" title="multilib">http://connie.slackware.com/~alien/multilib/13.37/</a><br />
把相应的*.txz下载下来并用upgradepkg &#8211;install-new *.txz安装<br />
4. 依赖jdk，所以还要安装jdk，我装的是jdk-6u25<br />
5. 最后安装virtualbox，成功后别急着运行<br />
6. virtualbox运行还依赖virtualbox-kernel <a href="http://slackbuilds.org/repository/13.37/system/virtualbox-kernel/" title="virtualbox-kernel">http://slackbuilds.org/repository/13.37/system/virtualbox-kernel/</a> ,装完这个重启便可</p>
<p>注意：slackbuilds.org站上找到包后，要下载Source Download列表中的每一个文件和Slack Build文件，否则会编译失败，编译成功后会生成/tmp/foo.tgz文件（slackware的包文件)，接着用installpkg foo.tgz便可成功安装。以上每步我都有生成包文件，如果环境与我一致，应该可以通用。</p>
<p>VirtualBox在安装了增强包之后就像打了鸡血一样，拖动窗口也不卡了，还可以和宿主机共享数据空间，还可以和宿主机共享粘贴板，并且分辩率随窗口大小而变化，真心感觉不错，赞一个！！！</p>
]]></content:encoded>
			<wfw:commentRss>http://roygu.com/2012/04/linux/install-virtualbox-4-1-8-ose-on-slackware-13-37-x86_64.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>php multi-thread</title>
		<link>http://roygu.com/2012/03/php/php-multi-thread.html</link>
		<comments>http://roygu.com/2012/03/php/php-multi-thread.html#comments</comments>
		<pubDate>Mon, 19 Mar 2012 07:28:54 +0000</pubDate>
		<dc:creator>校长</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[multi-thread]]></category>

		<guid isPermaLink="false">http://roygu.com/?p=1574</guid>
		<description><![CDATA[今天突然想看看PHP多线程的问题，发现很多人讲PHP的多线程其实是多进程，唉，破灭了！！！网上给PHP的模拟多线程提出了几种方案，下面仅摘录： There are a few solutions, varying from &#8220;Hmmm, just about OK&#8221; through to &#8220;Poke out your eyes&#8221;. 1. Write your multithreaded code as a PHP extension. Probably the most supported, but you need to write in C (or another &#8230; <a href="http://roygu.com/2012/03/php/php-multi-thread.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>今天突然想看看PHP多线程的问题，发现很多人讲PHP的多线程其实是多进程，唉，破灭了！！！网上给PHP的模拟多线程提出了几种方案，下面仅摘录：</p>
<blockquote><p>
There are a few solutions, varying from &#8220;Hmmm, just about OK&#8221; through to &#8220;Poke out your eyes&#8221;.</p>
<p>    1. Write your multithreaded code as a PHP extension. Probably the most supported, but you need to write in C (or another language supported for extensions).<br />
    2. Spawn child processes onto the underlying OS, and read/write to their input/output with standard file handles. See popen for one route in, or PCNTRL. Reasonable, and you can use PHP from the command line.<br />
    3. Make other HTTP requests to yourself via CURL or similar, thus piggybacking on your web servers multi-processing capacity. Keeps all your code &#8220;web like&#8221;, but runs the risk of irate support developers tracking you down and breaking thumbs.</p>
</blockquote>
]]></content:encoded>
			<wfw:commentRss>http://roygu.com/2012/03/php/php-multi-thread.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>emacs window systems</title>
		<link>http://roygu.com/2012/03/gnu/emacs/emacs-window-systems.html</link>
		<comments>http://roygu.com/2012/03/gnu/emacs/emacs-window-systems.html#comments</comments>
		<pubDate>Mon, 19 Mar 2012 04:08:29 +0000</pubDate>
		<dc:creator>校长</dc:creator>
				<category><![CDATA[emacs]]></category>
		<category><![CDATA[window]]></category>

		<guid isPermaLink="false">http://roygu.com/?p=1565</guid>
		<description><![CDATA[在配置emacs的时候，一直想区别对待x-window和terminal两种环境。上周五配的nxhtml时，因为mumamo会给同一个buffer中的不同模式加上背景色，而我一般以终端方式使用emacs，所以当然希望背景全是黑的。 这时候，情况出现了。使用GUI方式时同一buffer的不同模式的背景是黑色，但和GUI默认的代码高亮方案冲突了，所以代码基本没法看。而terminal下面又表现的近乎完美，所以才有想区别对待x-window和terminal两种情况。翻遍emacs lisp才找到原来有个系统变量window-system，那么接下来的事情就好办了，为x-window装一个配色解决方案：color-theme： 下面是emacs lisp手册中的原文描述： 这下就完美了！！！]]></description>
			<content:encoded><![CDATA[<p>在配置emacs的时候，一直想区别对待x-window和terminal两种环境。上周五配的nxhtml时，因为mumamo会给同一个buffer中的不同模式加上背景色，而我一般以终端方式使用emacs，所以当然希望背景全是黑的。</p>
<pre class="src"><br />
(custom-set-faces<br />
  ;; custom-set-faces was added by Custom.<br />
  ;; If you edit it by hand, you could mess it up, so be careful.<br />
  ;; Your init file should contain only one such instance.<br />
  ;; If there is more than one, they won&#8217;t work right.                                        </p>
<p> &#8216;(mumamo-background-chunk-major ((((class color) (min-colors 8)) (:background &#8220;black&#8221;))))<br />
 &#8216;(mumamo-background-chunk-submode1 ((((class color) (min-colors 8)) (:background &#8220;black&#8221;))))<br />
 &#8216;(mumamo-background-chunk-submode2 ((((class color) (min-colors 8)) (:background &#8220;black&#8221;))))<br />
 &#8216;(mumamo-background-chunk-submode3 ((((class color) (min-colors 8)) (:background &#8220;black&#8221;))))<br />
 &#8216;(mumamo-background-chunk-submode4 ((((class color) (min-colors 8)) (:background &#8220;black&#8221;)))))<br />
</pre>
<p>这时候，情况出现了。使用GUI方式时同一buffer的不同模式的背景是黑色，但和GUI默认的代码高亮方案冲突了，所以代码基本没法看。而terminal下面又表现的近乎完美，所以才有想区别对待x-window和terminal两种情况。翻遍emacs lisp才找到原来有个系统变量<code>window-system</code>，那么接下来的事情就好办了，为x-window装一个配色解决方案：color-theme：<br />
<pre class="src"><br />
;; color theme<br />
(if (eq window-system &#8216;x)<br />
    (progn<br />
      (setq default-font &#8220;DejaVu Sans Mono&#8221;)<br />
      (add-to-list &#8216;load-path &#8220;/share/.emacs.d/color-theme-6.6.0&#8243;)<br />
      (require &#8216;color-theme)<br />
      (eval-after-load &#8220;color-theme&#8221;<br />
        &#8216;(progn<br />
           (color-theme-initialize)<br />
           (color-theme-hober)))))<br />
</pre></p>
<p>下面是emacs lisp手册中的原文描述：<br />
<pre class="src"><br />
Window Systems<br />
Emacs works with several window systems, most notably the X Window System. Both Emacs and X use the term &#8220;window&#8221;, but use it differently. An Emacs frame is a single window as far as X is concerned; the individual Emacs windows are not known to X at all.</p>
<p>topVariable: window-system<br />
This variable tells Lisp programs what window system Emacs is running under. The possible values are </p>
<p>x<br />
Emacs is displaying using X.<br />
pc<br />
Emacs is displaying using MSDOS.<br />
w32<br />
Emacs is displaying using Windows NT or Windows 95.<br />
nil<br />
Emacs is using a character-based terminal.<br />
</pre></p>
<p>这下就完美了！！！</p>
]]></content:encoded>
			<wfw:commentRss>http://roygu.com/2012/03/gnu/emacs/emacs-window-systems.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>常见HTTP状态码</title>
		<link>http://roygu.com/2012/02/other/http-status-code.html</link>
		<comments>http://roygu.com/2012/02/other/http-status-code.html#comments</comments>
		<pubDate>Sun, 26 Feb 2012 07:12:39 +0000</pubDate>
		<dc:creator>校长</dc:creator>
				<category><![CDATA[杂谈]]></category>
		<category><![CDATA[http]]></category>
		<category><![CDATA[web]]></category>

		<guid isPermaLink="false">http://roygu.com/?p=1551</guid>
		<description><![CDATA[常见HTTP状态码 200 OK 301 Moved Permanently 302 Found 304 Not Modified 307 Temporary Redirect 400 Bad Request 401 Unauthorized 403 Forbidden 404 Not Found 410 Gone 500 Internal Server Error 501 Not Implemented 100 Continue 初始的请求已经接受，客户应当继续发送请求的其余部分 101 Switching Protocols 服务器将遵从客户的请求转换到另外一种协议 &#8230; <a href="http://roygu.com/2012/02/other/http-status-code.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>常见HTTP状态码</p>
<p>    200 OK<br />
    301 Moved Permanently<br />
    302 Found<br />
    304 Not Modified<br />
    307 Temporary Redirect<br />
    400 Bad Request<br />
    401 Unauthorized<br />
    403 Forbidden<br />
    404 Not Found<br />
    410 Gone<br />
    500 Internal Server Error<br />
    501 Not Implemented</p>
<p><span id="more-1551"></span></p>
<p>100 Continue</p>
<p>初始的请求已经接受，客户应当继续发送请求的其余部分<br />
101 Switching Protocols</p>
<p>服务器将遵从客户的请求转换到另外一种协议<br />
200 OK</p>
<p>一切正常，对GET和POST请求的应答文档跟在后面<br />
201 Created</p>
<p>服务器已经创建了文档，Location头给出了它的URL。<br />
202 Accepted</p>
<p>已经接受请求，但处理尚未完成。<br />
203 Non-Authoritative Information</p>
<p>文档已经正常地返回，但一些应答头可能不正确，因为使用的是文档的拷贝<br />
204 No Content</p>
<p>没有新文档，浏览器应该继续显示原来的文档。如果用户定期地刷新页面，而Servlet可以确定用户文档足够新，这个状态代码是很有用的<br />
205 Reset Content</p>
<p>没有新的内容，但浏览器应该重置它所显示的内容。用来强制浏览器清除表单输入内容<br />
206 Partial Content</p>
<p>客户发送了一个带有Range头的GET请求，服务器完成了它<br />
300 Multiple Choices</p>
<p>客户请求的文档可以在多个位置找到，这些位置已经在返回的文档内列出。如果服务器要提出优先选择，则应该在Location应答头指明。<br />
301 Moved Permanently</p>
<p>客户请求的文档在其他地方，新的URL在Location头中给出，浏览器应该自动地访问新的URL。<br />
302 Found</p>
<p>类似于301，但新的URL应该被视为临时性的替代，而不是永久性的。<br />
303 See Other</p>
<p>类似于301/302，不同之处在于，如果原来的请求是POST，Location头指定的重定向目标文档应该通过GET提取<br />
304 Not Modified</p>
<p>客户端有缓冲的文档并发出了一个条件性的请求（一般是提供If-Modified-Since头表示客户只想比指定日期更新的文档）。服务器告诉客户，原来缓冲的文档还可以继续使用。<br />
305 Use Proxy</p>
<p>客户请求的文档应该通过Location头所指明的代理服务器提取<br />
307 Temporary Redirect</p>
<p>和302（Found）相同。许多浏览器会错误地响应302应答进行重定向，即使原来的请求是 POST，即使它实际上只能在POST请求的应答是303时才能重定向。由于这个原因，HTTP 1.1新增了307，以便更加清除地区分几个状态代码： 当出现303应答时，浏览器可以跟随重定向的GET和POST请求；如果是307应答，则浏览器只能跟随对GET请求的重定向。<br />
400 Bad Request</p>
<p>请求出现语法错误。<br />
401 Unauthorized</p>
<p>客户试图未经授权访问受密码保护的页面。应答中会包含一个WWW-Authenticate头，浏览器据此显示用户名字/密码对话框，然后在填写合适的Authorization头后再次发出请求。<br />
403 Forbidden</p>
<p>资源不可用。<br />
404 Not Found</p>
<p>无法找到指定位置的资源<br />
405 Method Not Allowed</p>
<p>请求方法（GET、POST、HEAD、Delete、PUT、TRACE等）对指定的资源不适用。<br />
406 Not Acceptable</p>
<p>指定的资源已经找到，但它的MIME类型和客户在Accpet头中所指定的不兼容<br />
407 Proxy Authentication Required</p>
<p>类似于401，表示客户必须先经过代理服务器的授权。<br />
408 Request Timeout</p>
<p>在服务器许可的等待时间内，客户一直没有发出任何请求。客户可以在以后重复同一请求。<br />
409 Conflict</p>
<p>通常和PUT请求有关。由于请求和资源的当前状态相冲突，因此请求不能成功。<br />
410 Gone</p>
<p>所请求的文档已经不再可用，而且服务器不知道应该重定向到哪一个地址。它和404的不同在于，返回407表示文档永久地离开了指定的位置，而404表示由于未知的原因文档不可用。<br />
411 Length Required</p>
<p>服务器不能处理请求，除非客户发送一个Content-Length头。<br />
412 Precondition Failed</p>
<p>请求头中指定的一些前提条件失败<br />
413 Request Entity Too Large</p>
<p>目标文档的大小超过服务器当前愿意处理的大小。如果服务器认为自己能够稍后再处理该请求，则应该提供一个Retry-After头<br />
414 Request URI Too Long</p>
<p>URI太长<br />
416 Requested Range Not Satisfiable</p>
<p>服务器不能满足客户在请求中指定的Range头<br />
500 Internal Server Error</p>
<p>服务器遇到了意料不到的情况，不能完成客户的请求<br />
501 Not Implemented</p>
<p>服务器不支持实现请求所需要的功能。例如，客户发出了一个服务器不支持的PUT请求<br />
502 Bad Gateway</p>
<p>服务器作为网关或者代理时，为了完成请求访问下一个服务器，但该服务器返回了非法的应答<br />
503 Service Unavailable</p>
<p>服务器由于维护或者负载过重未能应答。例如，Servlet可能在数据库连接池已满的情况下返回503。服务器返回503时可以提供一个Retry-After头<br />
504 Gateway Timeout</p>
<p>由作为代理或网关的服务器使用，表示不能及时地从远程服务器获得应答<br />
505 HTTP Version Not Supported</p>
<p>服务器不支持请求中所指明的HTTP版本</p>
]]></content:encoded>
			<wfw:commentRss>http://roygu.com/2012/02/other/http-status-code.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>in PHP what does it mean by a function being binary-safe ?</title>
		<link>http://roygu.com/2012/01/php/n-php-what-does-it-mean-by-a-function-being-binary-safe.html</link>
		<comments>http://roygu.com/2012/01/php/n-php-what-does-it-mean-by-a-function-being-binary-safe.html#comments</comments>
		<pubDate>Fri, 13 Jan 2012 10:17:10 +0000</pubDate>
		<dc:creator>校长</dc:creator>
				<category><![CDATA[php]]></category>
		<category><![CDATA[binary safe]]></category>

		<guid isPermaLink="false">http://roygu.com/?p=1536</guid>
		<description><![CDATA[It means the function will work correctly when you pass it arbitrary binary data (i.e. strings containing non-ASCII bytes and/or null bytes). For example, a non-binary-safe function might be based on a C function which expects null-terminated strings, so if &#8230; <a href="http://roygu.com/2012/01/php/n-php-what-does-it-mean-by-a-function-being-binary-safe.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>It means the function will work correctly when you pass it arbitrary binary data (i.e. strings containing non-ASCII bytes and/or null bytes).</p>
<p>For example, a non-binary-safe function might be based on a C function which expects null-terminated strings, so if the string contains a null character, the function would ignore anything after it.</p>
<p>This is relevant because PHP does not cleanly separate string and binary data.</p>
<p>For instance, if PHP&#8217;s <code>strlen</code> function worked like C standard library <code>strlen</code>, the result here would be wrong:</p>
<pre>如果函数是binary safe的话，我们将得到7；如果函数是非binary safe的话，我们将得到3 * strlen是binary safe的，所以实际上以下的运行结果是"7"</pre>
<pre class="src">
$str = "abc\x00abc";
echo strlen($str); //gives 7, not 3!
</pre>
]]></content:encoded>
			<wfw:commentRss>http://roygu.com/2012/01/php/n-php-what-does-it-mean-by-a-function-being-binary-safe.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Manage Subscriptions</title>
		<link>http://roygu.com/2011/11/solarphp/manage-subscriptions.html</link>
		<comments>http://roygu.com/2011/11/solarphp/manage-subscriptions.html#comments</comments>
		<pubDate>Tue, 01 Nov 2011 01:19:18 +0000</pubDate>
		<dc:creator>校长</dc:creator>
				<category><![CDATA[solarphp]]></category>

		<guid isPermaLink="false">http://roygu.com/2011/11/solarphp/manage-subscriptions.html</guid>
		<description><![CDATA[[wpmlmanagement]]]></description>
			<content:encoded><![CDATA[<p>[wpmlmanagement]</p>
]]></content:encoded>
			<wfw:commentRss>http://roygu.com/2011/11/solarphp/manage-subscriptions.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>[转]无密码卸载Symantec Endpoint Protection 11</title>
		<link>http://roygu.com/2011/10/other/%e8%bd%ac%e6%97%a0%e5%af%86%e7%a0%81%e5%8d%b8%e8%bd%bdsymantec-endpoint-protection-11.html</link>
		<comments>http://roygu.com/2011/10/other/%e8%bd%ac%e6%97%a0%e5%af%86%e7%a0%81%e5%8d%b8%e8%bd%bdsymantec-endpoint-protection-11.html#comments</comments>
		<pubDate>Mon, 31 Oct 2011 00:32:39 +0000</pubDate>
		<dc:creator>校长</dc:creator>
				<category><![CDATA[杂谈]]></category>
		<category><![CDATA[symantec]]></category>
		<category><![CDATA[uninstall]]></category>
		<category><![CDATA[卸载]]></category>
		<category><![CDATA[密码]]></category>
		<category><![CDATA[赛门铁克]]></category>

		<guid isPermaLink="false">http://roygu.com/?p=1530</guid>
		<description><![CDATA[不需要密码卸载Symantec Endpoint Protection 11的步骤: 1. 点击“开始”按钮 -&#62; 运行 (或直接： Window徽标键 + R) 2. 输入 smc -stop. 如果要密码，则打开注册表(Window徽标键 + R; 输入 regedit; 敲回车) ，然后找到 HKEY_LOCAL_MACHINE\SOFTWARE\Symantec\Symantec Endpoint Protection\SMC，在右边删除类似于 smc_exit_test 的键，然后再在运行里输入 smc -stop 。 3. 现在继续到 HKEY_LOCAL_MACHINE\SOFTWARE\Symantec\Symantec Endpoint Protection\SMC.，在右边删除类似于 smcinstdata 的键。 4. 现在你可以到 &#8230; <a href="http://roygu.com/2011/10/other/%e8%bd%ac%e6%97%a0%e5%af%86%e7%a0%81%e5%8d%b8%e8%bd%bdsymantec-endpoint-protection-11.html">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>不需要密码卸载Symantec Endpoint Protection 11的步骤:<br />
1. 点击“开始”按钮 -&gt; 运行 (或直接： Window徽标键 + R)<br />
2. 输入 smc -stop. 如果要密码，则打开注册表(Window徽标键 + R; 输入 regedit; 敲回车) ，然后找到 HKEY_LOCAL_MACHINE\SOFTWARE\Symantec\Symantec Endpoint Protection\SMC，在右边删除类似于 smc_exit_test 的键，然后再在运行里输入 smc -stop 。<br />
3. 现在继续到 HKEY_LOCAL_MACHINE\SOFTWARE\Symantec\Symantec Endpoint Protection\SMC.，在右边删除类似于 smcinstdata 的键。<br />
4. 现在你可以到 添加删除程序 里无需密码就可以卸载 SEP 11。</p>
]]></content:encoded>
			<wfw:commentRss>http://roygu.com/2011/10/other/%e8%bd%ac%e6%97%a0%e5%af%86%e7%a0%81%e5%8d%b8%e8%bd%bdsymantec-endpoint-protection-11.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

