<?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>神秘果</title>
	<atom:link href="http://www.shenmiguo.com/feed" rel="self" type="application/rss+xml" />
	<link>http://www.shenmiguo.com</link>
	<description>There&#039;re Miracles When You Believe.</description>
	<lastBuildDate>Wed, 07 Apr 2010 03:46:57 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Coredump设置</title>
		<link>http://www.shenmiguo.com/archives/2010/327_coredump.html</link>
		<comments>http://www.shenmiguo.com/archives/2010/327_coredump.html#comments</comments>
		<pubDate>Wed, 07 Apr 2010 03:46:43 +0000</pubDate>
		<dc:creator>神秘果</dc:creator>
				<category><![CDATA[程序设计]]></category>
		<category><![CDATA[coredump]]></category>
		<category><![CDATA[linux]]></category>

		<guid isPermaLink="false">http://www.shenmiguo.com/?p=327</guid>
		<description><![CDATA[Linux下当程序crash时，会产生core文件，记录程序非正常退出时的内存映象，通过gdb可以加载core文件可调试跟踪程序出错的代码所在行。

配置coredump
Coredump的设置和2个文件相关。在/proc/sys/kernel目录下：
/proc/sys/kernel/core_pattern文件设置core文件的保存路径和文件名称，pattern可使用参数：
%p &#8211; insert pid into filename
%u &#8211; insert current uid into filename
%g &#8211; insert current gid into filename
%s &#8211; insert signal that caused the coredump into the filename
%t &#8211; insert UNIX time that the coredump occurred into filename
%h &#8211; insert hostname where the coredump happened into filename
%e &#8211; insert coredumping executable name into filename
如：
&#160;&#160;&#160;&#160;&#160;&#160; echo [...]]]></description>
			<content:encoded><![CDATA[<p><span class="Apple-style-span" style="line-height: 15px; ">Linux<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">下当程序</span>crash<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">时，会产生</span>core<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">文件，记录程序非正常退出时的内存映象，通过</span>gdb<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">可以加载</span>core<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">文件可调试跟踪程序出错的代码所在行。</span></span></p>
<div style="margin-bottom:3.0pt;<br />
line-height:125%"><span id="more-327"></span></div>
<div style="margin-bottom:3.0pt;<br />
line-height:125%"><b><span style="font-size:12.0pt;line-height:125%;font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">配置</span></b><b><span style="font-size:12.0pt;<br />
line-height:125%">coredump</span></b></div>
<div style="margin-bottom:3.0pt;<br />
line-height:125%">Coredump<span style="font-family:<br />
宋体;Times New Roman&quot;;Times New Roman&quot;">的设置和</span>2<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">个文件相关。在</span>/proc/sys/kernel<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">目录下：</span></div>
<div style="margin-bottom:3.0pt;<br />
line-height:125%"><span style="color:red">/proc/sys/kernel/core_pattern</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">文件设置</span>core<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">文件的保存路径和文件名称，</span>pattern<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">可使用参数：</span></div>
<div style="margin-top:0cm;margin-right:0cm;margin-bottom:3.0pt;<br />
margin-left:21.0pt;line-height:125%">%p &#8211; insert pid into filename</div>
<div style="margin-top:0cm;margin-right:0cm;margin-bottom:3.0pt;<br />
margin-left:21.0pt;line-height:125%">%u &#8211; insert current uid into filename</div>
<div style="margin-top:0cm;margin-right:0cm;margin-bottom:3.0pt;<br />
margin-left:21.0pt;line-height:125%">%g &#8211; insert current gid into filename</div>
<div style="margin-top:0cm;margin-right:0cm;margin-bottom:3.0pt;<br />
margin-left:21.0pt;line-height:125%">%s &#8211; insert signal that caused the coredump into the filename</div>
<div style="margin-top:0cm;margin-right:0cm;margin-bottom:3.0pt;<br />
margin-left:21.0pt;line-height:125%">%t &#8211; insert UNIX time that the coredump occurred into filename</div>
<div style="margin-top:0cm;margin-right:0cm;margin-bottom:3.0pt;<br />
margin-left:21.0pt;line-height:125%">%h &#8211; insert hostname where the coredump happened into filename</div>
<div style="margin-top:0cm;margin-right:0cm;margin-bottom:3.0pt;<br />
margin-left:21.0pt;line-height:125%">%e &#8211; insert coredumping executable name into filename</div>
<div style="margin-bottom:3.0pt;<br />
line-height:125%"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">如：</span></div>
<div style="margin-bottom:3.0pt;<br />
line-height:125%"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo &quot;/data/coredump/core_%e_%t&quot; &gt; /proc/sys/kernel/core_pattern</span></div>
<div style="margin-bottom:3.0pt;<br />
line-height:125%">core<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">文件统一在</span>/data/coredump<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">目录下产生，格式为</span>core_<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">进程名</span>_<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">时间戳</span></div>
<div style="margin-bottom:3.0pt;<br />
line-height:125%">/proc/sys/kernel/core_pattern<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">中的默认内容是</span>core<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">，表示</span>core<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">文件生成在可执行程序所在目录，文件名叫</span>core<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">。新的</span>core<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">就会覆盖旧的</span>core<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">文件。</span></div>
<div style="margin-bottom:3.0pt;<br />
line-height:125%"><span style="color:red">/proc/sys/kernel/core_users_pid</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">控制</span>core<span style="font-family:<br />
宋体;Times New Roman&quot;;Times New Roman&quot;">文件是否加</span>pid<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">作为</span>core_pattern<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">中约定文件名称的扩展名。表示添加</span>pid<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">作为扩展名，生成的</span>core<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">文件格式为</span>core.xxxx<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">；为</span>0<span style="font-family:<br />
宋体;Times New Roman&quot;;Times New Roman&quot;">则表示生成的</span>core<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">文件同一命名为</span>core_pattern<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">。该文件内容默认值是</span>0<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">。</span></div>
<div style="margin-bottom:3.0pt;<br />
line-height:125%"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">如：</span></div>
<div style="margin-bottom:3.0pt;<br />
line-height:125%"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; echo &#39;1&#39; &gt; /proc/sys/kernel/core_uses_pid</span></div>
<div style="margin-bottom:3.0pt;<br />
line-height:125%"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">再加上</span>core_pattern <span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的设置，</span>core<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">文件统一在</span>/data/coredump<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">目录下产生，格式为</span>core_<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">进程名</span>_<span style="font-family:<br />
宋体;Times New Roman&quot;;Times New Roman&quot;">时间戳</span>.<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">进程号</span></div>
<div style="margin-bottom:3.0pt;<br />
line-height:125%">&nbsp;</div>
<div style="margin-bottom:3.0pt;<br />
line-height:125%"><b><span style="font-size:12.0pt;line-height:125%">Core</span></b><b><span style="font-size:12.0pt;line-height:125%;font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">文件开关</span></b></div>
<div style="margin-bottom:3.0pt;<br />
line-height:125%"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">使用</span>ulimit -c<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">查看</span>core<span style="font-family:<br />
宋体;Times New Roman&quot;;Times New Roman&quot;">文件生成开关。若为</span>0<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">则表示不会生成</span>core<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">文件。</span></div>
<div style="margin-bottom:3.0pt;<br />
line-height:125%"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">使用</span>ulimit -c size<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">设置</span>core<span style="font-family:<br />
宋体;Times New Roman&quot;;Times New Roman&quot;">文件的大小限制，</span>size<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">的单位是</span>kbyte<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">。若要想</span>core<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">文件大小不受限制，则使用</span>ulimit -c unlimited</div>
<div style="margin-bottom:3.0pt;<br />
line-height:125%"><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">有了</span>core<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">文件。使用</span>gdb<span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">加载调试：</span></div>
<div style="margin-bottom:3.0pt;<br />
line-height:125%"><span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; gdb &ndash;c core</span><span style="font-family:宋体;Times New Roman&quot;;Times New Roman&quot;">文件名</span> <span style="font-family:<br />
宋体;Times New Roman&quot;;Times New Roman&quot;">可执行程序名</span></div>
]]></content:encoded>
			<wfw:commentRss>http://www.shenmiguo.com/archives/2010/327_coredump.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Base64编码原理</title>
		<link>http://www.shenmiguo.com/archives/2010/326_base64-encode.html</link>
		<comments>http://www.shenmiguo.com/archives/2010/326_base64-encode.html#comments</comments>
		<pubDate>Sun, 28 Feb 2010 04:14:16 +0000</pubDate>
		<dc:creator>神秘果</dc:creator>
				<category><![CDATA[程序设计]]></category>
		<category><![CDATA[base64 编码]]></category>

		<guid isPermaLink="false">http://www.shenmiguo.com/?p=326</guid>
		<description><![CDATA[定义
Base64是用64个可见字符表示任意字节编码方式。
Base64在RFC2045的section 6.8（The Base64 Content-Transfer-Encoding is designed to represent arbitrary sequences of octets in a form that need not be humanly readable）定义：Base64内容传送编码被设计用来把任意序列的8位字节描述为一种不易被人直接识别的形式。
相对于Base64，还有Base16、Base32编码方式，可以参见RFC3548（The Base16, Base32, and Base64 Data Encodings）。
Base64编码应用：电子邮件编码传输、广告点击跳转加密编码串、Cookie串二进制内容编码。

&#160;
编码范围
一个字节的编码范围是[0x00, 0xff]，共8个位，256个字符（可称为一个八位组或Base256）。
Base64的编码范围是[0x00, 0x3f]，共6个位，64个字符（也为一个六位组）。
Base64的编码过程就是把八位组变成六位组的过程，每三个8bit的字节转换为四个6bit的字节（3*8 = 4*6 = 24），然后把6bit再添两位高位0，组成四个8bit的字节。也就是说，转换后的字符串理论上要比原来的长1/3（3字节编码成4字节）。
Base64使用的映射字符：





编码


字符


编码


字符


编码


字符


编码


字符




0


A


17


R


34


i


51


z




1


B


18


S


35


j


52


0




2


C


19


T


36


k


53


1




3


D


20


U


37


l


54


2




4


E


21


V


38


m


55


3




5


F


22


W


39


n


56


4




6


G


23


X


40


o


57


5




7


H


24


Y


41


p


58


6




8


I


25


Z


42


q


59


7




9


J


26


a


43


r


60


8




10


K


27


b


44


s


61


9




11


L


28


c


45


t


62


+




12


M


29


d


46


u


63


/




13


N


30


e


47


v


&#160;


&#160;




14


O


31


f


48


w


pad


=




15


P


32


g


49


x


&#160;


&#160;




16


Q


33


h


50


y


&#160;


&#160;





pad是填充字符，当转换字节不是3的倍数时，就用pad字符填充补齐。填充字符数=转换字节数 MOD 3。第62，63，pad字符可以根据使用场合来自定义。譬如在URL串里，=表示特殊意义，就不能使用=作为填充字符。
&#160;
编码举例
如果字节串是3的倍数，刚好对齐。下面是3字节编码成4字节：





转换前bit内容


12345678


12345678


12345678


&#160;




转换后bit内容


00123456


00781234


00567812


00345678





如果字节串不是3的位数，不足的bit用0填充，不足的字节使用填充字符。下面是2字节编码成4字节：





转换前bit内容


12345678


12345678


pad


&#160;




转换后bit内容


00123456


00781234


00567800


=





如：&#8220;张&#8221;占用2个字节，字节内容是：11010101 11000101，16进制（Base16）表示就是：D5C5。编码成Base64，需要使用填充字符补齐成3字节再编码，编码结果是1iU=





转换前bit内容


11010101


11000101


pad


&#160;




转换后bit内容


00110101


00011100


00010100


=




转换后字符


1（53）


i（34）


U（20）


=





&#160;
编码过程
第一个字符通过右移2位获得第一个目标字符的Base64表位置，根据这个数值取到表上相应的字符，就是第一个目标字符。
然后将第一个字符左移4 位加上第二个字符右移4位，即获得第二个目标字符。
再将第二个字符左移2位加上第三个字符右移6位，获得第三个目标字符。
最后取第三个字符的右6位即获得第四个目标字符。
在以上的每一个步骤之后，再把结果与 0&#215;3f 进行 AND 位操作，就可以得到编码后的字符了。
如果原文字节数不是3的倍数，补齐尾部不足的字节使用填充字符。
]]></description>
			<content:encoded><![CDATA[<p><b><span style="font-size: 12pt; line-height: 125%; font-family: 宋体;">定义</span></b></p>
<div style="margin-bottom: 3.9pt; line-height: 125%;">Base64<span style="font-family: 宋体;">是<span style="color: red;">用</span></span><span style="color: red;">64</span><span style="font-family: 宋体; color: red;">个可见字符表示任意字节</span><span style="font-family: 宋体;">编码方式。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">Base64<span style="font-family: 宋体;">在</span><a href="http://www.ietf.org/rfc/rfc2045.txt">RFC2045</a><span style="font-family: 宋体;">的</span>section 6.8<span style="font-family: 宋体;">（</span>The Base64 Content-Transfer-Encoding is designed to represent arbitrary sequences of octets in a form that need not be humanly readable<span style="font-family: 宋体;">）定义：</span>Base64<span style="font-family: 宋体;">内容传送编码被设计用来把任意序列的</span>8<span style="font-family: 宋体;">位字节描述为一种不易被人直接识别的形式。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">相对于</span>Base64<span style="font-family: 宋体;">，还有</span>Base16<span style="font-family: 宋体;">、</span>Base32<span style="font-family: 宋体;">编码方式，可以参见</span><a href="http://www.ietf.org/rfc/rfc3548.txt">RFC3548</a><span style="font-family: 宋体;">（</span>The Base16, Base32, and Base64 Data Encodings<span style="font-family: 宋体;">）。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">Base64<span style="font-family: 宋体;">编码应用：电子邮件编码传输、广告点击跳转加密编码串、</span>Cookie<span style="font-family: 宋体;">串二进制内容编码。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span id="more-326"></span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><b><span style="font-size: 12pt; line-height: 125%; font-family: 宋体;">编码范围</span></b></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">一个字节的编码范围是</span>[0x00, 0xff]<span style="font-family: 宋体;">，共</span>8<span style="font-family: 宋体;">个位，</span>256<span style="font-family: 宋体;">个字符（可称为一个<span style="color: red;">八位组或</span></span><span style="color: red;">Base256</span><span style="font-family: 宋体;">）。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">Base64<span style="font-family: 宋体;">的编码范围是</span>[0x00, 0x3f]<span style="font-family: 宋体;">，共</span>6<span style="font-family: 宋体;">个位，</span>64<span style="font-family: 宋体;">个字符（也为一个<span style="color: red;">六位组</span>）。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">Base64<span style="font-family: 宋体;">的编码过程就是把八位组变成六位组的过程，每三个</span>8bit<span style="font-family: 宋体;">的字节转换为四个</span>6bit<span style="font-family: 宋体;">的字节（</span>3*8 = 4*6 = 24<span style="font-family: 宋体;">），然后把</span>6bit<span style="font-family: 宋体;">再添两位高位</span>0<span style="font-family: 宋体;">，组成四个</span>8bit<span style="font-family: 宋体;">的字节。也就是说，转换后的字符串理论上要比原来的长</span>1/3<span style="font-family: 宋体;">（</span><span style="color: red;">3</span><span style="font-family: 宋体; color: red;">字节编码成</span><span style="color: red;">4</span><span style="font-family: 宋体; color: red;">字节</span><span style="font-family: 宋体;">）。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">Base64<span style="font-family: 宋体;">使用的映射字符：</span></div>
<div align="center">
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse; border: medium none;">
<tbody>
<tr>
<td style="width: 33.75pt; border: 1pt solid black; padding: 0cm 5.4pt;" valign="top" width="45">
<div><span style="font-family: 宋体;">编码</span></div>
</td>
<td style="width: 60.95pt; border-width: 1pt 1pt 1pt medium; border-style: solid solid solid none; border-color: black black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="81">
<div><span style="font-family: 宋体;">字符</span></div>
</td>
<td style="width: 38.3pt; border-width: 1pt 1pt 1pt medium; border-style: solid solid solid none; border-color: black black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="51">
<div><span style="font-family: 宋体;">编码</span></div>
</td>
<td style="width: 56.4pt; border-width: 1pt 1pt 1pt medium; border-style: solid solid solid none; border-color: black black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="75">
<div><span style="font-family: 宋体;">字符</span></div>
</td>
<td style="width: 35.75pt; border-width: 1pt 1pt 1pt medium; border-style: solid solid solid none; border-color: black black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="48">
<div><span style="font-family: 宋体;">编码</span></div>
</td>
<td style="width: 58.95pt; border-width: 1pt 1pt 1pt medium; border-style: solid solid solid none; border-color: black black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="79">
<div><span style="font-family: 宋体;">字符</span></div>
</td>
<td style="width: 40.25pt; border-width: 1pt 1pt 1pt medium; border-style: solid solid solid none; border-color: black black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="54">
<div><span style="font-family: 宋体;">编码</span></div>
</td>
<td style="width: 54.45pt; border-width: 1pt 1pt 1pt medium; border-style: solid solid solid none; border-color: black black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="73">
<div><span style="font-family: 宋体;">字符</span></div>
</td>
</tr>
<tr>
<td style="width: 33.75pt; border-width: medium 1pt 1pt; border-style: none solid solid; border-color: -moz-use-text-color black black; padding: 0cm 5.4pt;" valign="top" width="45">
<div>0</div>
</td>
<td style="width: 60.95pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="81">
<div>A</div>
</td>
<td style="width: 38.3pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="51">
<div>17</div>
</td>
<td style="width: 56.4pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="75">
<div>R</div>
</td>
<td style="width: 35.75pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="48">
<div>34</div>
</td>
<td style="width: 58.95pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="79">
<div>i</div>
</td>
<td style="width: 40.25pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="54">
<div>51</div>
</td>
<td style="width: 54.45pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="73">
<div>z</div>
</td>
</tr>
<tr>
<td style="width: 33.75pt; border-width: medium 1pt 1pt; border-style: none solid solid; border-color: -moz-use-text-color black black; padding: 0cm 5.4pt;" valign="top" width="45">
<div>1</div>
</td>
<td style="width: 60.95pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="81">
<div>B</div>
</td>
<td style="width: 38.3pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="51">
<div>18</div>
</td>
<td style="width: 56.4pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="75">
<div>S</div>
</td>
<td style="width: 35.75pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="48">
<div>35</div>
</td>
<td style="width: 58.95pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="79">
<div>j</div>
</td>
<td style="width: 40.25pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="54">
<div>52</div>
</td>
<td style="width: 54.45pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="73">
<div>0</div>
</td>
</tr>
<tr>
<td style="width: 33.75pt; border-width: medium 1pt 1pt; border-style: none solid solid; border-color: -moz-use-text-color black black; padding: 0cm 5.4pt;" valign="top" width="45">
<div>2</div>
</td>
<td style="width: 60.95pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="81">
<div>C</div>
</td>
<td style="width: 38.3pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="51">
<div>19</div>
</td>
<td style="width: 56.4pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="75">
<div>T</div>
</td>
<td style="width: 35.75pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="48">
<div>36</div>
</td>
<td style="width: 58.95pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="79">
<div>k</div>
</td>
<td style="width: 40.25pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="54">
<div>53</div>
</td>
<td style="width: 54.45pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="73">
<div>1</div>
</td>
</tr>
<tr>
<td style="width: 33.75pt; border-width: medium 1pt 1pt; border-style: none solid solid; border-color: -moz-use-text-color black black; padding: 0cm 5.4pt;" valign="top" width="45">
<div>3</div>
</td>
<td style="width: 60.95pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="81">
<div>D</div>
</td>
<td style="width: 38.3pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="51">
<div>20</div>
</td>
<td style="width: 56.4pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="75">
<div>U</div>
</td>
<td style="width: 35.75pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="48">
<div>37</div>
</td>
<td style="width: 58.95pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="79">
<div>l</div>
</td>
<td style="width: 40.25pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="54">
<div>54</div>
</td>
<td style="width: 54.45pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="73">
<div>2</div>
</td>
</tr>
<tr>
<td style="width: 33.75pt; border-width: medium 1pt 1pt; border-style: none solid solid; border-color: -moz-use-text-color black black; padding: 0cm 5.4pt;" valign="top" width="45">
<div>4</div>
</td>
<td style="width: 60.95pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="81">
<div>E</div>
</td>
<td style="width: 38.3pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="51">
<div>21</div>
</td>
<td style="width: 56.4pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="75">
<div>V</div>
</td>
<td style="width: 35.75pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="48">
<div>38</div>
</td>
<td style="width: 58.95pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="79">
<div>m</div>
</td>
<td style="width: 40.25pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="54">
<div>55</div>
</td>
<td style="width: 54.45pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="73">
<div>3</div>
</td>
</tr>
<tr>
<td style="width: 33.75pt; border-width: medium 1pt 1pt; border-style: none solid solid; border-color: -moz-use-text-color black black; padding: 0cm 5.4pt;" valign="top" width="45">
<div>5</div>
</td>
<td style="width: 60.95pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="81">
<div>F</div>
</td>
<td style="width: 38.3pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="51">
<div>22</div>
</td>
<td style="width: 56.4pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="75">
<div>W</div>
</td>
<td style="width: 35.75pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="48">
<div>39</div>
</td>
<td style="width: 58.95pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="79">
<div>n</div>
</td>
<td style="width: 40.25pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="54">
<div>56</div>
</td>
<td style="width: 54.45pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="73">
<div>4</div>
</td>
</tr>
<tr>
<td style="width: 33.75pt; border-width: medium 1pt 1pt; border-style: none solid solid; border-color: -moz-use-text-color black black; padding: 0cm 5.4pt;" valign="top" width="45">
<div>6</div>
</td>
<td style="width: 60.95pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="81">
<div>G</div>
</td>
<td style="width: 38.3pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="51">
<div>23</div>
</td>
<td style="width: 56.4pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="75">
<div>X</div>
</td>
<td style="width: 35.75pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="48">
<div>40</div>
</td>
<td style="width: 58.95pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="79">
<div>o</div>
</td>
<td style="width: 40.25pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="54">
<div>57</div>
</td>
<td style="width: 54.45pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="73">
<div>5</div>
</td>
</tr>
<tr>
<td style="width: 33.75pt; border-width: medium 1pt 1pt; border-style: none solid solid; border-color: -moz-use-text-color black black; padding: 0cm 5.4pt;" valign="top" width="45">
<div>7</div>
</td>
<td style="width: 60.95pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="81">
<div>H</div>
</td>
<td style="width: 38.3pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="51">
<div>24</div>
</td>
<td style="width: 56.4pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="75">
<div>Y</div>
</td>
<td style="width: 35.75pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="48">
<div>41</div>
</td>
<td style="width: 58.95pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="79">
<div>p</div>
</td>
<td style="width: 40.25pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="54">
<div>58</div>
</td>
<td style="width: 54.45pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="73">
<div>6</div>
</td>
</tr>
<tr>
<td style="width: 33.75pt; border-width: medium 1pt 1pt; border-style: none solid solid; border-color: -moz-use-text-color black black; padding: 0cm 5.4pt;" valign="top" width="45">
<div>8</div>
</td>
<td style="width: 60.95pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="81">
<div>I</div>
</td>
<td style="width: 38.3pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="51">
<div>25</div>
</td>
<td style="width: 56.4pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="75">
<div>Z</div>
</td>
<td style="width: 35.75pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="48">
<div>42</div>
</td>
<td style="width: 58.95pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="79">
<div>q</div>
</td>
<td style="width: 40.25pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="54">
<div>59</div>
</td>
<td style="width: 54.45pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="73">
<div>7</div>
</td>
</tr>
<tr>
<td style="width: 33.75pt; border-width: medium 1pt 1pt; border-style: none solid solid; border-color: -moz-use-text-color black black; padding: 0cm 5.4pt;" valign="top" width="45">
<div>9</div>
</td>
<td style="width: 60.95pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="81">
<div>J</div>
</td>
<td style="width: 38.3pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="51">
<div>26</div>
</td>
<td style="width: 56.4pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="75">
<div>a</div>
</td>
<td style="width: 35.75pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="48">
<div>43</div>
</td>
<td style="width: 58.95pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="79">
<div>r</div>
</td>
<td style="width: 40.25pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="54">
<div>60</div>
</td>
<td style="width: 54.45pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="73">
<div>8</div>
</td>
</tr>
<tr>
<td style="width: 33.75pt; border-width: medium 1pt 1pt; border-style: none solid solid; border-color: -moz-use-text-color black black; padding: 0cm 5.4pt;" valign="top" width="45">
<div>10</div>
</td>
<td style="width: 60.95pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="81">
<div>K</div>
</td>
<td style="width: 38.3pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="51">
<div>27</div>
</td>
<td style="width: 56.4pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="75">
<div>b</div>
</td>
<td style="width: 35.75pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="48">
<div>44</div>
</td>
<td style="width: 58.95pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="79">
<div>s</div>
</td>
<td style="width: 40.25pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="54">
<div>61</div>
</td>
<td style="width: 54.45pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="73">
<div>9</div>
</td>
</tr>
<tr>
<td style="width: 33.75pt; border-width: medium 1pt 1pt; border-style: none solid solid; border-color: -moz-use-text-color black black; padding: 0cm 5.4pt;" valign="top" width="45">
<div>11</div>
</td>
<td style="width: 60.95pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="81">
<div>L</div>
</td>
<td style="width: 38.3pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="51">
<div>28</div>
</td>
<td style="width: 56.4pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="75">
<div>c</div>
</td>
<td style="width: 35.75pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="48">
<div>45</div>
</td>
<td style="width: 58.95pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="79">
<div>t</div>
</td>
<td style="width: 40.25pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="54">
<div><span style="color: red;">62</span></div>
</td>
<td style="width: 54.45pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="73">
<div><span style="color: red;">+</span></div>
</td>
</tr>
<tr>
<td style="width: 33.75pt; border-width: medium 1pt 1pt; border-style: none solid solid; border-color: -moz-use-text-color black black; padding: 0cm 5.4pt;" valign="top" width="45">
<div>12</div>
</td>
<td style="width: 60.95pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="81">
<div>M</div>
</td>
<td style="width: 38.3pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="51">
<div>29</div>
</td>
<td style="width: 56.4pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="75">
<div>d</div>
</td>
<td style="width: 35.75pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="48">
<div>46</div>
</td>
<td style="width: 58.95pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="79">
<div>u</div>
</td>
<td style="width: 40.25pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="54">
<div><span style="color: red;">63</span></div>
</td>
<td style="width: 54.45pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="73">
<div><span style="color: red;">/</span></div>
</td>
</tr>
<tr>
<td style="width: 33.75pt; border-width: medium 1pt 1pt; border-style: none solid solid; border-color: -moz-use-text-color black black; padding: 0cm 5.4pt;" valign="top" width="45">
<div>13</div>
</td>
<td style="width: 60.95pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="81">
<div>N</div>
</td>
<td style="width: 38.3pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="51">
<div>30</div>
</td>
<td style="width: 56.4pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="75">
<div>e</div>
</td>
<td style="width: 35.75pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="48">
<div>47</div>
</td>
<td style="width: 58.95pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="79">
<div>v</div>
</td>
<td style="width: 40.25pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="54">
<div>&nbsp;</div>
</td>
<td style="width: 54.45pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="73">
<div>&nbsp;</div>
</td>
</tr>
<tr>
<td style="width: 33.75pt; border-width: medium 1pt 1pt; border-style: none solid solid; border-color: -moz-use-text-color black black; padding: 0cm 5.4pt;" valign="top" width="45">
<div>14</div>
</td>
<td style="width: 60.95pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="81">
<div>O</div>
</td>
<td style="width: 38.3pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="51">
<div>31</div>
</td>
<td style="width: 56.4pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="75">
<div>f</div>
</td>
<td style="width: 35.75pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="48">
<div>48</div>
</td>
<td style="width: 58.95pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="79">
<div>w</div>
</td>
<td style="width: 40.25pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="54">
<div><span style="color: red;">pad</span></div>
</td>
<td style="width: 54.45pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="73">
<div><span style="color: red;">=</span></div>
</td>
</tr>
<tr>
<td style="width: 33.75pt; border-width: medium 1pt 1pt; border-style: none solid solid; border-color: -moz-use-text-color black black; padding: 0cm 5.4pt;" valign="top" width="45">
<div>15</div>
</td>
<td style="width: 60.95pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="81">
<div>P</div>
</td>
<td style="width: 38.3pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="51">
<div>32</div>
</td>
<td style="width: 56.4pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="75">
<div>g</div>
</td>
<td style="width: 35.75pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="48">
<div>49</div>
</td>
<td style="width: 58.95pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="79">
<div>x</div>
</td>
<td style="width: 40.25pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="54">
<div>&nbsp;</div>
</td>
<td style="width: 54.45pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="73">
<div>&nbsp;</div>
</td>
</tr>
<tr>
<td style="width: 33.75pt; border-width: medium 1pt 1pt; border-style: none solid solid; border-color: -moz-use-text-color black black; padding: 0cm 5.4pt;" valign="top" width="45">
<div>16</div>
</td>
<td style="width: 60.95pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="81">
<div>Q</div>
</td>
<td style="width: 38.3pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="51">
<div>33</div>
</td>
<td style="width: 56.4pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="75">
<div>h</div>
</td>
<td style="width: 35.75pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="48">
<div>50</div>
</td>
<td style="width: 58.95pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="79">
<div>y</div>
</td>
<td style="width: 40.25pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="54">
<div>&nbsp;</div>
</td>
<td style="width: 54.45pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="73">
<div>&nbsp;</div>
</td>
</tr>
</tbody>
</table>
</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">pad<span style="font-family: 宋体;">是填充字符，当转换字节不是</span>3<span style="font-family: 宋体;">的倍数时，就用</span>pad<span style="font-family: 宋体;">字符填充补齐。<span style="color: red;">填充字符数</span></span><span style="color: red;">=</span><span style="font-family: 宋体; color: red;">转换字节数</span><span style="color: red;"> MOD 3</span><span style="font-family: 宋体;">。第</span>62<span style="font-family: 宋体;">，</span>63<span style="font-family: 宋体;">，</span>pad<span style="font-family: 宋体;">字符可以根据使用场合来自定义。譬如在</span>URL<span style="font-family: 宋体;">串里，</span>=<span style="font-family: 宋体;">表示特殊意义，就不能使用</span>=<span style="font-family: 宋体;">作为填充字符。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><b><span style="font-size: 12pt; line-height: 125%; font-family: 宋体;">编码举例</span></b></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">如果字节串是</span>3<span style="font-family: 宋体;">的倍数，刚好对齐。下面是</span>3<span style="font-family: 宋体;">字节编码成</span>4<span style="font-family: 宋体;">字节：</span></div>
<div align="center">
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse; border: medium none;">
<tbody>
<tr>
<td style="width: 85.2pt; border: 1pt solid black; padding: 0cm 5.4pt;" valign="top" width="114">
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">转换前</span>bit<span style="font-family: 宋体;">内容</span></div>
</td>
<td style="width: 69.05pt; border-width: 1pt 1pt 1pt medium; border-style: solid solid solid none; border-color: black black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="92">
<div style="margin-bottom: 3.9pt; line-height: 125%;">12345678</div>
</td>
<td style="width: 70.9pt; border-width: 1pt 1pt 1pt medium; border-style: solid solid solid none; border-color: black black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="95">
<div style="margin-bottom: 3.9pt; line-height: 125%;">12345678</div>
</td>
<td style="width: 70.85pt; border-width: 1pt 1pt 1pt medium; border-style: solid solid solid none; border-color: black black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="94">
<div style="margin-bottom: 3.9pt; line-height: 125%;">12345678</div>
</td>
<td style="width: 70.9pt; border-width: 1pt 1pt 1pt medium; border-style: solid solid solid none; border-color: black black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="95">
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
</td>
</tr>
<tr>
<td style="width: 85.2pt; border-width: medium 1pt 1pt; border-style: none solid solid; border-color: -moz-use-text-color black black; padding: 0cm 5.4pt;" valign="top" width="114">
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">转换后</span>bit<span style="font-family: 宋体;">内容</span></div>
</td>
<td style="width: 69.05pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="92">
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">00</span>123456</div>
</td>
<td style="width: 70.9pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="95">
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">00</span>781234</div>
</td>
<td style="width: 70.85pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="94">
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">00</span>567812</div>
</td>
<td style="width: 70.9pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="95">
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">00</span>345678</div>
</td>
</tr>
</tbody>
</table>
</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">如果字节串不是</span>3<span style="font-family: 宋体;">的位数，不足的bit用0填充，不足的字节使用填充字符。下面是</span>2<span style="font-family: 宋体;">字节编码成</span>4<span style="font-family: 宋体;">字节：</span></div>
<div align="center">
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse; border: medium none;">
<tbody>
<tr>
<td style="width: 85.2pt; border: 1pt solid black; padding: 0cm 5.4pt;" valign="top" width="114">
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">转换前</span>bit<span style="font-family: 宋体;">内容</span></div>
</td>
<td style="width: 69.05pt; border-width: 1pt 1pt 1pt medium; border-style: solid solid solid none; border-color: black black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="92">
<div style="margin-bottom: 3.9pt; line-height: 125%;">12345678</div>
</td>
<td style="width: 70.9pt; border-width: 1pt 1pt 1pt medium; border-style: solid solid solid none; border-color: black black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="95">
<div style="margin-bottom: 3.9pt; line-height: 125%;">12345678</div>
</td>
<td style="width: 70.85pt; border-width: 1pt 1pt 1pt medium; border-style: solid solid solid none; border-color: black black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="94">
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">pad</span></div>
</td>
<td style="width: 70.9pt; border-width: 1pt 1pt 1pt medium; border-style: solid solid solid none; border-color: black black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="95">
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
</td>
</tr>
<tr>
<td style="width: 85.2pt; border-width: medium 1pt 1pt; border-style: none solid solid; border-color: -moz-use-text-color black black; padding: 0cm 5.4pt;" valign="top" width="114">
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">转换后</span>bit<span style="font-family: 宋体;">内容</span></div>
</td>
<td style="width: 69.05pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="92">
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">00</span>123456</div>
</td>
<td style="width: 70.9pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="95">
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">00</span>781234</div>
</td>
<td style="width: 70.85pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="94">
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">00</span>5678<span style="color: red;">00</span></div>
</td>
<td style="width: 70.9pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="95">
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">=</span></div>
</td>
</tr>
</tbody>
</table>
</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">如：&ldquo;张&rdquo;占用</span>2<span style="font-family: 宋体;">个字节，字节内容是：</span>11010101 11000101<span style="font-family: 宋体;">，</span>16<span style="font-family: 宋体;">进制（</span>Base16<span style="font-family: 宋体;">）表示就是：</span>D5C5<span style="font-family: 宋体;">。编码成</span>Base64<span style="font-family: 宋体;">，需要使用填充字符补齐成</span>3<span style="font-family: 宋体;">字节再编码，编码结果是</span>1iU=</div>
<div align="center">
<table border="1" cellpadding="0" cellspacing="0" style="border-collapse: collapse; border: medium none;">
<tbody>
<tr>
<td style="width: 85.2pt; border: 1pt solid black; padding: 0cm 5.4pt;" valign="top" width="114">
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">转换前</span>bit<span style="font-family: 宋体;">内容</span></div>
</td>
<td style="width: 69.05pt; border-width: 1pt 1pt 1pt medium; border-style: solid solid solid none; border-color: black black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="92">
<div style="margin-bottom: 3.9pt; line-height: 125%;">11010101</div>
</td>
<td style="width: 70.9pt; border-width: 1pt 1pt 1pt medium; border-style: solid solid solid none; border-color: black black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="95">
<div style="margin-bottom: 3.9pt; line-height: 125%;">11000101</div>
</td>
<td style="width: 70.85pt; border-width: 1pt 1pt 1pt medium; border-style: solid solid solid none; border-color: black black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="94">
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">pad</span></div>
</td>
<td style="width: 70.9pt; border-width: 1pt 1pt 1pt medium; border-style: solid solid solid none; border-color: black black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="95">
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
</td>
</tr>
<tr>
<td style="width: 85.2pt; border-width: medium 1pt 1pt; border-style: none solid solid; border-color: -moz-use-text-color black black; padding: 0cm 5.4pt;" valign="top" width="114">
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">转换后</span>bit<span style="font-family: 宋体;">内容</span></div>
</td>
<td style="width: 69.05pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="92">
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">00</span>110101</div>
</td>
<td style="width: 70.9pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="95">
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">00</span>011100</div>
</td>
<td style="width: 70.85pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="94">
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">00</span>0101<span style="color: red;">00</span></div>
</td>
<td style="width: 70.9pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="95">
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">=</span></div>
</td>
</tr>
<tr>
<td style="width: 85.2pt; border-width: medium 1pt 1pt; border-style: none solid solid; border-color: -moz-use-text-color black black; padding: 0cm 5.4pt;" valign="top" width="114">
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">转换后字符</span></div>
</td>
<td style="width: 69.05pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="92">
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">1</span><span style="font-family: 宋体; color: red;">（</span><span style="color: red;">53</span><span style="font-family: 宋体; color: red;">）</span></div>
</td>
<td style="width: 70.9pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="95">
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">i</span><span style="font-family: 宋体; color: red;">（</span><span style="color: red;">34</span><span style="font-family: 宋体; color: red;">）</span></div>
</td>
<td style="width: 70.85pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="94">
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">U</span><span style="font-family: 宋体; color: red;">（</span><span style="color: red;">20</span><span style="font-family: 宋体; color: red;">）</span></div>
</td>
<td style="width: 70.9pt; border-width: medium 1pt 1pt medium; border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; padding: 0cm 5.4pt;" valign="top" width="95">
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">=</span></div>
</td>
</tr>
</tbody>
</table>
</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><b><span style="font-size: 12pt; line-height: 125%; font-family: 宋体;">编码过程</span></b></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">第一个字符通过右移</span>2<span style="font-family: 宋体;">位获得第一个目标字符的</span>Base64<span style="font-family: 宋体;">表位置，根据这个数值取到表上相应的字符，就是第一个目标字符。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">然后将第一个字符左移</span>4 <span style="font-family: 宋体;">位加上第二个字符右移</span>4<span style="font-family: 宋体;">位，即获得第二个目标字符。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">再将第二个字符左移</span>2<span style="font-family: 宋体;">位加上第三个字符右移</span>6<span style="font-family: 宋体;">位，获得第三个目标字符。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">最后取第三个字符的右</span>6<span style="font-family: 宋体;">位即获得第四个目标字符。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">在以上的每一个步骤之后，再把结果与</span> 0&#215;3f <span style="font-family: 宋体;">进行</span> AND <span style="font-family: 宋体;">位操作，就可以得到编码后的字符了。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">如果原文字节数不是</span>3<span style="font-family: 宋体;">的倍数，补齐尾部不足的字节使用填充字符。</span></div>
]]></content:encoded>
			<wfw:commentRss>http://www.shenmiguo.com/archives/2010/326_base64-encode.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mysql状态变量性能调优</title>
		<link>http://www.shenmiguo.com/archives/2009/325_mysql-status-optimization.html</link>
		<comments>http://www.shenmiguo.com/archives/2009/325_mysql-status-optimization.html#comments</comments>
		<pubDate>Sun, 15 Nov 2009 15:32:04 +0000</pubDate>
		<dc:creator>神秘果</dc:creator>
				<category><![CDATA[数据库]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.shenmiguo.com/?p=325</guid>
		<description><![CDATA[Mysql状态变量通过&#8221;show global status&#8221;（自Mysql上次启动以来的统计）获取，重要的参数包括各种SQL执行频率，索引使用情况、锁资源使用情况等。
长时间运行的Mysql服务器，运行flush status;可以重置一些计数器优化性能。

例如DB服务器是4核16G内存，通过状态变量，可以优化Mysql静态变量和SQL：
&#160;





参数


说明




基本情况


&#160;




Connections


连接服务器(不管是否成功)的次数




Uptime


服务器工作时间




Max_used_connections


同时使用的最大连接数量




Open_tables


当前打开的表的数量。




Opened_tables


已经打开的表的数量。调优静态变量表缓存数table_cache：如果open_tables接近table_cache，并且opened_tables不断增长，就需要增加table_cache的值。
table_cache是所有线程打开的表的数目(一个表使用2个文件描述符)，表数量多，就要大一些。增大该值可以增加mysqld需要的文件描述符的数量。根据数据库系统中表数量来决定该值，如2048。




线程使用情况


&#160;




Threads_cached


线程缓存内的线程数




Threads_connected


当前打开的线程数




Threads_created


创建过的线程数。调优静态变量线程缓存数thread_cache：如果该值增加很快，当前thread_cache_size的值可能太小。缓存访问率是Threads_created/Connections。
服务器应缓存多少线程以便重新使用。当客户端断开连接时，如果线程少于thread_cache_size，则客户端的线程被放入缓存，一般配置8。




Threads_running


运行(非睡眠)状态的线程数




查询缓存


&#160;




Qcache_free_blocks


缓存中相邻内存块的个数。数目大说明可能有碎片。调优方法：FLUSH QUERY CACHE;会对缓存中的碎片进行整理，从而得到一个空闲块，如果flush运行的时间很长，说明缓存太大了，可以适当调小静态变量query_cache_size的值。




Qcache_free_memory


缓存中剩余的内存。调优静态参数query_cache_size：如果剩余内存不足，可以增加该值，如设置query_cache_size=64M




Qcache_hits


查询缓存命中次数，该值越大越好




Qcache_inserts


插入查询缓存的次数。缓存命中率 = 1 &#8211; Qcache_hits/ Qcache_inserts。80%以上的查询缓存命中率就算合格。




Qcache_lowmem_prunes


查询缓存过低的次数。缓存出现内存不足并且必须要进行清理以便为更多查询提供空间的次数。这个数字最好长时间来看；如果这个数字在不断增长，就表示可能碎片非常严重，或者内存很少。（上面的 free_blocks 和 free_memory 可以告诉您属于哪种情况）。




Qcache_not_cached


不适合进行缓存的查询的数量，通常是由于这些查询不是 SELECT 语句。




Qcache_queries_in_cache


当前缓存的查询（和响应）的数量。




Qcache_total_blocks


缓存中块的数量。




SQL执行频率


&#160;




Com_select


执行select操作次数




Com_insert


执行insert操作次数




Com_update


执行update操作次数




Com_delete


执行delete操作次数




Com_commit


事务执行commit操作次数




Comm_rollback


事务执行rollback操作次数。如果回滚频繁，就说明程序存在某些问题。




Slow_queries


慢查询的次数。调优SQL性能：如果该值增加很快，需要分析慢查询日志，针对查询SQL优化。




Innodb_rows_read


执行select返回的行数。以下几个InnoDB的。




Innodb_rows_inserted


执行insert操作的行数。通过这几个参数，可以知道数据库是查询为主还是插入为主。




Innodb_rows_updated


执行update操作的行数




Innodb_rows_deleted


执行delete操作的行数




Sort_merge_passes


排序算法已经执行的合并的数量。调优静态变量sort_buffer_size：如果该值很大，说明排序缓冲区太小，如设置sort_buffer_size = 5M
当 MySQL 必须要进行排序时，就会在从磁盘上读取数据时分配一个排序缓冲区来存放这些数据行。如果要排序的数据太大，那么数据就必须保存到磁盘上的临时文件中，并再次进行排序。




索引使用情况


&#160;




Handler_read_first


使用全索引扫描的次数。如SELECT col1 FROM foo，假定col1有索引




Handler_read_key


使用索引次数，该值越高越好。




Handler_read_next


按照键顺序读下一行的请求数。使用索引描述时，从数据文件取数据的次数




Handler_read_prev


使用索引描述时，按索引倒序从数据文件取数据的次数。一般是order by/desc查询




Handler_read_rnd


查询直接操作数据文件的次数，有可能未使用索引




Handler_read_rnd_next


在数据文件中读下一行的请求数。若该值非常大，说明使用了大量的表扫描，索引使用率不高或没有使用索引。Handler_read_rnd_next/Com_select是表扫描比率，如果该值超过 4000，就应该调优静态参数read_buffer_size。如read_buffer_size=1M，若超过8M，那么就要优化SQL了。




锁使用情况


&#160;




Innodb_row_lock_current_waits


当前等待行锁的行数




Innodb_row_lock_time


行锁定用的总时间(ms)




Innodb_row_lock_time_avg


行锁定的平均时间(ms)。该值大，说明锁冲突大




Innodb_row_lock_time_max


行锁定的最长时间(ms)




Innodb_row_lock_waits


行锁定必须等待的时间(ms)。该值大，说明锁冲突大





&#160;
]]></description>
			<content:encoded><![CDATA[<p>Mysql<span style="font-family: 宋体;">状态变量通过</span>&rdquo;show global status&rdquo;<span style="font-family: 宋体;">（自</span>Mysql<span style="font-family: 宋体;">上次启动以来的统计）获取，重要的参数包括各种</span>SQL<span style="font-family: 宋体;">执行频率，索引使用情况、锁资源使用情况等。</span></p>
<div style="line-height: 125%;"><span style="font-family: 宋体;">长时间运行的</span>Mysql<span style="font-family: 宋体;">服务器，运行</span>flush status;<span style="font-family: 宋体;">可以重置一些计数器优化性能。</span></div>
<div style="line-height: 125%;"><span id="more-325"></span></div>
<div style="line-height: 125%;"><span style="font-family: 宋体;">例如</span>DB<span style="font-family: 宋体;">服务器是</span>4<span style="font-family: 宋体;">核</span>16G<span style="font-family: 宋体;">内存，通过状态变量，可以优化</span>Mysql<span style="font-family: 宋体;">静态变量和</span>SQL<span style="font-family: 宋体;">：</span></div>
<div style="line-height: 125%;">&nbsp;</div>
<div align="center">
<table border="1" cellpadding="0" cellspacing="0" style="border: medium none ; border-collapse: collapse;">
<tbody>
<tr>
<td style="border: 1pt solid black; padding: 0cm 5.4pt; width: 127.1pt;" valign="top" width="169">
<div align="center" style="text-align: center; line-height: 150%;"><b><span style="font-family: 宋体;">参数</span></b></div>
</td>
<td style="border-style: solid solid solid none; border-color: black black black -moz-use-text-color; border-width: 1pt 1pt 1pt medium; padding: 0cm 5.4pt; width: 287.15pt;" valign="top" width="383">
<div align="center" style="text-align: center; line-height: 150%;"><b><span style="font-family: 宋体;">说明</span></b></div>
</td>
</tr>
<tr>
<td style="border-style: none solid solid; border-color: -moz-use-text-color black black; border-width: medium 1pt 1pt; padding: 0cm 5.4pt; width: 127.1pt;" valign="top" width="169">
<div style="line-height: 150%;"><b><span style="font-family: 宋体;">基本情况</span></b></div>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0cm 5.4pt; width: 287.15pt;" valign="top" width="383">
<div align="center" style="text-align: center; line-height: 150%;"><b>&nbsp;</b></div>
</td>
</tr>
<tr>
<td style="border-style: none solid solid; border-color: -moz-use-text-color black black; border-width: medium 1pt 1pt; padding: 0cm 5.4pt; width: 127.1pt;" valign="top" width="169">
<div style="line-height: 150%;">Connections</div>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0cm 5.4pt; width: 287.15pt;" valign="top" width="383">
<div style="line-height: 150%;"><span style="font-family: 宋体;">连接服务器</span>(<span style="font-family: 宋体;">不管是否成功</span>)<span style="font-family: 宋体;">的次数</span></div>
</td>
</tr>
<tr>
<td style="border-style: none solid solid; border-color: -moz-use-text-color black black; border-width: medium 1pt 1pt; padding: 0cm 5.4pt; width: 127.1pt;" valign="top" width="169">
<div style="line-height: 150%;">Uptime</div>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0cm 5.4pt; width: 287.15pt;" valign="top" width="383">
<div style="line-height: 150%;"><span style="font-family: 宋体;">服务器工作时间</span></div>
</td>
</tr>
<tr>
<td style="border-style: none solid solid; border-color: -moz-use-text-color black black; border-width: medium 1pt 1pt; padding: 0cm 5.4pt; width: 127.1pt;" valign="top" width="169">
<div style="line-height: 150%;">Max_used_connections</div>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0cm 5.4pt; width: 287.15pt;" valign="top" width="383">
<div style="line-height: 150%;"><span style="font-family: 宋体;">同时使用的最大连接数量</span></div>
</td>
</tr>
<tr>
<td style="border-style: none solid solid; border-color: -moz-use-text-color black black; border-width: medium 1pt 1pt; padding: 0cm 5.4pt; width: 127.1pt;" valign="top" width="169">
<div style="line-height: 150%;">Open_tables</div>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0cm 5.4pt; width: 287.15pt;" valign="top" width="383">
<div style="line-height: 150%;"><span style="font-family: 宋体;">当前打开的表的数量。</span></div>
</td>
</tr>
<tr>
<td style="border-style: none solid solid; border-color: -moz-use-text-color black black; border-width: medium 1pt 1pt; padding: 0cm 5.4pt; width: 127.1pt;" valign="top" width="169">
<div style="line-height: 150%;"><span style="color: red;">Opened_tables</span></div>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0cm 5.4pt; width: 287.15pt;" valign="top" width="383">
<div style="line-height: 150%;"><span style="font-family: 宋体;">已经打开的表的数量。<span style="color: red;">调优静态变量表缓存数</span></span><span style="color: red;">table_cache</span><span style="font-family: 宋体;">：如果</span>open_tables<span style="font-family: 宋体;">接近</span>table_cache<span style="font-family: 宋体;">，并且</span>opened_tables<span style="font-family: 宋体;">不断增长，就需要增加</span>table_cache<span style="font-family: 宋体;">的值。</span></div>
<div style="line-height: 150%;">table_cache<span style="font-family: 宋体;">是所有线程打开的表的数目</span>(<span style="font-family: 宋体;">一个表使用</span>2<span style="font-family: 宋体;">个文件描述符</span>)<span style="font-family: 宋体;">，表数量多，就要大一些。增大该值可以增加</span>mysqld<span style="font-family: 宋体;">需要的文件描述符的数量。根据数据库系统中表数量来决定该值，如</span>2048<span style="font-family: 宋体;">。</span></div>
</td>
</tr>
<tr>
<td style="border-style: none solid solid; border-color: -moz-use-text-color black black; border-width: medium 1pt 1pt; padding: 0cm 5.4pt; width: 127.1pt;" valign="top" width="169">
<div style="line-height: 150%;"><b><span style="font-family: 宋体;">线程使用情况</span></b></div>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0cm 5.4pt; width: 287.15pt;" valign="top" width="383">
<div style="line-height: 150%;"><b>&nbsp;</b></div>
</td>
</tr>
<tr>
<td style="border-style: none solid solid; border-color: -moz-use-text-color black black; border-width: medium 1pt 1pt; padding: 0cm 5.4pt; width: 127.1pt;" valign="top" width="169">
<div style="line-height: 150%;">Threads_cached</div>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0cm 5.4pt; width: 287.15pt;" valign="top" width="383">
<div style="line-height: 150%;"><span style="font-family: 宋体;">线程缓存内的线程数</span></div>
</td>
</tr>
<tr>
<td style="border-style: none solid solid; border-color: -moz-use-text-color black black; border-width: medium 1pt 1pt; padding: 0cm 5.4pt; width: 127.1pt;" valign="top" width="169">
<div style="line-height: 150%;">Threads_connected</div>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0cm 5.4pt; width: 287.15pt;" valign="top" width="383">
<div style="line-height: 150%;"><span style="font-family: 宋体;">当前打开的线程数</span></div>
</td>
</tr>
<tr>
<td style="border-style: none solid solid; border-color: -moz-use-text-color black black; border-width: medium 1pt 1pt; padding: 0cm 5.4pt; width: 127.1pt;" valign="top" width="169">
<div style="line-height: 150%;"><span style="color: red;">Threads_created</span></div>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0cm 5.4pt; width: 287.15pt;" valign="top" width="383">
<div style="line-height: 150%;"><span style="font-family: 宋体;">创建过的线程数。<span style="color: red;">调优静态变量线程缓存数</span></span><span style="color: red;">thread_cache</span><span style="font-family: 宋体;">：如果该值增加很快，当前</span>thread_cache_size<span style="font-family: 宋体;">的值可能太小。缓存访问率是</span>Threads_created/Connections<span style="font-family: 宋体;">。</span></div>
<div style="line-height: 150%;"><span style="font-family: 宋体;">服务器应缓存多少线程以便重新使用。当客户端断开连接时，如果线程少于</span>thread_cache_size<span style="font-family: 宋体;">，则客户端的线程被放入缓存，一般配置</span>8<span style="font-family: 宋体;">。</span></div>
</td>
</tr>
<tr>
<td style="border-style: none solid solid; border-color: -moz-use-text-color black black; border-width: medium 1pt 1pt; padding: 0cm 5.4pt; width: 127.1pt;" valign="top" width="169">
<div style="line-height: 150%;">Threads_running</div>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0cm 5.4pt; width: 287.15pt;" valign="top" width="383">
<div style="line-height: 150%;"><span style="font-family: 宋体;">运行</span>(<span style="font-family: 宋体;">非睡眠</span>)<span style="font-family: 宋体;">状态的线程数</span></div>
</td>
</tr>
<tr>
<td style="border-style: none solid solid; border-color: -moz-use-text-color black black; border-width: medium 1pt 1pt; padding: 0cm 5.4pt; width: 127.1pt;" valign="top" width="169">
<div style="line-height: 150%;"><b><span style="font-family: 宋体;">查询缓存</span></b></div>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0cm 5.4pt; width: 287.15pt;" valign="top" width="383">
<div style="line-height: 150%;">&nbsp;</div>
</td>
</tr>
<tr>
<td style="border-style: none solid solid; border-color: -moz-use-text-color black black; border-width: medium 1pt 1pt; padding: 0cm 5.4pt; width: 127.1pt;" valign="top" width="169">
<div style="line-height: 150%;"><span style="color: red;">Qcache_free_blocks</span></div>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0cm 5.4pt; width: 287.15pt;" valign="top" width="383">
<div style="line-height: 150%;"><span style="font-family: 宋体;">缓存中相邻内存块的个数。数目大说明可能有碎片。<span style="color: red;">调优方法</span>：</span><span style="color: red;">FLUSH QUERY CACHE;</span><span style="font-family: 宋体;">会对缓存中的碎片进行整理，从而得到一个空闲块，如果</span>flush<span style="font-family: 宋体;">运行的时间很长，说明缓存太大了，可以适当调小静态变量</span>query_cache_size<span style="font-family: 宋体;">的值。</span></div>
</td>
</tr>
<tr>
<td style="border-style: none solid solid; border-color: -moz-use-text-color black black; border-width: medium 1pt 1pt; padding: 0cm 5.4pt; width: 127.1pt;" valign="top" width="169">
<div style="line-height: 150%;">Qcache_free_memory</div>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0cm 5.4pt; width: 287.15pt;" valign="top" width="383">
<div style="line-height: 150%;"><span style="font-family: 宋体;">缓存中剩余的内存。<span style="color: red;">调优静态参数</span></span><span style="color: red;">query_cache_size</span><span style="font-family: 宋体;">：如果剩余内存不足，可以增加该值，如设置</span>query_cache_size=64M</div>
</td>
</tr>
<tr>
<td style="border-style: none solid solid; border-color: -moz-use-text-color black black; border-width: medium 1pt 1pt; padding: 0cm 5.4pt; width: 127.1pt;" valign="top" width="169">
<div style="line-height: 150%;">Qcache_hits</div>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0cm 5.4pt; width: 287.15pt;" valign="top" width="383">
<div style="line-height: 150%;"><span style="font-family: 宋体;">查询缓存命中次数，该值越大越好</span></div>
</td>
</tr>
<tr>
<td style="border-style: none solid solid; border-color: -moz-use-text-color black black; border-width: medium 1pt 1pt; padding: 0cm 5.4pt; width: 127.1pt;" valign="top" width="169">
<div style="line-height: 150%;">Qcache_inserts</div>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0cm 5.4pt; width: 287.15pt;" valign="top" width="383">
<div style="line-height: 150%;"><span style="font-family: 宋体;">插入查询缓存的次数。<span style="color: red;">缓存命中率</span></span> = 1 &#8211; Qcache_hits/ Qcache_inserts<span style="font-family: 宋体;">。</span>80%<span style="font-family: 宋体;">以上的查询缓存命中率就算合格。</span></div>
</td>
</tr>
<tr>
<td style="border-style: none solid solid; border-color: -moz-use-text-color black black; border-width: medium 1pt 1pt; padding: 0cm 5.4pt; width: 127.1pt;" valign="top" width="169">
<div style="line-height: 150%;"><span style="color: red;">Qcache_lowmem_prunes</span></div>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0cm 5.4pt; width: 287.15pt;" valign="top" width="383">
<div style="line-height: 150%;"><span style="font-family: 宋体;">查询缓存过低的次数。缓存出现内存不足并且必须要进行清理以便为更多查询提供空间的次数。这个数字最好长时间来看；如果这个数字在不断增长，就表示可能碎片非常严重，或者内存很少。（上面的</span> free_blocks <span style="font-family: 宋体;">和</span> free_memory <span style="font-family: 宋体;">可以告诉您属于哪种情况）。</span></div>
</td>
</tr>
<tr>
<td style="border-style: none solid solid; border-color: -moz-use-text-color black black; border-width: medium 1pt 1pt; padding: 0cm 5.4pt; width: 127.1pt;" valign="top" width="169">
<div style="line-height: 150%;">Qcache_not_cached</div>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0cm 5.4pt; width: 287.15pt;" valign="top" width="383">
<div style="line-height: 150%;"><span style="font-family: 宋体;">不适合进行缓存的查询的数量，通常是由于这些查询不是</span> SELECT <span style="font-family: 宋体;">语句。</span></div>
</td>
</tr>
<tr>
<td style="border-style: none solid solid; border-color: -moz-use-text-color black black; border-width: medium 1pt 1pt; padding: 0cm 5.4pt; width: 127.1pt;" valign="top" width="169">
<div style="line-height: 150%;">Qcache_queries_in_cache</div>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0cm 5.4pt; width: 287.15pt;" valign="top" width="383">
<div style="line-height: 150%;"><span style="font-family: 宋体;">当前缓存的查询（和响应）的数量。</span></div>
</td>
</tr>
<tr>
<td style="border-style: none solid solid; border-color: -moz-use-text-color black black; border-width: medium 1pt 1pt; padding: 0cm 5.4pt; width: 127.1pt;" valign="top" width="169">
<div style="line-height: 150%;">Qcache_total_blocks</div>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0cm 5.4pt; width: 287.15pt;" valign="top" width="383">
<div style="line-height: 150%;"><span style="font-family: 宋体;">缓存中块的数量。</span></div>
</td>
</tr>
<tr>
<td style="border-style: none solid solid; border-color: -moz-use-text-color black black; border-width: medium 1pt 1pt; padding: 0cm 5.4pt; width: 127.1pt;" valign="top" width="169">
<div style="line-height: 150%;"><b>SQL</b><b><span style="font-family: 宋体;">执行频率</span></b></div>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0cm 5.4pt; width: 287.15pt;" valign="top" width="383">
<div style="line-height: 150%;">&nbsp;</div>
</td>
</tr>
<tr>
<td style="border-style: none solid solid; border-color: -moz-use-text-color black black; border-width: medium 1pt 1pt; padding: 0cm 5.4pt; width: 127.1pt;" valign="top" width="169">
<div style="line-height: 150%;">Com_select</div>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0cm 5.4pt; width: 287.15pt;" valign="top" width="383">
<div style="line-height: 150%;"><span style="font-family: 宋体;">执行</span>select<span style="font-family: 宋体;">操作次数</span></div>
</td>
</tr>
<tr>
<td style="border-style: none solid solid; border-color: -moz-use-text-color black black; border-width: medium 1pt 1pt; padding: 0cm 5.4pt; width: 127.1pt;" valign="top" width="169">
<div style="line-height: 150%;">Com_insert</div>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0cm 5.4pt; width: 287.15pt;" valign="top" width="383">
<div style="line-height: 150%;"><span style="font-family: 宋体;">执行</span>insert<span style="font-family: 宋体;">操作次数</span></div>
</td>
</tr>
<tr>
<td style="border-style: none solid solid; border-color: -moz-use-text-color black black; border-width: medium 1pt 1pt; padding: 0cm 5.4pt; width: 127.1pt;" valign="top" width="169">
<div style="line-height: 150%;">Com_update</div>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0cm 5.4pt; width: 287.15pt;" valign="top" width="383">
<div style="line-height: 150%;"><span style="font-family: 宋体;">执行</span>update<span style="font-family: 宋体;">操作次数</span></div>
</td>
</tr>
<tr>
<td style="border-style: none solid solid; border-color: -moz-use-text-color black black; border-width: medium 1pt 1pt; padding: 0cm 5.4pt; width: 127.1pt;" valign="top" width="169">
<div style="line-height: 150%;">Com_delete</div>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0cm 5.4pt; width: 287.15pt;" valign="top" width="383">
<div style="line-height: 150%;"><span style="font-family: 宋体;">执行</span>delete<span style="font-family: 宋体;">操作次数</span></div>
</td>
</tr>
<tr>
<td style="border-style: none solid solid; border-color: -moz-use-text-color black black; border-width: medium 1pt 1pt; padding: 0cm 5.4pt; width: 127.1pt;" valign="top" width="169">
<div style="line-height: 150%;">Com_commit</div>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0cm 5.4pt; width: 287.15pt;" valign="top" width="383">
<div style="line-height: 150%;"><span style="font-family: 宋体;">事务执行</span>commit<span style="font-family: 宋体;">操作次数</span></div>
</td>
</tr>
<tr>
<td style="border-style: none solid solid; border-color: -moz-use-text-color black black; border-width: medium 1pt 1pt; padding: 0cm 5.4pt; width: 127.1pt;" valign="top" width="169">
<div style="line-height: 150%;"><span style="color: red;">Comm_rollback</span></div>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0cm 5.4pt; width: 287.15pt;" valign="top" width="383">
<div style="line-height: 150%;"><span style="font-family: 宋体;">事务执行</span>rollback<span style="font-family: 宋体;">操作次数。如果回滚频繁，就说明程序存在某些问题。</span></div>
</td>
</tr>
<tr>
<td style="border-style: none solid solid; border-color: -moz-use-text-color black black; border-width: medium 1pt 1pt; padding: 0cm 5.4pt; width: 127.1pt;" valign="top" width="169">
<div style="line-height: 150%;"><span style="color: red;">Slow_queries</span></div>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0cm 5.4pt; width: 287.15pt;" valign="top" width="383">
<div style="line-height: 150%;"><span style="font-family: 宋体;">慢查询的次数。<span style="color: red;">调优</span></span><span style="color: red;">SQL</span><span style="font-family: 宋体; color: red;">性能</span><span style="font-family: 宋体;">：如果该值增加很快，需要分析慢查询日志，针对查询</span>SQL<span style="font-family: 宋体;">优化。</span></div>
</td>
</tr>
<tr>
<td style="border-style: none solid solid; border-color: -moz-use-text-color black black; border-width: medium 1pt 1pt; padding: 0cm 5.4pt; width: 127.1pt;" valign="top" width="169">
<div style="line-height: 150%;">Innodb_rows_read</div>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0cm 5.4pt; width: 287.15pt;" valign="top" width="383">
<div style="line-height: 150%;"><span style="font-family: 宋体;">执行</span>select<span style="font-family: 宋体;">返回的行数。以下几个</span>InnoDB<span style="font-family: 宋体;">的。</span></div>
</td>
</tr>
<tr>
<td style="border-style: none solid solid; border-color: -moz-use-text-color black black; border-width: medium 1pt 1pt; padding: 0cm 5.4pt; width: 127.1pt;" valign="top" width="169">
<div style="line-height: 150%;">Innodb_rows_inserted</div>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0cm 5.4pt; width: 287.15pt;" valign="top" width="383">
<div style="line-height: 150%;"><span style="font-family: 宋体;">执行</span>insert<span style="font-family: 宋体;">操作的行数。通过这几个参数，可以知道数据库是查询为主还是插入为主。</span></div>
</td>
</tr>
<tr>
<td style="border-style: none solid solid; border-color: -moz-use-text-color black black; border-width: medium 1pt 1pt; padding: 0cm 5.4pt; width: 127.1pt;" valign="top" width="169">
<div style="line-height: 150%;">Innodb_rows_updated</div>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0cm 5.4pt; width: 287.15pt;" valign="top" width="383">
<div style="line-height: 150%;"><span style="font-family: 宋体;">执行</span>update<span style="font-family: 宋体;">操作的行数</span></div>
</td>
</tr>
<tr>
<td style="border-style: none solid solid; border-color: -moz-use-text-color black black; border-width: medium 1pt 1pt; padding: 0cm 5.4pt; width: 127.1pt;" valign="top" width="169">
<div style="line-height: 150%;">Innodb_rows_deleted</div>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0cm 5.4pt; width: 287.15pt;" valign="top" width="383">
<div style="line-height: 150%;"><span style="font-family: 宋体;">执行</span>delete<span style="font-family: 宋体;">操作的行数</span></div>
</td>
</tr>
<tr>
<td style="border-style: none solid solid; border-color: -moz-use-text-color black black; border-width: medium 1pt 1pt; padding: 0cm 5.4pt; width: 127.1pt;" valign="top" width="169">
<div style="line-height: 150%;"><span style="color: red;">Sort_merge_passes</span></div>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0cm 5.4pt; width: 287.15pt;" valign="top" width="383">
<div style="line-height: 150%;"><span style="font-family: 宋体;">排序算法已经执行的合并的数量。<span style="color: red;">调优静态变量</span></span><span style="color: red;">sort_buffer_size</span><span style="font-family: 宋体;">：如果该值很大，说明排序缓冲区太小，如设置</span>sort_buffer_size = 5M</div>
<div style="line-height: 150%;"><font class="Apple-style-span" face="宋体" size="4"><span class="Apple-style-span" style="font-size: 14px;"><span style="font-size:10.5pt;<br />
font-family:宋体;Times New Roman&quot;;">当</span><span style="font-size:10.5pt;font-family:&quot;Calibri&quot;,&quot;sans-serif&quot;;Times New Roman&quot;;"> MySQL </span><span style="font-size:10.5pt;font-family:宋体;Times New Roman&quot;;">必须要进行排序时，就会在从磁盘上读取数据时分配一个排序缓冲区来存放这些数据行。如果要排序的数据太大，那么数据就必须保存到磁盘上的临时文件中，并再次进行排序。</span></span></font></div>
</td>
</tr>
<tr>
<td style="border-style: none solid solid; border-color: -moz-use-text-color black black; border-width: medium 1pt 1pt; padding: 0cm 5.4pt; width: 127.1pt;" valign="top" width="169">
<div style="line-height: 150%;"><b><span style="font-family: 宋体;">索引使用情况</span></b></div>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0cm 5.4pt; width: 287.15pt;" valign="top" width="383">
<div style="line-height: 150%;">&nbsp;</div>
</td>
</tr>
<tr>
<td style="border-style: none solid solid; border-color: -moz-use-text-color black black; border-width: medium 1pt 1pt; padding: 0cm 5.4pt; width: 127.1pt;" valign="top" width="169">
<div style="line-height: 150%;"><span style="line-height: 150%; font-family: &quot;Trebuchet MS&quot;,&quot;sans-serif&quot;; color: black;">Handler_read_first</span></div>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0cm 5.4pt; width: 287.15pt;" valign="top" width="383">
<div style="line-height: 150%;"><span style="font-family: 宋体;">使用全索引扫描的次数。如</span>SELECT col1 FROM foo<span style="font-family: 宋体;">，假定</span>col1<span style="font-family: 宋体;">有索引</span></div>
</td>
</tr>
<tr>
<td style="border-style: none solid solid; border-color: -moz-use-text-color black black; border-width: medium 1pt 1pt; padding: 0cm 5.4pt; width: 127.1pt;" valign="top" width="169">
<div style="line-height: 150%;"><span style="line-height: 150%; font-family: &quot;Trebuchet MS&quot;,&quot;sans-serif&quot;; color: black;">Handler_read_key</span></div>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0cm 5.4pt; width: 287.15pt;" valign="top" width="383">
<div style="line-height: 150%;"><span style="font-family: 宋体;">使用索引次数，该值越高越好。</span></div>
</td>
</tr>
<tr>
<td style="border-style: none solid solid; border-color: -moz-use-text-color black black; border-width: medium 1pt 1pt; padding: 0cm 5.4pt; width: 127.1pt;" valign="top" width="169">
<div style="line-height: 150%;"><span style="line-height: 150%; font-family: &quot;Trebuchet MS&quot;,&quot;sans-serif&quot;; color: black;">Handler_read_next</span></div>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0cm 5.4pt; width: 287.15pt;" valign="top" width="383">
<div style="line-height: 150%;"><span style="font-family: 宋体;">按照键顺序读下一行的请求数。使用索引描述时，从数据文件取数据的次数</span></div>
</td>
</tr>
<tr>
<td style="border-style: none solid solid; border-color: -moz-use-text-color black black; border-width: medium 1pt 1pt; padding: 0cm 5.4pt; width: 127.1pt;" valign="top" width="169">
<div style="line-height: 150%;"><span style="line-height: 150%; font-family: &quot;Trebuchet MS&quot;,&quot;sans-serif&quot;; color: black;">Handler_read_prev</span></div>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0cm 5.4pt; width: 287.15pt;" valign="top" width="383">
<div style="line-height: 150%;"><span style="font-family: 宋体;">使用索引描述时，按索引倒序从数据文件取数据的次数。一般是</span>order by/desc<span style="font-family: 宋体;">查询</span></div>
</td>
</tr>
<tr>
<td style="border-style: none solid solid; border-color: -moz-use-text-color black black; border-width: medium 1pt 1pt; padding: 0cm 5.4pt; width: 127.1pt;" valign="top" width="169">
<div style="line-height: 150%;"><span style="line-height: 150%; font-family: &quot;Trebuchet MS&quot;,&quot;sans-serif&quot;; color: black;">Handler_read_rnd</span></div>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0cm 5.4pt; width: 287.15pt;" valign="top" width="383">
<div style="line-height: 150%;"><span style="font-family: 宋体;">查询直接操作数据文件的次数，有可能未使用索引</span></div>
</td>
</tr>
<tr>
<td style="border-style: none solid solid; border-color: -moz-use-text-color black black; border-width: medium 1pt 1pt; padding: 0cm 5.4pt; width: 127.1pt;" valign="top" width="169">
<div style="line-height: 150%;"><span style="line-height: 150%; font-family: &quot;Trebuchet MS&quot;,&quot;sans-serif&quot;; color: red;">Handler_read_rnd_next</span></div>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0cm 5.4pt; width: 287.15pt;" valign="top" width="383">
<div style="line-height: 150%;"><span style="font-family: 宋体;">在数据文件中读下一行的请求数。若该值非常大，说明使用了大量的表扫描，索引使用率不高或没有使用索引。</span>Handler_read_rnd_next/Com_select<span style="font-family: 宋体;">是表扫描比率，如果该值超过</span> 4000<span style="font-family: 宋体;">，就应该<span style="color: red;">调优静态参数</span></span><span style="color: red;">read_buffer_size</span><span style="font-family: 宋体;">。如</span>read_buffer_size=1M<span style="font-family: 宋体;">，若超过</span>8M<span style="font-family: 宋体;">，那么就要优化</span>SQL<span style="font-family: 宋体;">了。</span></div>
</td>
</tr>
<tr>
<td style="border-style: none solid solid; border-color: -moz-use-text-color black black; border-width: medium 1pt 1pt; padding: 0cm 5.4pt; width: 127.1pt;" valign="top" width="169">
<div style="line-height: 150%;"><b><span style="font-family: 宋体;">锁使用情况</span></b></div>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0cm 5.4pt; width: 287.15pt;" valign="top" width="383">
<div style="line-height: 150%;">&nbsp;</div>
</td>
</tr>
<tr>
<td style="border-style: none solid solid; border-color: -moz-use-text-color black black; border-width: medium 1pt 1pt; padding: 0cm 5.4pt; width: 127.1pt;" valign="top" width="169">
<div style="line-height: 150%;"><span style="line-height: 150%; font-family: &quot;Trebuchet MS&quot;,&quot;sans-serif&quot;; color: black;">Innodb_row_lock_current_waits</span></div>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0cm 5.4pt; width: 287.15pt;" valign="top" width="383">
<div style="line-height: 150%;"><span style="font-family: 宋体;">当前等待行锁的行数</span></div>
</td>
</tr>
<tr>
<td style="border-style: none solid solid; border-color: -moz-use-text-color black black; border-width: medium 1pt 1pt; padding: 0cm 5.4pt; width: 127.1pt;" valign="top" width="169">
<div style="line-height: 150%;"><span style="line-height: 150%; font-family: &quot;Trebuchet MS&quot;,&quot;sans-serif&quot;; color: black;">Innodb_row_lock_time</span></div>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0cm 5.4pt; width: 287.15pt;" valign="top" width="383">
<div style="line-height: 150%;"><span style="font-family: 宋体;">行锁定用的总时间</span>(ms)</div>
</td>
</tr>
<tr>
<td style="border-style: none solid solid; border-color: -moz-use-text-color black black; border-width: medium 1pt 1pt; padding: 0cm 5.4pt; width: 127.1pt;" valign="top" width="169">
<div style="line-height: 150%;"><span style="line-height: 150%; font-family: &quot;Trebuchet MS&quot;,&quot;sans-serif&quot;; color: red;">Innodb_row_lock_time_avg</span></div>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0cm 5.4pt; width: 287.15pt;" valign="top" width="383">
<div style="line-height: 150%;"><span style="font-family: 宋体;">行锁定的平均时间</span>(ms)<span style="font-family: 宋体;">。该值大，说明锁冲突大</span></div>
</td>
</tr>
<tr>
<td style="border-style: none solid solid; border-color: -moz-use-text-color black black; border-width: medium 1pt 1pt; padding: 0cm 5.4pt; width: 127.1pt;" valign="top" width="169">
<div style="line-height: 150%;"><span style="line-height: 150%; font-family: &quot;Trebuchet MS&quot;,&quot;sans-serif&quot;; color: black;">Innodb_row_lock_time_max</span></div>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0cm 5.4pt; width: 287.15pt;" valign="top" width="383">
<div style="line-height: 150%;"><span style="font-family: 宋体;">行锁定的最长时间</span>(ms)</div>
</td>
</tr>
<tr>
<td style="border-style: none solid solid; border-color: -moz-use-text-color black black; border-width: medium 1pt 1pt; padding: 0cm 5.4pt; width: 127.1pt;" valign="top" width="169">
<div style="line-height: 150%;"><span style="line-height: 150%; font-family: &quot;Trebuchet MS&quot;,&quot;sans-serif&quot;; color: red;">Innodb_row_lock_waits</span></div>
</td>
<td style="border-style: none solid solid none; border-color: -moz-use-text-color black black -moz-use-text-color; border-width: medium 1pt 1pt medium; padding: 0cm 5.4pt; width: 287.15pt;" valign="top" width="383">
<div style="line-height: 150%;"><span style="font-family: 宋体;">行锁定必须等待的时间</span>(ms)<span style="font-family: 宋体;">。该值大，说明锁冲突大</span></div>
</td>
</tr>
</tbody>
</table>
</div>
<div style="line-height: 115%;">&nbsp;</div>
]]></content:encoded>
			<wfw:commentRss>http://www.shenmiguo.com/archives/2009/325_mysql-status-optimization.html/feed</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Mysql主从复制配置</title>
		<link>http://www.shenmiguo.com/archives/2009/324_mysql-rep.html</link>
		<comments>http://www.shenmiguo.com/archives/2009/324_mysql-rep.html#comments</comments>
		<pubDate>Wed, 11 Nov 2009 09:42:47 +0000</pubDate>
		<dc:creator>神秘果</dc:creator>
				<category><![CDATA[数据库]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.shenmiguo.com/?p=324</guid>
		<description><![CDATA[Mysql主从复制是一台服务器充当主服务器，另一台或多台服务器充当从服务器，主机自动复制到从机。对于多级复制，数据服务器即可充当主机，也可充当从机。Mysql复制的基础是主服务器对数据库修改记录二进制日志binlog，从服务器通过主服务器的binlog自动执行更新。

下面以InnoDB引擎为例，说明配置主从复制的方法。
&#160;
1配置/etc/my.cnf
修改主服务器my.cnf，在[mysqld]中增加如下内容：
##打开binlog
log-bin=mysql-bin
##服务器ID。服务器之间不能有重复ID，一般主是1
server-id&#160;&#160;&#160;&#160;&#160;&#160; = 1
##指定不写binlog的数据库，不同步系统库
binlog-ignore-db = mysql
binlog-ignore-db = information_schema
binlog-ignore-db = cluster
##指定写二进制的数据库，多个要多行
replicate-do-db = DB_Test
##指定跨库更新也同步的数据库。和replicate-do-db相同多行
replicate-wild-do-table=DB\_Test.%
&#160;
修改从服务器my.cnf，设置server-id=2。
另外，主从服务器的ip和端口信息配置不在my.cnf里配置，整合到后面的change master命令里。
修改了my.cnf，重启主从服务器：
mysqladmin -uroot shutdown
&#160;
2主服务器上添加数据库复制用户
在主服务器上，必须为从服务器创建主从复制的用户，并设置replication slave权限。所用具体命令如下：
grant replication slave on *.* to rep@&#39;172.25.38.145&#39; identified by &#39;&#39;;
flush privileges;
172.25.38.145是从服务器，就通过rep用户密码为空来同步复制。通过查询user表查看Repl_slave_priv的值为Y：
select * from mysql.user where user=&#39;rep&#39;\G;
&#160;
3导出主服务器数据
主服务器上要保证数据一致性，获取数据快照。在获取快照后，主服务器不能有写操作。
先刷新所有语句并阻止写入，这样的目的是保证主机数据快照的一致性：
FLUSH TABLES WITH READ LOCK;
执行完这句后，所有对主服务器数据库的更新都被挂起，直到执行UNLOCK TABLES;或者关闭当前的终端。
获取主服务器的快照：
show master status\G;
记录File 及Position 项的值，以便之后对从服务器进行配置。File是当前处理的binlog，Position是处理的binlog位置，这是从服务器的同步起点。
接下来是导出主服务器的数据。导出数据有两种方式：mysqldump导出需要同步的数据库和拷贝数据库数据目录。
&#160;
1) mysqldump方式备份数据
Mysqldump适合数据库还不是特别大的情况。
导出主服务器需要同步的数据库数据，在另一个终端上执行命令：
mysqldump -uroot DB_Test1 DB_Test2 &#8211;opt &#8211;single-transaction &#8211;flush-logs &#8211;routines &#8211;force &#8211;database &#62; master.sql
导出数据后就可以解锁了：
UNLOCK TABLES;
&#160;
2) 拷贝文件方式备份数据
拷贝文件是主服务器上的数据文件目录打包到从服务器上。
拷贝文件的方式需要关闭数据，比较适合数据库庞大mysqldump比较慢的场合。注意：binlog可能非常庞大，影响文件备份速度。可以定期移走不用的binlog，通过show slave status查看当前的binlog，移走这以前的binlog。
对于MyISAM引擎，可以在不关闭数据库的情况下直接tar，但对于InnoDB事务型数据库，就麻烦一些了。商业软件InnoDB [...]]]></description>
			<content:encoded><![CDATA[<p>Mysql<span style="font-family: 宋体;">主从复制是一台服务器充当主服务器，另一台或多台服务器充当从服务器，主机自动复制到从机。对于多级复制，数据服务器即可充当主机，也可充当从机。</span>Mysql<span style="font-family: 宋体;">复制的基础是主服务器对数据库修改记录二进制日志</span>binlog<span style="font-family: 宋体;">，从服务器通过主服务器的</span>binlog<span style="font-family: 宋体;">自动执行更新。</span></p>
<p><span id="more-324"></span></p>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">下面以</span><span style="color: rgb(0, 0, 204);">InnoDB</span><span style="font-family: 宋体;">引擎为例，说明配置主从复制的方法。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><b><span style="font-size: 14pt; line-height: 125%;">1</span></b><b><span style="font-size: 14pt; line-height: 125%; font-family: 宋体;">配置</span></b><b><span style="font-size: 14pt; line-height: 125%;">/etc/my.cnf</span></b></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体; color: red;">修改主服务器</span>my.cnf<span style="font-family: 宋体;">，在</span>[mysqld]<span style="font-family: 宋体;">中增加如下内容：</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: gray;">##</span><span style="font-family: 宋体; color: gray;">打开</span><span style="color: gray;">binlog</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: rgb(0, 0, 204);">log-bin=mysql-bin</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: gray;">##</span><span style="font-family: 宋体; color: gray;">服务器</span><span style="color: gray;">ID</span><span style="font-family: 宋体; color: gray;">。服务器之间不能有重复</span><span style="color: gray;">ID</span><span style="font-family: 宋体; color: gray;">，一般主是</span><span style="color: gray;">1</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: rgb(0, 0, 204);">server-id&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = 1</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: gray;">##</span><span style="font-family: 宋体; color: gray;">指定不写</span><span style="color: gray;">binlog</span><span style="font-family: 宋体; color: gray;">的数据库，不同步系统库</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: rgb(0, 0, 204);">binlog-ignore-db = mysql</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: rgb(0, 0, 204);">binlog-ignore-db = information_schema</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: rgb(0, 0, 204);">binlog-ignore-db = cluster</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: gray;">##</span><span style="font-family: 宋体; color: gray;">指定写二进制的数据库，多个要多行</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: rgb(0, 0, 204);">replicate-do-db = DB_Test</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: gray;">##</span><span style="font-family: 宋体; color: gray;">指定跨库更新也同步的数据库。和</span><span style="color: gray;">replicate-do-db</span><span style="font-family: 宋体; color: gray;">相同多行</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: rgb(0, 0, 204);">replicate-wild-do-table=DB\_Test.%</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体; color: red;">修改从服务器</span>my.cnf<span style="font-family: 宋体;">，设置</span>server-id=2<span style="font-family: 宋体;">。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">另外，主从服务器的</span>ip<span style="font-family: 宋体;">和端口信息配置不在</span>my.cnf<span style="font-family: 宋体;">里配置，整合到后面的</span>change master<span style="font-family: 宋体;">命令里。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">修改了</span>my.cnf<span style="font-family: 宋体;">，重启主从服务器：</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: rgb(0, 0, 204);">mysqladmin -uroot shutdown</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><b><span style="font-size: 14pt; line-height: 125%;">2</span></b><b><span style="font-size: 14pt; line-height: 125%; font-family: 宋体;">主服务器上添加数据库复制用户</span></b></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">在主服务器上，必须为从服务器<span style="color: red;">创建主从复制的用户</span>，并设置</span>replication slave<span style="font-family: 宋体;">权限。所用具体命令如下：</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: rgb(0, 0, 204);">grant replication slave on *.* to rep@&#39;172.25.38.145&#39; identified by &#39;&#39;;</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: rgb(0, 0, 204);">flush privileges;</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">172.25.38.145<span style="font-family: 宋体;">是从服务器，就通过</span>rep<span style="font-family: 宋体;">用户密码为空来同步复制。通过查询</span>user<span style="font-family: 宋体;">表查看</span>Repl_slave_priv<span style="font-family: 宋体;">的值为</span>Y<span style="font-family: 宋体;">：</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: rgb(0, 0, 204);">select * from mysql.user where user=&#39;rep&#39;\G;</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><b><span style="font-size: 14pt; line-height: 125%;">3</span></b><b><span style="font-size: 14pt; line-height: 125%; font-family: 宋体;">导出主服务器数据</span></b></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">主服务器上要保证数据一致性，获取数据快照。在获取快照后，主服务器不能有写操作。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">先<span style="color: red;">刷新所有语句并阻止写入</span>，这样的目的是保证主机数据快照的一致性：</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: rgb(0, 0, 204);">FLUSH TABLES WITH READ LOCK;</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">执行完这句后，所有对主服务器数据库的更新都被挂起，直到执行</span>UNLOCK TABLES;<span style="font-family: 宋体;">或者关闭当前的终端。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体; color: red;">获取主服务器的快照</span><span style="font-family: 宋体;">：</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: rgb(0, 0, 204);">show master status\G;</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">记录</span>File <span style="font-family: 宋体;">及</span>Position <span style="font-family: 宋体;">项的值，以便之后对从服务器进行配置。</span>File<span style="font-family: 宋体;">是当前处理的</span>binlog<span style="font-family: 宋体;">，</span>Position<span style="font-family: 宋体;">是处理的</span>binlog<span style="font-family: 宋体;">位置，这是从服务器的同步起点。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">接下来是导出主服务器的数据。导出数据有两种方式：</span>mysqldump<span style="font-family: 宋体;">导出需要同步的数据库和拷贝数据库数据目录。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><b>1) mysqldump</b><b><span style="font-family: 宋体;">方式备份数据</span></b></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">Mysqldump<span style="font-family: 宋体;">适合数据库还不是特别大的情况。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">导出主服务器需要同步的数据库数据，在另一个终端上执行命令：</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: rgb(0, 0, 204);">mysqldump -uroot DB_Test1 DB_Test2 &#8211;opt &#8211;single-transaction &#8211;flush-logs &#8211;routines &#8211;force &#8211;database &gt; master.sql</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">导出数据后就可以解锁了：</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: rgb(0, 0, 204);">UNLOCK TABLES;</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><b>2) </b><b><span style="font-family: 宋体;">拷贝文件方式备份数据</span></b></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">拷贝文件是主服务器上的数据文件目录打包到从服务器上。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">拷贝文件的方式需要关闭数据，比较适合数据库庞大</span>mysqldump<span style="font-family: 宋体;">比较慢的场合。<span style="color: red;">注意</span>：</span>binlog<span style="font-family: 宋体;">可能非常庞大，影响文件备份速度。可以定期移走不用的</span>binlog<span style="font-family: 宋体;">，通过</span>show slave status<span style="font-family: 宋体;">查看当前的</span>binlog<span style="font-family: 宋体;">，移走这以前的</span>binlog<span style="font-family: 宋体;">。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">对于</span>MyISAM<span style="font-family: 宋体;">引擎，可以在不关闭数据库的情况下直接</span>tar<span style="font-family: 宋体;">，但对于</span>InnoDB<span style="font-family: 宋体;">事务型数据库，就麻烦一些了。商业软件</span>InnoDB Hot Backup<span style="font-family: 宋体;">提供了在线备份工具，除了这个收费的工具，最简单的办法就是关闭主服务器后执行</span>tar<span style="font-family: 宋体;">。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">新开一个终端（不能在</span>FLUSH TABLES WITH READ LOCK;<span style="font-family: 宋体;">的终端操作），<span style="color: red;">关闭主服务器</span>：</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: rgb(0, 0, 204);">mysqladmin -uroot shutdown</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">打包数据库数据目录，例如数据目录是</span>/data/dbdata<span style="font-family: 宋体;">：</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: rgb(0, 0, 204);">cd /data</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: rgb(0, 0, 204);">tar zcvf dbdata.tar.gz dbdata</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">备份后就可以启动主服务器了：</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: rgb(0, 0, 204);">mysqld_safe &#8211;user=mysql &amp;</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">以上两种备份选择任意一种即可，把文件</span>scp<span style="font-family: 宋体;">到从服务器上。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><b><span style="font-size: 14pt; line-height: 125%;">4</span></b><b><span style="font-size: 14pt; line-height: 125%; font-family: 宋体;">数据导入到从服务器</span></b></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体; color: red;">在从服务器上导入数据</span><span style="font-family: 宋体;">。两种不同的备份方式分别对应其数据导入的方式。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><b>1) Mysqldump</b><b><span style="font-family: 宋体;">方式的导入</span></b></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: rgb(0, 0, 204);">mysql -uroot &lt;./master.sql</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><b>2) </b><b><span style="font-family: 宋体;">备份文件方式的导入</span></b></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">由于需要置换成主服务器的数据目录，先关闭服务：</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: rgb(0, 0, 204);">mysqladmin -uroot shutdown</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">备份数据目录</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: rgb(0, 0, 204);">mv dbdata dbdata.bak</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">解包从主服务器拷贝来的数据目录</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: rgb(0, 0, 204);">tar zxvf dbdata.tar.gz</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">要确保文件的权限属主等设置没问题，</span>dbdata<span style="font-family: 宋体;">目录应该是</span>mysql:mysql<span style="font-family: 宋体;">用户所有。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">以上二选一，完成数据导入。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">删除</span>dbdata<span style="font-family: 宋体;">下的主机信息文件和中继日志文件：</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: rgb(0, 0, 204);">rm dbdata/master.info</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: rgb(0, 0, 204);">rm dbdata/relay-log.info</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">如果是拷贝文件方式同步，还需要启动从服务器：</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: rgb(0, 0, 204);">mysqld_safe &#8211;user=mysql &amp;</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><b><span style="font-size: 14pt; line-height: 125%;">5</span></b><b><span style="font-size: 14pt; line-height: 125%; font-family: 宋体;">在从服务器上开始同步</span></b></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体; color: red;">在从服务器上操作</span><span style="font-family: 宋体;">，连接主服务器开始同步数据：</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: rgb(0, 0, 204);">Change master to</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: rgb(0, 0, 204);">Master_host = &#39;10.6.209.126&#39;,</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: rgb(0, 0, 204);">Master_port = 3306,</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: rgb(0, 0, 204);">Master_user = &#39;rep&#39;,</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: rgb(0, 0, 204);">Master_password = &#39;&#39;,</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: rgb(0, 0, 204);">Master_log_file = &#39;mysql-bin.000034&#39;,</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: rgb(0, 0, 204);">Master_log_pos = 102;</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">这里包含的信息有主机的地址和端口、主机提供的复制帐号、主机的</span>binlog<span style="font-family: 宋体;">位置信息。</span>Master_log_file<span style="font-family: 宋体;">和</span>Master_log_pos<span style="font-family: 宋体;">是主服务器的快照信息，从服务器从该</span>binlog<span style="font-family: 宋体;">的相应位置开始从主服务器同步数据。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">启动从服务器线程就可以开始同步了：</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: rgb(0, 0, 204);">start slave;</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">一旦从服务器开始同步了，就能在数据文件目录下找到</span>2<span style="font-family: 宋体;">个文件</span>master.info<span style="font-family: 宋体;">和</span>relay-log.info<span style="font-family: 宋体;">。从服务器利用这</span>2<span style="font-family: 宋体;">个文件来跟踪处理了多少</span>master<span style="font-family: 宋体;">的</span>binlog<span style="font-family: 宋体;">。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">分别在主从服务器</span>show processlist<span style="font-family: 宋体;">查看连接，就可以看到</span>rep<span style="font-family: 宋体;">用户的连接，可证明复制已经生效。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><b><span style="font-size: 14pt; line-height: 125%; font-family: 宋体;">灾难恢复</span></b></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><b><span style="font-family: 宋体;">主从不同步</span></b></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">如果主从同步出现了不一致，就需要重新实施主从复制。步骤和上面相同，只是省略了修改配置文件和创建用户的步骤。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">重新配置之前，需要在从服务器停止同步线程：</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: rgb(0, 0, 204);">stop slave;</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><b><span style="font-family: 宋体;">从从服务器恢复</span></b></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">如果主机挂了，可以把从服务器提升为主机，把原主服务器作为备机。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">先在从服务器停止同步线程：</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: rgb(0, 0, 204);">stop slave;</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">在从服务器上添加同步用户：</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: rgb(0, 0, 204);">grant replication slave on *.* to rep@&#39;</span><span style="font-family: 宋体; color: rgb(0, 0, 204);">新的从服务器</span><span style="color: rgb(0, 0, 204);">ip&#39; identified by &#39;&#39;;</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: rgb(0, 0, 204);">flush privileges;</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">配置文件中</span>my.cnf<span style="font-family: 宋体;">的</span>server-id<span style="font-family: 宋体;">可以不修改，只要保证</span>id<span style="font-family: 宋体;">不冲突就行了。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">然后，按照主从复制的步骤来进行操作。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
]]></content:encoded>
			<wfw:commentRss>http://www.shenmiguo.com/archives/2009/324_mysql-rep.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>使用TCMalloc优化Mysql性能</title>
		<link>http://www.shenmiguo.com/archives/2009/323_mysql-tcmalloc.html</link>
		<comments>http://www.shenmiguo.com/archives/2009/323_mysql-tcmalloc.html#comments</comments>
		<pubDate>Wed, 04 Nov 2009 07:06:11 +0000</pubDate>
		<dc:creator>神秘果</dc:creator>
				<category><![CDATA[数据库]]></category>
		<category><![CDATA[mysql]]></category>
		<category><![CDATA[tcmalloc]]></category>

		<guid isPermaLink="false">http://www.shenmiguo.com/?p=323</guid>
		<description><![CDATA[TCMalloc（Thread-Caching Malloc）是google-perftools工具中的一个，与标准的glibc库的malloc相比，TCMalloc在内存的分配上效率和速度要高得多，可以提高Mysql服务器在高并发情况下的性能，降低系统负载。

Google-perftools的项目：http://code.google.com/p/google-perftools/
TCMalloc的原理介绍翻译：http://shiningray.cn/tcmalloc-thread-caching-malloc.html
google-perftools包括TCMalloc、heap-checker、heap-profiler和cpu-profiler共4个组件，在只用TCMalloc的场景下，可以不编译其他三个组件，使用tcmalloc_minimal就足够。
下面介绍在Linux SUSE x86上安装TCMalloc动态库的过程。
&#160;
安装TCMalloc
从 http://code.google.com/p/google-perftools/ 下载源码包，现在最新版本是1.4。如果机器联网，直接：
wget &#160;http://google-perftools.googlecode.com/files/google-perftools-1.4.tar.gz
tar zxvf google-perftools-1.4.tar.gz
cd &#160;google-perftools-1.4
Mysql服务器只需要用SO动态库就可以了，没有必须要把其他的文件(头文件静态库文档等)也安装到/usr/local/里。先安装到一个临时文件夹：
mkdir /tmp/tc
./configure &#8211;prefix=/tmp/tc &#8211;disable-cpu-profiler &#8211;disable-heap-profiler &#8211;disable-heap-checker &#8211;disable-debugalloc &#8211;enable-minimal
加上后面的几个参数是指只生成tcmalloc_minimal。
如果要生成包含所有组件的tcmalloc，可：
./configure &#8211;prefix=/tmp/tc
如果要将文件直接安装到文件，就不需要临时目录了，可：
./configure
使用./configure &#8211;h可查看安装选项。
编译安装：
make &#38;&#38; make install
ls -alt /tmp/tc/lib/*
使用了最小安装，拷贝tcmalloc_minimal的动态库到系统库目录：
cp /tmp/tc/lib/libtcmalloc_minimal.so* /usr/local/lib
建立软连接指向tcmalloc：
ln -s /usr/local/lib/libtcmalloc_minimal.so.0.0.0 /usr/local/lib/libtcmalloc.so
ln -s /usr/local/lib/libtcmalloc_minimal.so.0.0.0 /usr/local/lib/libtcmalloc.so.0
ln -s /usr/local/lib/libtcmalloc_minimal.so.0.0.0 /usr/local/lib/libtcmalloc.so.0.0.0 
rm -rf /tmp/tc
&#160;
Mysql加入动态库
修改mysql服务的启动脚本mysqld_safe，在&#8220; # executing mysqld_safe&#8221;行后添加行：
export LD_PRELOAD=&#34;/usr/local/lib/libtcmalloc.so&#34;
目的是在启动mysql前，加载tcmalloc动态库。
重启Mysql服务：
/usr/local/mysql/bin/mysqladmin shutdown
/usr/local/mysql/bin/mysqld_safe &#8211;user=mysql &#38;
&#160;
验证
使用lsof查看mysql进程是否已经加载了tcmalloc库：
shell &#62; lsof -n &#124; grep tcmalloc 
mysqld&#160;&#160;&#160; 32398&#160;&#160;&#160;&#160;&#160; mysql&#160;mem&#160;&#160;&#160;&#160;&#160;&#160; REG&#160;&#160;&#160;&#160;&#160;&#160;&#160; [...]]]></description>
			<content:encoded><![CDATA[<p>TCMalloc<span style="font-family: 宋体;">（</span>Thread-Caching Malloc<span style="font-family: 宋体;">）是</span>google-perftools<span style="font-family: 宋体;">工具中的一个，与标准的</span>glibc<span style="font-family: 宋体;">库的</span>malloc<span style="font-family: 宋体;">相比，</span>TCMalloc<span style="font-family: 宋体;">在内存的分配上效率和速度要高得多，可以提高</span>Mysql<span style="font-family: 宋体;">服务器在高并发情况下的性能，降低系统负载。</span></p>
<p><span id="more-323"></span></p>
<p>Google-perftools<span style="font-family: 宋体;">的项目：</span><a href="http://code.google.com/p/google-perftools/">http://code.google.com/p/google-perftools/</a></p>
<div style="margin-bottom: 3.9pt; line-height: 125%;">TCMalloc<span style="font-family: 宋体;">的原理介绍翻译：</span><a href="http://shiningray.cn/tcmalloc-thread-caching-malloc.html">http://shiningray.cn/tcmalloc-thread-caching-malloc.html</a></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">google-perftools<span style="font-family: 宋体;">包括</span>TCMalloc<span style="font-family: 宋体;">、</span>heap-checker<span style="font-family: 宋体;">、</span>heap-profiler<span style="font-family: 宋体;">和</span>cpu-profiler<span style="font-family: 宋体;">共</span>4<span style="font-family: 宋体;">个组件，在只用</span>TCMalloc<span style="font-family: 宋体;">的场景下，可以不编译其他三个组件，使用</span>tcmalloc_minimal<span style="font-family: 宋体;">就足够。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">下面介绍在</span>Linux SUSE x86<span style="font-family: 宋体;">上安装</span>TCMalloc<span style="font-family: 宋体;">动态库的过程。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><b><span style="font-size: 14pt; line-height: 125%; font-family: 宋体;">安装</span></b><b><span style="font-size: 14pt; line-height: 125%;">TCMalloc</span></b></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">从</span> <a href="http://code.google.com/p/google-perftools/">http://code.google.com/p/google-perftools/</a> <span style="font-family: 宋体;">下载源码包，现在最新版本是</span>1.4<span style="font-family: 宋体;">。如果机器联网，直接：</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">wget &nbsp;http://google-perftools.googlecode.com/files/google-perftools-1.4.tar.gz</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">tar zxvf google-perftools-1.4.tar.gz</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">cd &nbsp;google-perftools-1.4</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">Mysql<span style="font-family: 宋体;">服务器只需要用</span>SO<span style="font-family: 宋体;">动态库就可以了，没有必须要把其他的文件</span>(<span style="font-family: 宋体;">头文件静态库文档等</span>)<span style="font-family: 宋体;">也安装到</span>/usr/local/<span style="font-family: 宋体;">里。先安装到一个临时文件夹：</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">mkdir /tmp/tc</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">./configure &#8211;prefix=/tmp/tc &#8211;disable-cpu-profiler &#8211;disable-heap-profiler &#8211;disable-heap-checker &#8211;disable-debugalloc &#8211;enable-minimal</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">加上后面的几个参数是指只生成</span>tcmalloc_minimal<span style="font-family: 宋体;">。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">如果要生成包含所有组件的</span>tcmalloc<span style="font-family: 宋体;">，可：</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">./configure &#8211;prefix=/tmp/tc</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">如果要将文件直接安装到文件，就不需要临时目录了，可：</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">./configure</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">使用</span>./configure &ndash;h<span style="font-family: 宋体;">可查看安装选项。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">编译安装：</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">make &amp;&amp; make install</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">ls -alt /tmp/tc/lib/*</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">使用了最小安装，拷贝</span>tcmalloc_minimal<span style="font-family: 宋体;">的动态库到系统库目录：</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">cp /tmp/tc/lib/libtcmalloc_minimal.so* /usr/local/lib</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">建立软连接指向</span>tcmalloc<span style="font-family: 宋体;">：</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">ln -s /usr/local/lib/libtcmalloc_minimal.so.0.0.0 /usr/local/lib/libtcmalloc.so</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">ln -s /usr/local/lib/libtcmalloc_minimal.so.0.0.0 /usr/local/lib/libtcmalloc.so.0</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">ln -s /usr/local/lib/libtcmalloc_minimal.so.0.0.0 /usr/local/lib/libtcmalloc.so.0.0.0 </span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">rm -rf /tmp/tc</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><b><span style="font-size: 14pt; line-height: 125%;">Mysql</span></b><b><span style="font-size: 14pt; line-height: 125%; font-family: 宋体;">加入动态库</span></b></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">修改</span>mysql<span style="font-family: 宋体;">服务的启动脚本</span>mysqld_safe<span style="font-family: 宋体;">，在&ldquo;</span> # executing mysqld_safe<span style="font-family: 宋体;">&rdquo;行后添加行：</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">export LD_PRELOAD=&quot;/usr/local/lib/libtcmalloc.so&quot;</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">目的是在启动</span>mysql<span style="font-family: 宋体;">前，加载</span>tcmalloc<span style="font-family: 宋体;">动态库。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">重启</span>Mysql<span style="font-family: 宋体;">服务：</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">/usr/local/mysql/bin/mysqladmin shutdown</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">/usr/local/mysql/bin/mysqld_safe &#8211;user=mysql &amp;</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><b><span style="font-size: 14pt; line-height: 125%; font-family: 宋体;">验证</span></b></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">使用</span>lsof<span style="font-family: 宋体;">查看</span>mysql<span style="font-family: 宋体;">进程是否已经加载了</span>tcmalloc<span style="font-family: 宋体;">库：</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">shell &gt; lsof -n | grep tcmalloc </span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">mysqld&nbsp;&nbsp;&nbsp; 32398&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mysql&nbsp;mem&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; REG&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 8,3&nbsp;&nbsp;&nbsp;&nbsp; 668454&nbsp;&nbsp;&nbsp; 1477703 /usr/local/lib/libtcmalloc_minimal.so.0.0.0</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">恭喜，成功安装了</span>tcmalloc<span style="font-family: 宋体;">。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
]]></content:encoded>
			<wfw:commentRss>http://www.shenmiguo.com/archives/2009/323_mysql-tcmalloc.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mysql配置文件my.cnf详解</title>
		<link>http://www.shenmiguo.com/archives/2009/322_mysql-config.html</link>
		<comments>http://www.shenmiguo.com/archives/2009/322_mysql-config.html#comments</comments>
		<pubDate>Mon, 02 Nov 2009 11:03:50 +0000</pubDate>
		<dc:creator>神秘果</dc:creator>
				<category><![CDATA[数据库]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.shenmiguo.com/?p=322</guid>
		<description><![CDATA[以下是Mysql数据库服务器配置文件/etc/my.cnf的详细配置。应用场合是InnoDB引擎，4核CPU， 32位SUSE。

[client]
port&#160;&#160;&#160;&#160;&#160;&#160;&#160; = 3306
socket&#160;&#160;&#160;&#160;&#160; = /tmp/mysql.sock
# The MySQL server
[mysqld]
bind-address = 192.168.0.11
port&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; = 3306
socket&#160;&#160;&#160;&#160;&#160;&#160; = /tmp/mysql.sock
&#160;
##设置表的默认类型。和default-storage-engine同义
default-table-type = innodb
&#160;
#以下是网络传输配置
#连接进程帧听队列的大小
back_log = 50
&#160;
#之前有过经验，connections超过370的时候，线程的栈空间被占满，mysqld无法工作，所以限制为200
max_connections=200
&#160;
#连接500次发生错误之后，屏蔽从该host的所有连接
max_connect_errors = 500
&#160;
#通信缓冲区的最大长度。包或任何生成的/中间字符串的最大大小。
max_allowed_packet = 32M
&#160;
在查询之间将通信缓冲区重设为该值。如果语句超出该长度，缓冲区自动扩大，直到max_allowed_packet字节。
net_buffer_length = 8K
&#160;
#以下是查询优化
#避免外部锁定(默认是ON). 对应variable的skip_external_locking
skip-locking
&#160;
#索引缓冲区(仅作用于MYISAM表和临时表)，决定了数据库索引处理的速度
key_buffer_size = 10M
&#160;
#所有线程打开的表的数目(一个表使用2个文件描述符)，表数量多，就要大一些。增大该值可以增加mysqld需要的文件描述符的数量。可以检查Opened_tables(已经打开的表的数量)状态变量来检查你是否需要增加表缓存。
table_cache = 2048
&#160;
#每个排序线程分配的缓冲区的大小。增加该值可以加快ORDER BY或GROUP BY操作
sort_buffer_size = 5M
&#160;
#用于完全联接的缓冲区的大小(当不使用索引的时候使用联接操作)。
#一般情况获得快速联接的最好方法是添加索引。当增加索引时不可能通过增加join_buffer_size值来获得快速完全联接。
#将为两个表之间的每个完全联接分配联接缓冲区。对于多个表之间不使用索引的复杂联接，需要多联接缓冲区。
join_buffer_size = 8M
&#160;
#服务器应缓存多少线程以便重新使用。当客户端断开连接时，如果线程少于thread_cache_size，则客户端的线程被放入缓存。
#如果状态变量Threads_created(创建用来处理连接的线程数)较大，你可能要增加thread_cache_size值。缓存访问率的计算方法Threads_created/Connections(试图连接到(不管是否成功)MySQL服务器的连接数)
thread_cache_size = 8
&#160;
#使应用程序向线程系统提供需要同时运行的期望的线程数目的提示
thread_concurrency = 8
&#160;
#为缓存查询结果分配的内存的数量，加快查询的速度。默认值是0，即禁用查询缓存。
query_cache_size = 64M
&#160;
#不要缓存大于该值的结果，默认值是1048576(1MB)。
query_cache_limit = 2M
&#160;
#ft_min_word_len和ft_max_word_len表示FULLTEXT索引的最小和最大字长
ft_min_word_len = 4
&#160;
#每个线程的堆栈大小
thread_stack = 192K
&#160;
#事务隔离级别。READ-UNCOMMITTED: 未提交读 会出现脏读、不可重复读、幻读 ( 隔离级别最低，并发性能高 ) ；READ-COMMITTED: 提交读 [...]]]></description>
			<content:encoded><![CDATA[<p><span class="Apple-style-span" style="line-height: 15px;"><span style="font-family: 宋体;">以下是</span>Mysql<span style="font-family: 宋体;">数据库服务器配置文件</span>/etc/my.cnf<span style="font-family: 宋体;">的详细配置。应用场合是</span>InnoDB<span style="font-family: 宋体;">引擎，</span>4<span style="font-family: 宋体;">核</span>CPU<span style="font-family: 宋体;">，</span> 32<span style="font-family: 宋体;">位</span>SUSE<span style="font-family: 宋体;">。</span></span></p>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span id="more-322"></span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">[client]</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">port<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = 3306</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">socket<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = /tmp/mysql.sock</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"># The MySQL server</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">[mysqld]</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">bind-address = 192.168.0.11</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">port<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = 3306</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">socket<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; = /tmp/mysql.sock</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">##<span style="font-family: 宋体;">设置表的默认类型。和</span>default-storage-engine<span style="font-family: 宋体;">同义</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><b><span style="color: red;">default-table-type = innodb</span></b></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><b><span style="font-size: 14pt; line-height: 125%;">#</span></b><b><span style="font-size: 14pt; line-height: 125%; font-family: 宋体;">以下是网络传输配置</span></b></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">#<span style="font-family: 宋体;">连接进程帧听队列的大小</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">back_log = 50</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">#<span style="font-family: 宋体;">之前有过经验，</span>connections<span style="font-family: 宋体;">超过</span>370<span style="font-family: 宋体;">的时候，线程的栈空间被占满，</span>mysqld<span style="font-family: 宋体;">无法工作，所以限制为</span>200</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><b><span style="color: red;">max_connections=200</span></b></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">#<span style="font-family: 宋体;">连接</span>500<span style="font-family: 宋体;">次发生错误之后，屏蔽从该</span>host<span style="font-family: 宋体;">的所有连接</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">max_connect_errors = 500</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">#<span style="font-family: 宋体;">通信缓冲区的最大长度。包或任何生成的</span>/<span style="font-family: 宋体;">中间字符串的最大大小。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">max_allowed_packet = 32M</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="font-family: 宋体;">在查询之间将通信缓冲区重设为该值。如果语句超出该长度，缓冲区自动扩大，直到</span>max_allowed_packet<span style="font-family: 宋体;">字节。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">net_buffer_length = 8K</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><b><span style="font-size: 14pt; line-height: 125%;">#</span></b><b><span style="font-size: 14pt; line-height: 125%; font-family: 宋体;">以下是查询优化</span></b></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">#<span style="font-family: 宋体;">避免外部锁定</span>(<span style="font-family: 宋体;">默认是</span>ON). <span style="font-family: 宋体;">对应</span>variable<span style="font-family: 宋体;">的</span>skip_external_locking</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">skip-locking</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">#<span style="font-family: 宋体;">索引缓冲区</span>(<span style="font-family: 宋体;">仅作用于</span>MYISAM<span style="font-family: 宋体;">表和临时表</span>)<span style="font-family: 宋体;">，决定了数据库索引处理的速度</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><b><span style="color: red;">key_buffer_size = 10M</span></b></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">#<span style="font-family: 宋体;">所有线程打开的表的数目</span>(<span style="font-family: 宋体;">一个表使用</span>2<span style="font-family: 宋体;">个文件描述符</span>)<span style="font-family: 宋体;">，表数量多，就要大一些。增大该值可以增加</span>mysqld<span style="font-family: 宋体;">需要的文件描述符的数量。可以检查</span>Opened_tables(<span style="font-family: 宋体;">已经打开的表的数量</span>)<span style="font-family: 宋体;">状态变量来检查你是否需要增加表缓存。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><b><span style="color: red;">table_cache = 2048</span></b></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">#<span style="font-family: 宋体;">每个排序线程分配的缓冲区的大小。增加该值可以加快</span>ORDER BY<span style="font-family: 宋体;">或</span>GROUP BY<span style="font-family: 宋体;">操作</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><b><span style="color: red;">sort_buffer_size = 5M</span></b></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">#<span style="font-family: 宋体;">用于完全联接的缓冲区的大小</span>(<span style="font-family: 宋体;">当不使用索引的时候使用联接操作</span>)<span style="font-family: 宋体;">。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">#<span style="font-family: 宋体;">一般情况获得快速联接的最好方法是添加索引。当增加索引时不可能通过增加</span>join_buffer_size<span style="font-family: 宋体;">值来获得快速完全联接。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">#<span style="font-family: 宋体;">将为两个表之间的每个完全联接分配联接缓冲区。对于多个表之间不使用索引的复杂联接，需要多联接缓冲区。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><b><span style="color: red;">join_buffer_size = 8M</span></b></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">#<span style="font-family: 宋体;">服务器应缓存多少线程以便重新使用。当客户端断开连接时，如果线程少于</span>thread_cache_size<span style="font-family: 宋体;">，则客户端的线程被放入缓存。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">#<span style="font-family: 宋体;">如果状态变量</span>Threads_created(<span style="font-family: 宋体;">创建用来处理连接的线程数</span>)<span style="font-family: 宋体;">较大，你可能要增加</span>thread_cache_size<span style="font-family: 宋体;">值。缓存访问率的计算方法</span>Threads_created/Connections(<span style="font-family: 宋体;">试图连接到</span>(<span style="font-family: 宋体;">不管是否成功</span>)MySQL<span style="font-family: 宋体;">服务器的连接数</span>)</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">thread_cache_size = 8</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">#<span style="font-family: 宋体;">使应用程序向线程系统提供需要同时运行的期望的线程数目的提示</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">thread_concurrency = 8</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">#<span style="font-family: 宋体;">为缓存查询结果分配的内存的数量，加快查询的速度。默认值是</span>0<span style="font-family: 宋体;">，即禁用查询缓存。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">query_cache_size = 64M</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">#<span style="font-family: 宋体;">不要缓存大于该值的结果，默认值是</span>1048576(1MB)<span style="font-family: 宋体;">。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">query_cache_limit = 2M</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">#ft_min_word_len<span style="font-family: 宋体;">和</span>ft_max_word_len<span style="font-family: 宋体;">表示</span>FULLTEXT<span style="font-family: 宋体;">索引的最小和最大字长</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">ft_min_word_len = 4</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">#<span style="font-family: 宋体;">每个线程的堆栈大小</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">thread_stack = 192K</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">#<span style="font-family: 宋体;">事务隔离级别。</span>READ-UNCOMMITTED: <span style="font-family: 宋体;">未提交读</span> <span style="font-family: 宋体;">会出现脏读、不可重复读、幻读</span> ( <span style="font-family: 宋体;">隔离级别最低，并发性能高</span> ) <span style="font-family: 宋体;">；</span>READ-COMMITTED: <span style="font-family: 宋体;">提交读</span> <span style="font-family: 宋体;">会出现不可重复读、幻读问题（锁定正在读取的行）；</span>REPEATABLE-READ: <span style="font-family: 宋体;">默认值，可重复读</span> <span style="font-family: 宋体;">会出幻读（锁定所读取的所有行）</span> <span style="font-family: 宋体;">；</span>SERIALIZABLE: <span style="font-family: 宋体;">序列化</span> <span style="font-family: 宋体;">保证所有的情况不会发生（锁表）</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">transaction_isolation = REPEATABLE-READ</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">#<span style="font-family: 宋体;">联合查询或者</span>view<span style="font-family: 宋体;">的时候，可能会建立临时表，如果在磁盘上建的话，会导致性能低，设置此值可以一定程度上加快速度</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">tmp_table_size = 64M</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">#<span style="font-family: 宋体;">每个线程连续扫描时为扫描的每个表分配的缓冲区的大小</span>,<span style="font-family: 宋体;">如果进行多次连续扫描，可能需要增加该值</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">read_buffer_size = 1M</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">#<span style="font-family: 宋体;">当排序后按排序后的顺序读取行时，则通过该缓冲区读取行，避免搜索硬盘。将该变量设置为较大的值可以大大改进</span>ORDER BY<span style="font-family: 宋体;">的性能。但是，这是为每个客户端分配的缓冲区，因此你不应将全局变量设置为较大的值。相反，只为需要运行大查询的客户端更改会话变量。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">read_rnd_buffer_size = 2M</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><b><span style="font-size: 14pt; line-height: 125%;">#</span></b><b><span style="font-size: 14pt; line-height: 125%; font-family: 宋体;">以下是主从同步配置</span></b></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"># Replication Master Server (default)</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">#<span style="font-family: 宋体;">主机是</span>1<span style="font-family: 宋体;">。备机从</span>2<span style="font-family: 宋体;">开始。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><b><span style="color: red;">server-id&nbsp;&nbsp;&nbsp; = 1</span></b></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">#<span style="font-family: 宋体;">启动数据库更新二进制日志记录，日志文件名前缀为</span>mysql-bin</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><b><span style="color: red;">log-bin=mysql-bin</span></b></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">#<span style="font-family: 宋体;">在事务过程中容纳二进制日志</span>SQL<span style="font-family: 宋体;">语句的缓存大小，</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">#<span style="font-family: 宋体;">二进制日志缓存是服务器支持事务存储引擎并且服务器启用了二进制日志</span>(&#8211;log-bin<span style="font-family: 宋体;">选项</span>)<span style="font-family: 宋体;">的前提下为每个客户端分配的内存。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">#<span style="font-family: 宋体;">如果经常使用大的，多语句事务，可以增加该值以获得更有的性能</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><b><span style="color: red;">binlog_cache_size = 5M</span></b></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">#<span style="font-family: 宋体;">是否记录慢查询，默认</span>OFF<span style="font-family: 宋体;">。用</span>long_query_time<span style="font-family: 宋体;">变量的值来确定&ldquo;慢查询&rdquo;。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><b><span style="color: red;">log_slow_queries</span></b></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">#<span style="font-family: 宋体;">超过</span>2S<span style="font-family: 宋体;">的</span>query<span style="font-family: 宋体;">将记</span>slow query<span style="font-family: 宋体;">日志</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">long_query_time = 2</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">#<span style="font-family: 宋体;">没有使用索引的查询也作为慢速查询记录到慢速日志里</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">
<div style="margin-bottom: 3pt; line-height: 125%;">#<span style="font-family: 宋体;">或者用</span><span style="color: red;">log-queries-not-using-indexes</span></div>
</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">log_long_format</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">#<span style="font-family: 宋体;">告诉主服务器，如果当前的数据库</span>(<span style="font-family: 宋体;">即</span>USE<span style="font-family: 宋体;">选定的数据库</span>)<span style="font-family: 宋体;">是</span>db_name<span style="font-family: 宋体;">，不应将更新保存到二进制日志中。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">binlog-ignore-db</span> = information_schema</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">binlog-ignore-db = cluster</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">binlog-ignore-db = mysql</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">#<span style="font-family: 宋体;">告诉从服务器限制默认数据库</span>(<span style="font-family: 宋体;">由</span>USE<span style="font-family: 宋体;">所选择</span>)<span style="font-family: 宋体;">为</span>db_name<span style="font-family: 宋体;">的语句的复制</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">replicate-do-db</span> = test1</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">replicate-do-db = test2</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">#<span style="font-family: 宋体;">跨库更新表要用到如下配置。告诉从服务器线程限制复制更新的表匹配指定的数据库和表名模式的语句。模式可以包含&lsquo;</span>%<span style="font-family: 宋体;">&rsquo;和&lsquo;</span>_<span style="font-family: 宋体;">&rsquo;通配符，与</span>LIKE<span style="font-family: 宋体;">模式匹配操作符具有相同的含义。要指定多个表，应多次使用该选项，每个表使用一次。该选项可以跨数据库进行更新。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><b><span style="color: red;">replicate-wild-do-table</span></b> = test1.%</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">replicate-wild-do-table = test2.%</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">#<span style="font-family: 宋体;">当</span>Slave<span style="font-family: 宋体;">从</span>Master<span style="font-family: 宋体;">数据库读取日志时更新新写入日志中</span> <span style="font-family: 宋体;">。如果只启动</span>log-bin <span style="font-family: 宋体;">而没有启动</span>log-slave-updates<span style="font-family: 宋体;">则</span>Slave<span style="font-family: 宋体;">只记录针对自己数据库操作的更新</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><b><span style="color: red;">log-slave-updates</span></b></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><b><span style="font-size: 14pt; line-height: 125%;">#</span></b><b><span style="font-size: 14pt; line-height: 125%; font-family: 宋体;">以下是</span></b><b><span style="font-size: 14pt; line-height: 125%;">InnoDB</span></b><b><span style="font-size: 14pt; line-height: 125%; font-family: 宋体;">引擎配置</span></b></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">#InnoDB <span style="font-family: 宋体;">不会自己建立目录，必须自己使用操作系统命令建立相应的目录。检查你的</span> MySQL <span style="font-family: 宋体;">服务程序在</span> datadir <span style="font-family: 宋体;">目录里</span> <span style="font-family: 宋体;">有足够的权限建立文件</span>(mysql<span style="font-family: 宋体;">用户组拥有</span>)<span style="font-family: 宋体;">。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">#<span style="font-family: 宋体;">这是</span>InnoDB<span style="font-family: 宋体;">表的目录共用设置。如果没有设置，</span>InnoDB <span style="font-family: 宋体;">将使用</span>MySQL<span style="font-family: 宋体;">的</span> datadir <span style="font-family: 宋体;">目录为缺省目录。如果设定一个空字串</span>,<span style="font-family: 宋体;">可以在</span> innodb_data_file_path <span style="font-family: 宋体;">中设定绝对路径。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">innodb_data_home_dir = /data/dbdata/</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">#<span style="font-family: 宋体;">单独指定数据文件的路径与大小。数据文件的完整路径由</span> innodb_data_home_dir <span style="font-family: 宋体;">与这里所设定值的组合。</span> <span style="font-family: 宋体;">文件大小以</span> MB <span style="font-family: 宋体;">单位指定。因此在文件大小指定后必有&ldquo;</span>M<span style="font-family: 宋体;">&rdquo;。</span> InnoDB <span style="font-family: 宋体;">也支持缩写&ldquo;</span>G<span style="font-family: 宋体;">&rdquo;，</span> 1G = 1024M<span style="font-family: 宋体;">。从</span> 3.23.44 <span style="font-family: 宋体;">开始，在那些支持大文件的操作系统上可以设置数据文件大小大于</span> 4 GB<span style="font-family: 宋体;">。而在另一些操作系统上数据文件必须小于</span> 2 GB<span style="font-family: 宋体;">。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">#<span style="font-family: 宋体;">如果用</span> autoextend <span style="font-family: 宋体;">选项描述最后一个数据文件，当</span> InnoDB <span style="font-family: 宋体;">用尽所有表自由空间后将会自动扩充最后一个数据文件，每次增量为</span>8MB</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">#InnoDB<span style="font-family: 宋体;">是不会注意你的</span>OS<span style="font-family: 宋体;">文件尺寸限制的，</span> <span style="font-family: 宋体;">在一些文件系统中你可能要设定最大容量</span>2G<span style="font-family: 宋体;">限制：</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">#innodb_data_home_dir = innodb_data_file_path = /ibdata/ibdata1:100M:autoextend:max:2000M</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">#<span style="font-family: 宋体;">这里应当预先创建好</span>10<span style="font-family: 宋体;">个</span>2048M<span style="font-family: 宋体;">的文件，目前还没有创建</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">innodb_data_file_path</span> = ibdata1:2000M;ibdata2:2000M;ibdata3:2000M;ibdata4:2000M;ibdata5:2000M;ibdata6:2000M;ibdata7:2000M;ibdata8:2000M;ibdata9:2000M;ibdata10:2000M:<span style="color: red;">autoextend</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">#InnoDB <span style="font-family: 宋体;">日志文件的路径。如果没有明确指定将默认在</span> MySQL <span style="font-family: 宋体;">的</span> datadir <span style="font-family: 宋体;">目录下建立两个</span> 5 MB <span style="font-family: 宋体;">大小的</span>ib_logfile0<span style="font-family: 宋体;">和</span>ib_logfile1<span style="font-family: 宋体;">文件。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">#<span style="font-family: 宋体;">将日志文件与数据文件分别放在不同的物理硬盘中对提高性能通常是很有益的</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">innodb_log_group_home_dir = /data/dbdata/</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">#<span style="font-family: 宋体;">主要用来存储表结构和数据字典，表越多要求内存就越大</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><b><span style="color: red;">innodb_additional_mem_pool_size = 16M</span></b></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"># You can set .._buffer_pool_size up to 50 &#8211; 80 %</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"># of RAM but beware of setting memory usage too high</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">#<span style="font-family: 宋体;">表和索引数据的内存缓冲区，越大性能越高。但不能超过物理内存的</span>50%<span style="font-family: 宋体;">。若</span>64<span style="font-family: 宋体;">位</span>OS<span style="font-family: 宋体;">，该值可以更大</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">#32<span style="font-family: 宋体;">位</span>OS<span style="font-family: 宋体;">受</span>2G<span style="font-family: 宋体;">内存的限制，不能将内存使用设置太高，</span> glibc <span style="font-family: 宋体;">会把进程堆增长到线程堆栈之上，这将会使服务器崩溃。下面的接近或超过于</span> 2G <span style="font-family: 宋体;">将会很危险：</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">#innodb_buffer_pool_size + key_buffer +<span>&nbsp;&nbsp;&nbsp; max_connections * (sort_buffer_size + record_buffer_size + binlog_cache_size) + max_connections * 2 MB</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">#<span style="font-family: 宋体;">每个线程将使用</span> 2MB(MySQL AB <span style="font-family: 宋体;">二进制版本为</span> 256 KB)<span style="font-family: 宋体;">的堆栈，在最坏的环境下还会使用</span> sort_buffer_size + record_buffer_size <span style="font-family: 宋体;">的附加内存。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><b><span style="color: red;">innodb_buffer_pool_size = 1G</span></b></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">#InnoDB <span style="font-family: 宋体;">中的文件</span> I/O <span style="font-family: 宋体;">线程。</span> <span style="font-family: 宋体;">通常设置为</span> 4</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">innodb_file_io_threads = 4</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">#<span style="font-family: 宋体;">并发线程。</span>2*(<span style="font-family: 宋体;">内核数量</span>+<span style="font-family: 宋体;">磁盘数量</span>)</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><b><span style="color: red;">innodb_thread_concurrency = 16</span></b></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">#1<span style="font-family: 宋体;">表示每次事务结束都写日志并刷新磁盘；</span>2<span style="font-family: 宋体;">表示每次事务写日志但不刷新磁盘</span>(<span style="font-family: 宋体;">每秒刷新</span>)<span style="font-family: 宋体;">；</span>0(<span style="font-family: 宋体;">默认值</span>)<span style="font-family: 宋体;">表示每秒写日志并刷新磁盘。</span>0<span style="font-family: 宋体;">表示最多丢失</span>1<span style="font-family: 宋体;">秒的数据，但性能最好。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><b><span style="color: red;">innodb_flush_log_at_trx_commit = 0</span></b></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">#InnoDB <span style="font-family: 宋体;">将日志写入日志磁盘文件前的缓冲大小。理想值为</span> 1M <span style="font-family: 宋体;">至</span> 8M<span style="font-family: 宋体;">。大的日志缓冲允许事务运行时不需要将日志保存入磁盘而只到事务被提交</span>(commit)<span style="font-family: 宋体;">。</span> <span style="font-family: 宋体;">因此，如果有大的事务，设置大的日志缓冲可以减少磁盘</span>I/O<span style="font-family: 宋体;">。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><b><span style="color: red;">innodb_log_buffer_size = 8M</span></b></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"># Set .._log_file_size to 25 % of buffer pool size</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">#<span style="font-family: 宋体;">日志文件大小设置。增大该值可减少刷新日志频率，但会延长</span>mysql<span style="font-family: 宋体;">启动和灾难恢复的时间。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">#<span style="font-family: 宋体;">日志组中的每个日志文件的大小</span>(<span style="font-family: 宋体;">单位</span> MB)<span style="font-family: 宋体;">。如果</span> n <span style="font-family: 宋体;">是日志组</span>(innodb_log_files_in_group)<span style="font-family: 宋体;">中日志文件的数目，那么理想的数值为</span> 1M <span style="font-family: 宋体;">至缓冲池</span>(innodb_log_buffer_size)<span style="font-family: 宋体;">大小的</span> 1/n<span style="font-family: 宋体;">。较大的值，可以减少刷新缓冲池的次数，从而减少磁盘</span> I/O<span style="font-family: 宋体;">。但是大的日志文件意味着在崩溃时需要更长的时间来恢复数据。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><b><span style="color: red;">innodb_log_file_size = 256M</span></b></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">#<span style="font-family: 宋体;">日志组中的日志文件数目。</span>InnoDB <span style="font-family: 宋体;">以环型方式</span>(circular fashion)<span style="font-family: 宋体;">写入文件。数值</span> 3 <span style="font-family: 宋体;">被推荐使用</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">innodb_log_files_in_group = 3</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">#InnoDB<span style="font-family: 宋体;">行锁导致的死锁等待时间</span>(<span style="font-family: 宋体;">默认值是</span>50S)</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><b><span style="color: red;">innodb_lock_wait_timeout = 30</span></b></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">#<span style="font-family: 宋体;">是否支持分布式事务，关闭以提高性能</span>(<span style="font-family: 宋体;">默认是</span>ON)</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"><span style="color: red;">innodb_support_xa = OFF</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">[mysqldump]</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">quick</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">max_allowed_packet = 16M</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">[mysql]</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">no-auto-rehash</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;"># Remove the next comment character if you are not familiar with SQL</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">#safe-updates</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">[isamchk]</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">key_buffer = 20M</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">sort_buffer_size = 20M</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">read_buffer = 2M</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">write_buffer = 2M</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">[myisamchk]</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">key_buffer = 20M</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">sort_buffer_size = 20M</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">read_buffer = 2M</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">write_buffer = 2M</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">[mysqlhotcopy]</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">interactive-timeout</div>
]]></content:encoded>
			<wfw:commentRss>http://www.shenmiguo.com/archives/2009/322_mysql-config.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mysql跨库主从热备失效问题</title>
		<link>http://www.shenmiguo.com/archives/2009/321_mysql-replications.html</link>
		<comments>http://www.shenmiguo.com/archives/2009/321_mysql-replications.html#comments</comments>
		<pubDate>Thu, 29 Oct 2009 06:51:10 +0000</pubDate>
		<dc:creator>神秘果</dc:creator>
				<category><![CDATA[数据库]]></category>
		<category><![CDATA[程序设计]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.shenmiguo.com/?p=321</guid>
		<description><![CDATA[
	在InnoDB引擎下发现，Mysql的主从热备存在数据不一致的问题，一些数据没有成功同步到备机。在use databases后，更新的表必须是当前选择的database才同步。譬如连上Mysql服务后操作：

	

	USE test2;

	UPDATE client SET name=&#39;test&#39; WHERE uid=1;

	数据未能同步到备机，而使用use &#160;test后，才可以成功同步，如下方式：

	USE test; 

	UPDATE client SET name=&#39;test&#39; WHERE uid=1;

	&#160;

	仔细看Mysql手册，发现同步启动选项中还有玄机，只设置replicate-do-db指定同步数据库还不够。是没有设置replicate-wild-do-table导致的跨库同步问题。Mysql默认是同步指定数据库下的更新操作，若要跨库操作更新同步，就必须指定replicate-wild-do-table参数。下面是Mysql手册中对replicate-do-db和replicate-wild-do-table启动选项的说明：

	&#160;

	&#8211;replicate-do-db=db_name

	告诉slave只同步那些缺省数据库是 db_name (也就是用 USE 选中的)的语句。想要指定更多的数据库，只需多次使用该选项，每次指定一个数据库。注意，类似 UPDATE some_db.some_table SET foo=&#39;bar&#39; 这样的跨库操作语句以及没有选中数据库的操作都不会被同步。如果必须使用跨库操作，要确保使用MySQL 3.23.28或更高，并且使用 &#8211;replicate-wild-do-table=db_name.% 选项。请仔细阅读最后面的注意事项。

	下面是一个不能按照预期工作的例子：如果启动slave时使用 &#8211;replicate-do-db=sales 选项，并且在master上执行下列语句，那么这个 UPDATE 语句不会被同步：

	USE prices;

	UPDATE sales.january SET amount=amount+1000;

	如果需要同步跨库操作，只需使用 &#8211;replicate-wild-do-table=db_name.% 选项。这个&#34;只检查缺省数据库&#34;特性的主要原因是因为想要单从一个语句中判断是否要被同步比较困难(例如，使用多表 DELETE 或者 UPDATE，这就跨库了)。不过想要检查是否是缺省数据库却很快。

	&#160;

	&#8211;replicate-wild-do-table=db_name.tbl_name

	限制slave只同步那些匹配指定模式的数据表。模式中可以包含通配符 `%` 和 `_`，它们的含义和 LIKE 模式一样。想要指定更多的数据表，只需多次使用该选项，每次指定一个数据表。请仔细阅读最后面的注意事项。

	例如： &#8211;replicate-wild-do-table=foo%.bar% 会同步所有以 foo 开头的数据库下的以 bar 开头的数据表上的更新操作。

	如果匹配模式是 %，则匹配所有的表名，且应用到数据库级语句(CREATE DATABASE, DROP [...]]]></description>
			<content:encoded><![CDATA[<p>
	<span style="font-family: 宋体;">在</span>InnoDB<span style="font-family: 宋体;">引擎下发现，</span>Mysql<span style="font-family: 宋体;">的主从热备存在数据不一致的问题，一些数据没有成功同步到备机。在</span>use databases<span style="font-family: 宋体;">后，更新的表必须是当前选择的</span>database<span style="font-family: 宋体;">才同步。譬如连上</span>Mysql<span style="font-family: 宋体;">服务后操作：</span></p>
<p>
	<span style="font-family: 宋体;"><span id="more-321"></span></span></p>
<div style="margin-bottom: 3.9pt; line-height: 125%;">
	<i>USE test2;</i></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">
	<i>UPDATE client SET name=&#39;test&#39; WHERE uid=1;</i></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">
	<span style="font-family: 宋体;">数据未能同步到备机，而使用</span>use &nbsp;test<span style="font-family: 宋体;">后，才可以成功同步，如下方式：</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">
	<i>USE test; </i></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">
	<i>UPDATE client SET name=&#39;test&#39; WHERE uid=1;</i></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">
	&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">
	<span style="font-family: 宋体;">仔细看</span>Mysql<span style="font-family: 宋体;">手册，发现同步启动选项中还有玄机，只设置</span>replicate-do-db<span style="font-family: 宋体;">指定同步数据库还不够。是没有设置</span>replicate-wild-do-table<span style="font-family: 宋体;">导致的跨库同步问题。</span>Mysql<span style="font-family: 宋体;">默认是同步指定数据库下的更新操作，若要跨库操作更新同步，就必须指定</span>replicate-wild-do-table<span style="font-family: 宋体;">参数。下面是</span>Mysql<span style="font-family: 宋体;">手册中对</span>replicate-do-db<span style="font-family: 宋体;">和</span>replicate-wild-do-table<span style="font-family: 宋体;">启动选项的说明：</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">
	&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">
	<span style="color: red;">&#8211;replicate-do-db=db_name</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">
	<span style="font-family: 宋体;">告诉</span>slave<span style="font-family: 宋体;">只同步那些缺省数据库是</span> db_name (<span style="font-family: 宋体;">也就是用</span> USE <span style="font-family: 宋体;">选中的</span>)<span style="font-family: 宋体;">的语句。想要指定更多的数据库，只需多次使用该选项，每次指定一个数据库。注意，类似</span> UPDATE some_db.some_table SET foo=&#39;bar&#39; <span style="font-family: 宋体;">这样的<span style="color: red;">跨库操作语句以及没有选中数据库的操作都不会被同步</span>。如果必须使用跨库操作，要确保使用</span>MySQL 3.23.28<span style="font-family: 宋体;">或更高，并且使用</span> &#8211;replicate-wild-do-table=db_name.% <span style="font-family: 宋体;">选项。请仔细阅读最后面的注意事项。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">
	<span style="font-family: 宋体;">下面是一个不能按照预期工作的例子：如果启动</span>slave<span style="font-family: 宋体;">时使用</span> &#8211;replicate-do-db=sales <span style="font-family: 宋体;">选项，并且在</span>master<span style="font-family: 宋体;">上执行下列语句，那么这个</span> UPDATE <span style="font-family: 宋体;">语句不会被同步：</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">
	<i>USE prices;</i></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">
	<i>UPDATE sales.january SET amount=amount+1000;</i></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">
	<span style="font-family: 宋体; color: red;">如果需要同步跨库操作，只需使用</span><span style="color: red;"> &#8211;replicate-wild-do-table=db_name.% </span><span style="font-family: 宋体; color: red;">选项</span><span style="font-family: 宋体;">。这个</span>&quot;<span style="font-family: 宋体;">只检查缺省数据库</span>&quot;<span style="font-family: 宋体;">特性的主要原因是因为想要单从一个语句中判断是否要被同步比较困难</span>(<span style="font-family: 宋体;">例如，使用多表</span> DELETE <span style="font-family: 宋体;">或者</span> UPDATE<span style="font-family: 宋体;">，这就跨库了</span>)<span style="font-family: 宋体;">。不过想要检查是否是缺省数据库却很快。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">
	&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">
	<span style="color: red;">&#8211;replicate-wild-do-table=db_name.tbl_name</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">
	<span style="font-family: 宋体;">限制</span>slave<span style="font-family: 宋体;">只同步那些匹配指定模式的数据表。模式中可以包含通配符</span> `%` <span style="font-family: 宋体;">和</span> `_`<span style="font-family: 宋体;">，它们的含义和</span> LIKE <span style="font-family: 宋体;">模式一样。想要指定更多的数据表，只需多次使用该选项，每次指定一个数据表。请仔细阅读最后面的注意事项。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">
	<span style="font-family: 宋体;">例如：</span> &#8211;replicate-wild-do-table=foo%.bar% <span style="font-family: 宋体;">会同步所有以</span> foo <span style="font-family: 宋体;">开头的数据库下的以</span> bar <span style="font-family: 宋体;">开头的数据表上的更新操作。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">
	<span style="font-family: 宋体;">如果匹配模式是</span> %<span style="font-family: 宋体;">，则匹配所有的表名，且应用到数据库级语句</span>(CREATE DATABASE, DROP DATABASE,<span style="font-family: 宋体;">和</span> ALTER DATABASE)<span style="font-family: 宋体;">。例如，使用</span> &#8211;replicate-wild-do-table=foo%.% <span style="font-family: 宋体;">选项的话，所有匹配</span> foo% <span style="font-family: 宋体;">模式的数据库级操作都会被同步。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">
	<span style="font-family: 宋体;">如果想要在数据库</span>/<span style="font-family: 宋体;">表模式中包含原义通配符，需要用反斜杠来转义它们。例如，想要同步</span> my_own%db <span style="font-family: 宋体;">数据库下的所有表，但是不想同步</span> my1ownAABCdb <span style="font-family: 宋体;">数据库下的表，就需要转义字符</span> `_`<span style="font-family: 宋体;">：</span> &#8211;replicate-wild-do-table=my\_own\%db<span style="font-family: 宋体;">。如果是在命令行中使用这个选项，就可能需要两个反斜杠来转义，这依赖于命令行解释器。例如，在</span> bash shell<span style="font-family: 宋体;">下，就需要输入：</span> &#8211;replicate-wild-do-table=my\\_own\\%db<span style="font-family: 宋体;">。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">
	&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">
	<span style="font-family: 宋体; color: red;">还存在一些问题</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">
	<span style="font-family: 宋体;">不管有没有</span>replicate-wild-do-table<span style="font-family: 宋体;">选项，更新操作必须是</span>mysql<span style="font-family: 宋体;">连接已经有选择的数据库了才进行，譬如新建的</span>mysql<span style="font-family: 宋体;">（新连接是没有默认选择的</span>database<span style="font-family: 宋体;">的）连接中执行：</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">
	<i>UPDATE test.client SET name=&#39;test&#39; WHERE uid=1;</i></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">
	<span style="font-family: 宋体;">这条更新无法同步到备机，必须在</span>update<span style="font-family: 宋体;">前</span>use database<span style="font-family: 宋体;">操作，该</span>database<span style="font-family: 宋体;">必须是</span>replicate-wild-do-table<span style="font-family: 宋体;">中指定的</span>database<span style="font-family: 宋体;">。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">
	<span style="font-family: 宋体; color: red;">保险的解决方式</span><span style="font-family: 宋体;">：连接上</span>mysql<span style="font-family: 宋体;">后，调用</span>mysql_select_db()<span style="font-family: 宋体;">选择数据库，之后进行的更新操作就可以自动同步了。</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">
	&nbsp;</div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">
	<span style="color: red;">SQL</span><span style="font-family: 宋体; color: red;">模式匹配</span></div>
<div style="margin-bottom: 3.9pt; line-height: 125%;">
	SQL<span style="font-family: 宋体;">的模式匹配允许你使用&ldquo;</span>_<span style="font-family: 宋体;">&rdquo;匹配任何单个字符，而&ldquo;</span>%<span style="font-family: 宋体;">&rdquo;匹配任意数目字符</span>(<span style="font-family: 宋体;">包括零个字符</span>)<span style="font-family: 宋体;">。在</span> MySQL<span style="font-family: 宋体;">中，</span>SQL<span style="font-family: 宋体;">的模式缺省是忽略大小写的。下面显示一些例子。注意在你使用</span>SQL<span style="font-family: 宋体;">模式时，你不能使用</span>=<span style="font-family: 宋体;">或</span>!=<span style="font-family: 宋体;">；而使用</span>LIKE<span style="font-family: 宋体;">或</span>NOT LIKE<span style="font-family: 宋体;">比较操作符。</span></div>
]]></content:encoded>
			<wfw:commentRss>http://www.shenmiguo.com/archives/2009/321_mysql-replications.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Apache和Mysql的并发配置</title>
		<link>http://www.shenmiguo.com/archives/2009/320_apache-mysql-perf.html</link>
		<comments>http://www.shenmiguo.com/archives/2009/320_apache-mysql-perf.html#comments</comments>
		<pubDate>Tue, 27 Oct 2009 10:24:05 +0000</pubDate>
		<dc:creator>神秘果</dc:creator>
				<category><![CDATA[程序设计]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.shenmiguo.com/?p=320</guid>
		<description><![CDATA[
	在测试页面并发压力的时候，并发到80以后，响应速度急剧下降，CPU占用率急剧上升。经分析，是Apache并发数和Mysql并发数匹配问题。

	

	Mysql并发瓶颈

	Mysql的连接数到达150以上的时候，服务器4核cpu占有率会急增，性能会急剧下降。Apache并发80的情况下，mysql连接数基本上到了配置的满额200（max-connections=200）。

	&#160;

	Apache与mysql的并发关系

	Apache最大并发数配置是600，大于mysql最大并发数200，每个apache请求要对应一个mysql连接，而Apache的并发能力要远大于mysql服务器的并发能力。高并发情况下，mysql的查询还没有返回结果，但下一次的apache请求已经到了，堆积效果就是mysql都是满额并发运行，可能导致连接mysql错误：&#8220;too many connections&#8230;&#8221;。

	&#160;

	Apache做Mysql的连接池

	从上面分析可以看出， mysql_pconnect连接Mysql，但没有控制和管理mysql连接数，可能导致Mysql服务器忙死。只要有连接池，就可以解决问题。

	利用apache做mysql的连接池，即控制apache的并发数。apache配置最大并发数（如20）小于mysql最大连接数。当并发过大的时候，就自动利用apache的队列来达到连接池的目的。虽然牺牲了apache性能，但保证了业务的稳定性和安全性，也不会导致Mysql服务器忙死。

	apache最大并发数配置的一个缺陷是：无法配置虚拟主机的并发数，只能配置全局并发数。

	使用Apache的prefork模式配置并发数：

	http://www.shenmiguo.com/archives/2009/318_apache-mpm.html

	Mysql持久连接介绍：

	http://www.shenmiguo.com/archives/2009/319_mysql-pconnect.html
]]></description>
			<content:encoded><![CDATA[<p>
	<span class="Apple-style-span" style="line-height: 18px; "><span style="font-family:宋体;">在测试页面并发压力的时候，并发到</span>80<span style="font-family:宋体;">以后，响应速度急剧下降，</span>CPU<span style="font-family:宋体;">占用率急剧上升。经分析，是</span>Apache<span style="font-family:宋体;">并发数和</span>Mysql<span style="font-family:宋体;">并发数匹配问题。</span></span></p>
<div style="line-height:150%">
	<span id="more-320"></span></div>
<div style="line-height:150%">
	<b>Mysql</b><b><span style="font-family:宋体;">并发瓶颈</span></b></div>
<div style="line-height:150%">
	Mysql<span style="font-family:宋体;">的连接数到达</span>150<span style="font-family:宋体;">以上的时候，服务器</span>4<span style="font-family:宋体;">核</span>cpu<span style="font-family:宋体;">占有率会急增，性能会急剧下降。</span>Apache<span style="font-family:宋体;">并发</span>80<span style="font-family:宋体;">的情况下，</span>mysql<span style="font-family:宋体;">连接数基本上到了配置的满额</span>200<span style="font-family:宋体;">（</span>max-connections=200<span style="font-family:宋体;">）。</span></div>
<div style="line-height:150%">
	&nbsp;</div>
<div style="line-height:150%">
	<b>Apache</b><b><span style="font-family:宋体;">与</span>mysql</b><b><span style="font-family:宋体;">的并发关系</span></b></div>
<div style="line-height:150%">
	Apache<span style="font-family:宋体;">最大并发数配置是</span>600<span style="font-family:宋体;">，大于</span>mysql<span style="font-family:宋体;">最大并发数</span>200<span style="font-family:宋体;">，每个</span>apache<span style="font-family:宋体;">请求要对应一个</span>mysql<span style="font-family:宋体;">连接，而</span>Apache<span style="font-family:宋体;">的并发能力要远大于</span>mysql<span style="font-family:宋体;">服务器的并发能力。高并发情况下，</span>mysql<span style="font-family:宋体;">的查询还没有返回结果，但下一次的</span>apache<span style="font-family:宋体;">请求已经到了，堆积效果就是</span>mysql<span style="font-family:宋体;">都是满额并发运行，可能导致连接</span>mysql<span style="font-family:宋体;">错误：&ldquo;</span>too many connections<span style="font-family:宋体;">&hellip;&rdquo;。</span></div>
<div style="line-height:150%">
	&nbsp;</div>
<div style="line-height:150%">
	<b>Apache</b><b><span style="font-family:宋体;">做</span>Mysql</b><b><span style="font-family:宋体;">的连接池</span></b></div>
<div style="line-height:150%">
	<span style="font-family:宋体;">从上面分析可以看出，</span> mysql_pconnect<span style="font-family:宋体;">连接</span>Mysql<span style="font-family:宋体;">，但没有控制和管理</span>mysql<span style="font-family:宋体;">连接数，可能导致</span>Mysql<span style="font-family:宋体;">服务器忙死。只要有连接池，就可以解决问题。</span></div>
<div style="line-height:150%">
	<span style="font-family:宋体;">利用</span>apache<span style="font-family:宋体;">做</span>mysql<span style="font-family:宋体;">的连接池，即控制</span>apache<span style="font-family:宋体;">的并发数。</span>apache<span style="font-family:宋体;">配置最大并发数（如</span>20<span style="font-family:宋体;">）小于</span>mysql<span style="font-family:宋体;">最大连接数。当并发过大的时候，就自动利用</span>apache<span style="font-family:宋体;">的队列来达到连接池的目的。虽然牺牲了</span>apache<span style="font-family:宋体;">性能，但保证了业务的稳定性和安全性，也不会导致</span>Mysql<span style="font-family:宋体;">服务器忙死。</span></div>
<div style="line-height:150%">
	apache<span style="font-family:宋体;">最大并发数配置的一个缺陷是：无法配置虚拟主机的并发数，只能配置全局并发数。</span></div>
<div style="line-height:150%">
	<span style="font-family:宋体;">使用</span>Apache<span style="font-family:宋体;">的</span>prefork<span style="font-family:宋体;">模式配置并发数：</span></div>
<div style="line-height:150%">
	<a href="http://www.shenmiguo.com/archives/2009/318_apache-mpm.html">http://www.shenmiguo.com/archives/2009/318_apache-mpm.html</a></div>
<div style="line-height:150%">
	Mysql<span style="font-family:宋体;">持久连接介绍：</span></div>
<div style="line-height:150%">
	<a href="http://www.shenmiguo.com/archives/2009/319_mysql-pconnect.html">http://www.shenmiguo.com/archives/2009/319_mysql-pconnect.html</a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.shenmiguo.com/archives/2009/320_apache-mysql-perf.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Mysql持久连接</title>
		<link>http://www.shenmiguo.com/archives/2009/319_mysql-pconnect.html</link>
		<comments>http://www.shenmiguo.com/archives/2009/319_mysql-pconnect.html#comments</comments>
		<pubDate>Tue, 27 Oct 2009 09:16:12 +0000</pubDate>
		<dc:creator>神秘果</dc:creator>
				<category><![CDATA[数据库]]></category>
		<category><![CDATA[程序设计]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[mysql]]></category>

		<guid isPermaLink="false">http://www.shenmiguo.com/?p=319</guid>
		<description><![CDATA[
	长短连接区别

	不同于mysql_connect的短连接，mysql_pconnect持久连接的时候，将先尝试寻找一个在同一个主机上用同样的用户名和密码已经打开的（持久）连接，如果找到，则返回此连接标识而不打开新连接。

	

	当执行完毕后，到 mysql 服务器的持久连接不会被关闭，此连接将保持打开以备以后使用，即mysql_close() 不会关闭由 mysql_pconnect() 建立的连接。

	&#160;

	Apache与长连接管理

	PHP本身并没有数据库连接池的概念，但是Apache有进程池的概念, 一个Apache子进程结束后会被放回进程池, 这也就使得用mysql_pconnect打开的的那个mysql连接资源可以不被释放，而是依附在相应的Apache子进程上保存到了进程池中。于是在下一个连接请求时它就可以被复用。但是在Apache并发访问量大的时候，如果使用mysql_pconnect，会由于之前的Apache子进程占用的MySQL连接没有close, 很快使MySQL达到最大连接数，使得之后的请求可能得不到响应。

	当然，高并发情况下也不能怪罪pconnect，用短连接频繁连接mysql，也一样有问题。在没有连接池的情况下，用apache做连接池管理是比较好的选择。
]]></description>
			<content:encoded><![CDATA[<p>
	<span class="Apple-style-span" style="line-height: 18px; "><b><span style="font-size:12.0pt;line-height:150%;font-family:宋体;">长短连接区别</span></b></span></p>
<div style="line-height:150%">
	<span style="font-family:宋体;">不同于</span>mysql_connect<span style="font-family:宋体;">的短连接，</span>mysql_pconnect<span style="font-family:宋体;">持久连接的时候，将先尝试寻找一个在同一个主机上用同样的用户名和密码已经打开的（持久）连接，如果找到，则返回此连接标识而不打开新连接。</span></div>
<div style="line-height:150%">
	<span id="more-319"></span></div>
<div style="line-height:150%">
	<span style="font-family:宋体;">当执行完毕后，到</span> mysql <span style="font-family:宋体;">服务器的持久连接不会被关闭，此连接将保持打开以备以后使用，即</span>mysql_close() <span style="font-family:宋体;">不会关闭由</span> mysql_pconnect() <span style="font-family:宋体;">建立的连接。</span></div>
<div style="line-height:150%">
	&nbsp;</div>
<div style="line-height:150%">
	<b><span style="font-size:12.0pt;line-height:150%">Apache</span></b><b><span style="font-size:12.0pt;line-height:<br />
150%;font-family:宋体;">与长连接管理</span></b></div>
<div style="line-height:150%">
	PHP<span style="font-family:宋体;">本身并没有数据库连接池的概念，但是</span>Apache<span style="font-family:宋体;">有进程池的概念</span>, <span style="font-family:宋体;">一个</span>Apache<span style="font-family:宋体;">子进程结束后会被放回进程池</span>, <span style="font-family:宋体;">这也就使得用</span>mysql_pconnect<span style="font-family:宋体;">打开的的那个</span>mysql<span style="font-family:宋体;">连接资源可以不被释放，而是依附在相应的</span>Apache<span style="font-family:宋体;">子进程上保存到了进程池中。于是在下一个连接请求时它就可以被复用。但是在</span>Apache<span style="font-family:宋体;">并发访问量大的时候，如果使用</span>mysql_pconnect<span style="font-family:宋体;">，会由于之前的</span>Apache<span style="font-family:宋体;">子进程占用的</span>MySQL<span style="font-family:宋体;">连接没有</span>close, <span style="font-family:宋体;">很快使</span>MySQL<span style="font-family:宋体;">达到最大连接数，使得之后的请求可能得不到响应。</span></div>
<div style="line-height:150%">
	<span style="font-family:宋体;">当然，高并发情况下也不能怪罪</span>pconnect<span style="font-family:宋体;">，用短连接频繁连接</span>mysql<span style="font-family:宋体;">，也一样有问题。在没有连接池的情况下，用</span>apache<span style="font-family:宋体;">做连接池管理是比较好的选择。</span></div>
]]></content:encoded>
			<wfw:commentRss>http://www.shenmiguo.com/archives/2009/319_mysql-pconnect.html/feed</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Apache多路处理与并发配置</title>
		<link>http://www.shenmiguo.com/archives/2009/318_apache-mpm.html</link>
		<comments>http://www.shenmiguo.com/archives/2009/318_apache-mpm.html#comments</comments>
		<pubDate>Tue, 27 Oct 2009 07:55:15 +0000</pubDate>
		<dc:creator>神秘果</dc:creator>
				<category><![CDATA[数据库]]></category>
		<category><![CDATA[程序设计]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[mpm]]></category>
		<category><![CDATA[并发]]></category>

		<guid isPermaLink="false">http://www.shenmiguo.com/?p=318</guid>
		<description><![CDATA[
	Apache通过多路处理模块（Multi-Processing Module）MPM控制并发，常用的有两种模式：prefork（默认）和worker，通过apachectrl &#160;-l可看到当前加载MPM模块（prefork.c或者worker.c）。

	

	prefork模式是预派生子进程方式，使用多个子进程，每个子进程只有一个线程。每个进程在某个确定的时间只能维持一个连接。

	worker模式是多线程与多进程混合方式，使用多个子进程，每个子进程有多个线程。每个线程在某个确定的时间只能维持一个连接。

	总的来说，prefork方式速度要稍高于worker，然而它需要的cpu和memory资源也稍多于woker。

	&#160;

	prefork模式

	httpd.conf中，prefork的配置如下：

	&#60;IfModule prefork.c&#62;

	ServerLimit &#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160;2000

	StartServers&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 300

	MinSpareServers&#160;&#160;&#160;&#160;&#160; 5

	MaxSpareServers&#160;&#160;&#160;&#160; 10

	MaxClients&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; &#160;600

	MaxRequestsPerChild&#160;10000

	&#60;/IfModule&#62;

	prefork的工作原理是，控制进程在最初建立&#34;StartServers&#34;个子进程后，为了满足&#34;MinSpareServers&#34;设置的需要创建一个进程，等待一秒钟，继续创建两个，再等待一秒钟，继续创建四个&#8230;&#8230;如此按指数级增加创建的进程数，最多达到每秒32个，直到满足 MinSpareServers设置的值为止。这就是预派生（prefork）的由来。这种模式可以不必在请求到来时再产生新的进程，从而减小了系统开销以增加性能。

	MaxClients是最重要的一个参数。可通过MaxClients来控制Apache并发数。

	&#160;

	prefork指令

	ServerLimit

	默认的MaxClient最大是600个线程,如果想设置更大的值，就的加上ServerLimit这个参数。20000是ServerLimit这个参数的最大值。如果需要更大，则必须编译apache，此前都是不需要重新编译Apache。

	生效前提：必须放在其他指令的前面。

	StartServers

	指定服务器启动时建立的子进程数量。应该要小于等于MaxClients。

	MinSpareServers

	指定空闲子进程的最小数量，默认为5。如果当前空闲子进程数少于MinSpareServers ，那么Apache将以最大每秒一个的速度产生新的子进程。此参数不要设的太大。

	MaxSpareServers

	设置空闲子进程的最大数量，默认为10。如果当前有超过MaxSpareServers数量的空闲子进程，那么父进程将杀死多余的子进程。此参数不要设的太大。如果你将该指令的值设置为比MinSpareServers小，Apache将会自动将其修改成MinSpareServers+1。

	MaxClients

	限定同一时间客户端最大接入请求的数量(单个进程并发线程数)，默认为600。任何超过MaxClients限制的请求都将进入等候队列,一旦一个链接被释放，队列中的请求将得到服务。要增大这个值，你必须同时增大ServerLimit。

	MaxRequestsPerChild

	MaxRequestsPerChild指令控制服务器杀死旧进程产生新进程的频率。每个子进程在其生存期内允许伺服的最大请求数量，默认为10000。到达MaxRequestsPerChild的限制后，子进程将会结束。如果MaxRequestsPerChild为&#8221;0&#8243;，子进程将永远不会结束。将MaxRequestsPerChild设置成非零值有两个好处：

	1. 可以防止(偶然的)内存泄漏无限进行，从而耗尽内存。

	2. 给进程一个有限寿命，从而有助于当服务器负载减轻的时候减少活动进程的数量。

	&#160;

	worker模式

	httpd.conf中，prefork的配置如下：

	&#60;IfModule worker.c&#62;

	ServerLimit 25

	ThreadLimit &#160;&#160;&#160;&#160;&#160;&#160;&#160;200

	StartServers&#160;&#160;&#160;&#160;&#160;&#160;&#160; 3 

	MaxClients&#160;&#160;&#160;&#160;&#160;&#160;&#160;&#160; 600

	MinSpareThreads&#160;&#160;&#160;&#160; 50

	MaxSpareThreads&#160;&#160;&#160;&#160; 100

	ThreadsPerChild&#160;&#160;&#160;&#160; 100

	MaxRequestsPerChild&#160;10000

	&#60;/IfModule&#62;

	worker的工作原理是，由主控制进程生成&#34;StartServers&#34;个子进程，每个子进程中包含固定的ThreadsPerChild线程数，各个线程独立地处理请求。同样，为了不在请求到来时再生成线程，MinSpareThreads和MaxSpareThreads设置了最少和最多的空闲线程数；而MaxClients设置了所有子进程中的线程总数。如果现有子进程中的线程总数不能满足负载，控制进程将派生新的子进程。

	ThreadsPerChild

	是worker模式中与性能相关最密切的指令。这个指令设置了每个子进程建立的线程数。子进程在启动时建立这些线程后就不再建立新的线程了。

	&#160;

	资源

	prefork文档：http://lamp.linux.gov.cn/Apache/ApacheMenu/mod/prefork.html

	workder文档：http://lamp.linux.gov.cn/Apache/ApacheMenu/mod/worker.html
]]></description>
			<content:encoded><![CDATA[<p>
	<span class="Apple-style-span" style="line-height: 18px; ">Apache<span style="font-family:宋体;">通过<b>多路处理模块</b>（</span>Multi-Processing Module<span style="font-family:宋体;">）</span>MPM<span style="font-family:宋体;">控制并发，常用的有两种模式：</span>prefork<span style="font-family:宋体;">（默认）和</span>worker<span style="font-family:宋体;">，通过</span><span style="color:red">apachectrl &nbsp;-l</span><span style="font-family:宋体;">可看到当前加载</span>MPM<span style="font-family:宋体;">模块（</span>prefork.c<span style="font-family:宋体;">或者</span>worker.c<span style="font-family:宋体;">）。</span></span></p>
<div style="line-height:150%;">
	<span id="more-318"></span></div>
<div style="line-height:150%">
	<span style="color:red">prefork</span><span style="font-family:宋体;">模式是预派生子进程方式，使用多个子进程，每个子进程只有一个线程。每个进程在某个确定的时间只能维持一个连接。</span></div>
<div style="line-height:150%">
	<span style="color:red">worker</span><span style="font-family:宋体;">模式是多线程与多进程混合方式，使用多个子进程，每个子进程有多个线程。每个线程在某个确定的时间只能维持一个连接。</span></div>
<div style="line-height:150%">
	<span style="font-family:宋体;">总的来说，</span>prefork<span style="font-family:宋体;">方式速度要稍高于</span>worker<span style="font-family:宋体;">，然而它需要的</span>cpu<span style="font-family:宋体;">和</span>memory<span style="font-family:宋体;">资源也稍多于</span>woker<span style="font-family:宋体;">。</span></div>
<div style="line-height:150%">
	&nbsp;</div>
<div style="line-height:150%;">
	<b><span style="font-size:12.0pt;<br />
line-height:150%">prefork</span></b><b><span style="font-size:12.0pt;line-height:150%;font-family:宋体;">模式</span></b></div>
<div style="line-height:150%">
	httpd.conf<span style="font-family:宋体;">中，</span>prefork<span style="font-family:宋体;">的配置如下：</span></div>
<div style="line-height:150%">
	&lt;IfModule prefork.c&gt;</div>
<div style="line-height:150%">
	ServerLimit <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;2000</span></div>
<div style="line-height:150%">
	StartServers<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 300</span></div>
<div style="line-height:150%">
	MinSpareServers<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 5</span></div>
<div style="line-height:150%">
	MaxSpareServers<span>&nbsp;&nbsp;&nbsp;&nbsp; 10</span></div>
<div style="line-height:150%">
	MaxClients<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;600</span></div>
<div style="line-height:150%">
	MaxRequestsPerChild&nbsp;10000</div>
<div style="line-height:150%">
	&lt;/IfModule&gt;</div>
<div style="line-height:150%">
	prefork<span style="font-family:宋体;">的工作原理是，控制进程在最初建立</span>&quot;StartServers&quot;<span style="font-family:宋体;">个子进程后，为了满足</span>&quot;MinSpareServers&quot;<span style="font-family:宋体;">设置的需要创建一个进程，等待一秒钟，继续创建两个，再等待一秒钟，继续创建四个&hellip;&hellip;如此按指数级增加创建的进程数，最多达到每秒</span>32<span style="font-family:宋体;">个，直到满足</span> MinSpareServers<span style="font-family:宋体;">设置的值为止。这就是预派生（</span>prefork<span style="font-family:宋体;">）的由来。这种模式可以不必在请求到来时再产生新的进程，从而减小了系统开销以增加性能。</span></div>
<div style="line-height:150%">
	<span style="color:red">MaxClients</span><span style="font-family:宋体;">是最重要的一个参数。可通过</span>MaxClients<span style="font-family:宋体;">来控制</span>Apache<span style="font-family:宋体;">并发数。</span></div>
<div style="line-height:150%">
	&nbsp;</div>
<div style="line-height:150%;">
	<b><span style="font-size:12.0pt;<br />
line-height:150%">prefork</span></b><b><span style="font-size:12.0pt;line-height:150%;font-family:宋体;">指令</span></b></div>
<div style="line-height:150%">
	<span style="color:red">ServerLimit</span></div>
<div style="line-height:150%">
	<span style="font-family:宋体;">默认的</span>MaxClient<span style="font-family:宋体;">最大是</span>600<span style="font-family:宋体;">个线程</span>,<span style="font-family:宋体;">如果想设置更大的值，就的加上</span>ServerLimit<span style="font-family:宋体;">这个参数。</span>20000<span style="font-family:宋体;">是</span>ServerLimit<span style="font-family:宋体;">这个参数的最大值。如果需要更大，则必须编译</span>apache<span style="font-family:宋体;">，此前都是不需要重新编译</span>Apache<span style="font-family:宋体;">。</span></div>
<div style="line-height:150%">
	<span style="font-family:宋体;">生效前提：必须放在其他指令的前面。</span></div>
<div style="line-height:150%">
	<span style="color:red">StartServers</span></div>
<div style="line-height:150%">
	<span style="font-family:宋体;">指定服务器启动时建立的子进程数量。应该要小于等于</span>MaxClients<span style="font-family:宋体;">。</span></div>
<div style="line-height:150%">
	<span style="color:red">MinSpareServers</span></div>
<div style="line-height:150%">
	<span style="font-family:宋体;">指定空闲子进程的最小数量，默认为</span>5<span style="font-family:宋体;">。如果当前空闲子进程数少于</span>MinSpareServers <span style="font-family:宋体;">，那么</span>Apache<span style="font-family:宋体;">将以最大每秒一个的速度产生新的子进程。此参数不要设的太大。</span></div>
<div style="line-height:150%">
	<span style="color:red">MaxSpareServers</span></div>
<div style="line-height:150%">
	<span style="font-family:宋体;">设置空闲子进程的最大数量，默认为</span>10<span style="font-family:宋体;">。如果当前有超过</span>MaxSpareServers<span style="font-family:宋体;">数量的空闲子进程，那么父进程将杀死多余的子进程。此参数不要设的太大。如果你将该指令的值设置为比</span>MinSpareServers<span style="font-family:宋体;">小，</span>Apache<span style="font-family:宋体;">将会自动将其修改成</span>MinSpareServers+1<span style="font-family:宋体;">。</span></div>
<div style="line-height:150%">
	<b><span style="color:red">MaxClients</span></b></div>
<div style="line-height:150%">
	<span style="font-family:宋体;">限定同一时间客户端最大接入请求的数量</span>(<span style="font-family:宋体;">单个进程并发线程数</span>)<span style="font-family:宋体;">，默认为</span>600<span style="font-family:宋体;">。任何超过</span>MaxClients<span style="font-family:宋体;">限制的请求都将进入等候队列</span>,<span style="font-family:宋体;">一旦一个链接被释放，队列中的请求将得到服务。要增大这个值，你必须同时增大</span>ServerLimit<span style="font-family:宋体;">。</span></div>
<div style="line-height:150%">
	<span style="color:red">MaxRequestsPerChild</span></div>
<div style="line-height:150%">
	MaxRequestsPerChild<span style="font-family:宋体;">指令控制服务器杀死旧进程产生新进程的频率。每个子进程在其生存期内允许伺服的最大请求数量，默认为</span>10000<span style="font-family:宋体;">。到达</span>MaxRequestsPerChild<span style="font-family:宋体;">的限制后，子进程将会结束。如果</span>MaxRequestsPerChild<span style="font-family:宋体;">为&rdquo;</span>0<span style="font-family:宋体;">&Prime;，子进程将永远不会结束。将</span><span style="color:red">MaxRequestsPerChild</span><span style="font-family:<br />
宋体;color:red">设置成非零值</span><span style="font-family:宋体;">有两个好处：</span></div>
<div style="line-height:150%">
	1. <span style="font-family:宋体;">可以防止</span>(<span style="font-family:宋体;">偶然的</span>)<span style="font-family:宋体;">内存泄漏无限进行，从而耗尽内存。</span></div>
<div style="line-height:150%">
	2. <span style="font-family:宋体;">给进程一个有限寿命，从而有助于当服务器负载减轻的时候减少活动进程的数量。</span></div>
<div style="line-height:150%">
	&nbsp;</div>
<div style="line-height:150%;">
	<b><span style="font-size:12.0pt;<br />
line-height:150%">worker</span></b><b><span style="font-size:12.0pt;line-height:150%;font-family:宋体;">模式</span></b></div>
<div style="line-height:150%">
	httpd.conf<span style="font-family:宋体;">中，</span>prefork<span style="font-family:宋体;">的配置如下：</span></div>
<div style="line-height:150%">
	&lt;IfModule worker.c&gt;</div>
<div style="line-height:150%">
	ServerLimit 25</div>
<div style="line-height:150%">
	ThreadLimit <span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;200</span></div>
<div style="line-height:150%">
	StartServers<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 3 </span></div>
<div style="line-height:150%">
	MaxClients<span>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 600</span></div>
<div style="line-height:150%">
	MinSpareThreads<span>&nbsp;&nbsp;&nbsp;&nbsp; 50</span></div>
<div style="line-height:150%">
	MaxSpareThreads<span>&nbsp;&nbsp;&nbsp;&nbsp; 100</span></div>
<div style="line-height:150%">
	<span style="color:red">ThreadsPerChild</span><span>&nbsp;&nbsp;&nbsp;&nbsp; 100</span></div>
<div style="line-height:150%">
	MaxRequestsPerChild&nbsp;10000</div>
<div style="line-height:150%">
	&lt;/IfModule&gt;</div>
<div style="line-height:150%">
	worker<span style="font-family:宋体;">的工作原理是，由主控制进程生成</span>&quot;StartServers&quot;<span style="font-family:宋体;">个子进程，每个子进程中包含固定的</span>ThreadsPerChild<span style="font-family:宋体;">线程数，各个线程独立地处理请求。同样，为了不在请求到来时再生成线程，</span>MinSpareThreads<span style="font-family:宋体;">和</span>MaxSpareThreads<span style="font-family:宋体;">设置了最少和最多的空闲线程数；而</span>MaxClients<span style="font-family:宋体;">设置了所有子进程中的线程总数。如果现有子进程中的线程总数不能满足负载，控制进程将派生新的子进程。</span></div>
<div style="line-height:150%">
	<span style="color:red">ThreadsPerChild</span></div>
<div style="line-height:150%">
	<span style="font-family:宋体;">是</span>worker<span style="font-family:宋体;">模式中与性能相关最密切的指令。这个指令设置了每个子进程建立的线程数。子进程在启动时建立这些线程后就不再建立新的线程了。</span></div>
<div style="line-height:150%">
	&nbsp;</div>
<div style="line-height:150%;">
	<b><span style="font-size:12.0pt;line-height:<br />
150%;font-family:宋体;">资源</span></b></div>
<div style="line-height:150%">
	prefork<span style="font-family:宋体;">文档：</span><a href="http://lamp.linux.gov.cn/Apache/ApacheMenu/mod/prefork.html">http://lamp.linux.gov.cn/Apache/ApacheMenu/mod/prefork.html</a></div>
<div style="line-height:150%">
	workder<span style="font-family:宋体;">文档：</span><a href="http://lamp.linux.gov.cn/Apache/ApacheMenu/mod/worker.html">http://lamp.linux.gov.cn/Apache/ApacheMenu/mod/worker.html</a></div>
]]></content:encoded>
			<wfw:commentRss>http://www.shenmiguo.com/archives/2009/318_apache-mpm.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
