﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>BlogJava-maxchen's blog-随笔分类-MySQL</title><link>http://www.blogjava.net/kelly859/category/51917.html</link><description /><language>zh-cn</language><lastBuildDate>Thu, 08 Oct 2015 21:23:42 GMT</lastBuildDate><pubDate>Thu, 08 Oct 2015 21:23:42 GMT</pubDate><ttl>60</ttl><item><title>MySQL详解--日志类型</title><link>http://www.blogjava.net/kelly859/archive/2012/09/24/388453.html</link><dc:creator>maxchen</dc:creator><author>maxchen</author><pubDate>Mon, 24 Sep 2012 10:12:00 GMT</pubDate><guid>http://www.blogjava.net/kelly859/archive/2012/09/24/388453.html</guid><wfw:comment>http://www.blogjava.net/kelly859/comments/388453.html</wfw:comment><comments>http://www.blogjava.net/kelly859/archive/2012/09/24/388453.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/kelly859/comments/commentRss/388453.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/kelly859/services/trackbacks/388453.html</trackback:ping><description><![CDATA[原文：<a href="http://www.cnblogs.com/kevintian/articles/1139118.html">http://www.cnblogs.com/kevintian/articles/1139118.html</a>&nbsp;<br /><br /><p style="font-size: 13px; line-height: 19px; color: #333333; font-family: Verdana, Arial, sans-serif, 'Lucida Grande'; background-color: #d6d3d6; ">&nbsp;MySQL<span style="font-family: 宋体; ">除了有些表类型会用到<span style="color: red; ">事务日志</span><span style="color: black; ">外，还使用了</span></span><span style="color: black; ">7</span><span style="color: black; font-family: 宋体; ">种日志文件，这些日志文件都是可选项。</span></p><p style="font-size: 13px; line-height: 19px; color: #333333; font-family: Verdana, Arial, sans-serif, 'Lucida Grande'; background-color: #d6d3d6; ">&nbsp;</p><div style="color: #333333; font-family: Verdana, Arial, sans-serif, 'Lucida Grande'; font-size: 13px; line-height: 23px; background-color: #d6d3d6; border-width: medium medium 1pt; border-style: none none solid; padding: 0cm 0cm 1pt; border-bottom-color: windowtext; "><p style="line-height: 19px; border: medium none; padding: 0cm; "><strong><span style="font-size: 14pt; color: black; ">1.&nbsp;</span></strong><strong><span style="font-size: 14pt; color: black; font-family: 宋体; ">二进制日志</span></strong><strong></strong></p></div><p style="text-indent: 21pt; font-size: 13px; line-height: 19px; color: #333333; font-family: Verdana, Arial, sans-serif, 'Lucida Grande'; background-color: #d6d3d6; "><strong><span style="color: red; font-family: 宋体; ">二进制日志存储修改数据库中表数据的所有动作，包含了所有更新了数据或者已经潜在更新了数据的所有语句。</span></strong><span style="color: black; font-family: 宋体; ">潜在跟新了数据的</span><span style="color: black; ">SQL</span><span style="color: black; font-family: 宋体; ">语句例如：无法匹配行的</span><span style="color: black; ">DELETE</span><span style="color: black; font-family: 宋体; ">语句；设置列为当前值的</span><span style="color: black; ">UPDATE</span><span style="color: black; font-family: 宋体; ">语句。除此之外，该日志还存储了语句执行期间耗时的相关信息。二进制日志文件以一种更有效并且是</span><strong><span style="color: red; font-family: 宋体; ">事务安全</span></strong><span style="color: black; font-family: 宋体; ">的方式包含更新日志中可用的所有信息。</span><span style="color: black; ">MySQL</span><span style="color: black; font-family: 宋体; ">在执行语句之后，但在释放锁之前，马上将修改写入二进制日志中，</span></p><p style="font-size: 13px; line-height: 19px; color: #333333; font-family: Verdana, Arial, sans-serif, 'Lucida Grande'; background-color: #d6d3d6; "><span style="color: black; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: black; font-family: 宋体; ">使用</span><span style="color: black; ">--log-bin[=file_name]</span><span style="color: black; font-family: 宋体; ">选项启动该日志类型，</span><span style="color: black; ">mysqld</span><span style="color: black; font-family: 宋体; ">写入包含所有更新数据的</span><span style="color: black; ">SQL</span><span style="color: black; font-family: 宋体; ">命令的日志文件。如果未给出</span><span style="color: black; ">file_name</span><span style="color: black; font-family: 宋体; ">值，默认名为&#8220;</span><span style="color: black; ">HOSTNAME-bin.nnnnn</span><span style="color: black; font-family: 宋体; ">&#8221;；如果给出了文件名，但没有包含路径，则文件被写入数据目录。如果在日志名中提供了扩展名</span><span style="color: black; ">(</span><span style="color: black; font-family: 宋体; ">例如，</span><span style="color: black; ">--log-bin=file_name.extension)</span><span style="color: black; font-family: 宋体; ">，则扩展名被悄悄除掉并忽略。二进制日志文件名的</span><span style="color: black; ">.nnnn</span><span style="color: black; font-family: 宋体; ">表示，</span><span style="color: black; ">mysqld</span><span style="color: black; font-family: 宋体; ">在每个二进制日志名后面添加一个数字扩展名。每次启动服务器或刷新日志（</span><span style="color: black; ">flush logs</span><span style="color: black; font-family: 宋体; ">）时该数字增加</span><span style="color: black; ">1</span><span style="color: black; font-family: 宋体; ">。如果当前的日志大小达到设定的</span><span style="color: black; ">max_binlog_size</span><span style="color: black; font-family: 宋体; ">，还会自动创建新的二进制日志。如果在该文件的末尾正使用大的事务，二进制日志还有肯呢个会超过</span><span style="color: black; ">max_binlog_size</span><span style="color: black; font-family: 宋体; ">：事务全写入一个二进制日志中，绝对不要写入不同的二进制日志中。</span></p><p style="font-size: 13px; line-height: 19px; color: #333333; font-family: Verdana, Arial, sans-serif, 'Lucida Grande'; background-color: #d6d3d6; "><span style="color: black; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></p><p style="text-indent: 21pt; font-size: 13px; line-height: 19px; color: #333333; font-family: Verdana, Arial, sans-serif, 'Lucida Grande'; background-color: #d6d3d6; "><span style="color: black; ">--binlog-do-db=db_name</span></p><p style="text-indent: 21pt; font-size: 13px; line-height: 19px; color: #333333; font-family: Verdana, Arial, sans-serif, 'Lucida Grande'; background-color: #d6d3d6; "><span style="color: black; font-family: 宋体; ">告诉主服务器，如果当前的数据库</span><span style="color: black; ">(</span><span style="color: black; font-family: 宋体; ">即</span><span style="color: black; ">USE</span><span style="color: black; font-family: 宋体; ">选定的数据库</span><span style="color: black; ">)</span><span style="color: black; font-family: 宋体; ">是</span><span style="color: black; ">db_name</span><span style="color: black; font-family: 宋体; ">，应将更新记录到二进制日志中。其它所有没有明显指定的数据库被忽略。</span></p><p style="text-indent: 21pt; font-size: 13px; line-height: 19px; color: #333333; font-family: Verdana, Arial, sans-serif, 'Lucida Grande'; background-color: #d6d3d6; "><strong><span style="color: black; font-family: 宋体; ">如果数据库启动时使用选项</span><span style="color: black; ">--binlog-do-db=DB_A</span></strong><strong><span style="color: black; font-family: 宋体; ">，使用语句&#8220;</span><span style="color: black; ">use DB_B</span></strong><strong><span style="color: black; font-family: 宋体; ">&#8221;置</span><span style="color: black; ">DB_B</span></strong><strong><span style="color: black; font-family: 宋体; ">为当前数据库，此时使用</span><span style="color: black; ">update</span></strong><strong><span style="color: black; font-family: 宋体; ">语句修改</span><span style="color: black; ">DB_A</span></strong><strong><span style="color: black; font-family: 宋体; ">的表数据时出现如下情况：</span></strong></p><p style="text-indent: 21pt; font-size: 13px; line-height: 19px; color: #333333; font-family: Verdana, Arial, sans-serif, 'Lucida Grande'; background-color: #d6d3d6; "><strong><span style="color: black; font-family: 宋体; ">数据库</span><span style="color: black; ">DB_B</span></strong><strong><span style="color: black; font-family: 宋体; ">不在允许</span><span style="color: black; ">binlog</span></strong><strong><span style="color: black; font-family: 宋体; ">的列表内，该语句不写入二进制日志文件</span></strong></p><p style="text-indent: 21pt; font-size: 13px; line-height: 19px; color: #333333; font-family: Verdana, Arial, sans-serif, 'Lucida Grande'; background-color: #d6d3d6; "><strong><span style="color: black; font-family: 宋体; ">数据库</span><span style="color: black; ">DB_B</span></strong><strong><span style="color: black; font-family: 宋体; ">在允许</span><span style="color: black; ">binlog</span></strong><strong><span style="color: black; font-family: 宋体; ">的列表内，该语句写入二进制日志文件</span></strong></p><p style="text-indent: 21pt; font-size: 13px; line-height: 19px; color: #333333; font-family: Verdana, Arial, sans-serif, 'Lucida Grande'; background-color: #d6d3d6; ">&nbsp;</p><p style="text-indent: 21pt; font-size: 13px; line-height: 19px; color: #333333; font-family: Verdana, Arial, sans-serif, 'Lucida Grande'; background-color: #d6d3d6; "><span style="color: black; ">--binlog-ignore-db=db_name</span></p><p style="text-indent: 21pt; font-size: 13px; line-height: 19px; color: #333333; font-family: Verdana, Arial, sans-serif, 'Lucida Grande'; background-color: #d6d3d6; "><span style="color: black; font-family: 宋体; ">告诉主服务器，如果当前的数据库</span><span style="color: black; ">(</span><span style="color: black; font-family: 宋体; ">即</span><span style="color: black; ">USE</span><span style="color: black; font-family: 宋体; ">选定的数据库</span><span style="color: black; ">)</span><span style="color: black; font-family: 宋体; ">是</span><span style="color: black; ">db_name</span><span style="color: black; font-family: 宋体; ">，不将更新保存到二进制日志中。</span></p><p style="text-indent: 21pt; font-size: 13px; line-height: 19px; color: #333333; font-family: Verdana, Arial, sans-serif, 'Lucida Grande'; background-color: #d6d3d6; "><strong><span style="color: black; font-family: 宋体; ">如果数据库启动时使用选项</span><span style="color: black; ">--binlog-ignore-db=DB_A</span></strong><strong><span style="color: black; font-family: 宋体; ">，使用语句&#8220;</span><span style="color: black; ">use DB_B</span></strong><strong><span style="color: black; font-family: 宋体; ">&#8221;置</span><span style="color: black; ">DB_B</span></strong><strong><span style="color: black; font-family: 宋体; ">为当前数据库，此时使用</span><span style="color: black; ">update</span></strong><strong><span style="color: black; font-family: 宋体; ">语句修改</span><span style="color: black; ">DB_A</span></strong><strong><span style="color: black; font-family: 宋体; ">的表数据时出现如下情况：</span></strong></p><p style="text-indent: 21pt; font-size: 13px; line-height: 19px; color: #333333; font-family: Verdana, Arial, sans-serif, 'Lucida Grande'; background-color: #d6d3d6; "><strong><span style="color: black; font-family: 宋体; ">数据库</span><span style="color: black; ">DB_B</span></strong><strong><span style="color: black; font-family: 宋体; ">不在允许</span><span style="color: black; ">binlog</span></strong><strong><span style="color: black; font-family: 宋体; ">的列表内，该语句不写入二进制日志文件</span></strong></p><p style="text-indent: 21pt; font-size: 13px; line-height: 19px; color: #333333; font-family: Verdana, Arial, sans-serif, 'Lucida Grande'; background-color: #d6d3d6; "><strong><span style="color: black; font-family: 宋体; ">数据库</span><span style="color: black; ">DB_B</span></strong><strong><span style="color: black; font-family: 宋体; ">在允许</span><span style="color: black; ">binlog</span></strong><strong><span style="color: black; font-family: 宋体; ">的列表内，该语句写入二进制日志文件</span></strong></p><p style="font-size: 13px; line-height: 19px; color: #333333; font-family: Verdana, Arial, sans-serif, 'Lucida Grande'; background-color: #d6d3d6; "><span style="color: black; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></p><p style="font-size: 13px; line-height: 19px; color: #333333; font-family: Verdana, Arial, sans-serif, 'Lucida Grande'; background-color: #d6d3d6; "><span style="color: black; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span><span style="color: black; font-family: 宋体; ">综上所述，使用这个两个选项时决定是否将该语句写入日志文件还有参考当前数据库的属性，如果指定了这两个选项尽量使指定的数据库为当前数据库，才能按照逻辑来记录日志。但</span><span style="color: black; ">CREATE DATABASE</span><span style="color: black; font-family: 宋体; ">、</span><span style="color: black; ">ALTER DATABASE</span><span style="color: black; font-family: 宋体; ">和</span><span style="color: black; ">DROP DATABASE</span><span style="color: black; font-family: 宋体; ">等语句，有一个例外，即通过操作的数据库来决定是否应记录语句。</span></p><p style="font-size: 13px; line-height: 19px; color: #333333; font-family: Verdana, Arial, sans-serif, 'Lucida Grande'; background-color: #d6d3d6; ">&nbsp;</p><div style="color: #333333; font-family: Verdana, Arial, sans-serif, 'Lucida Grande'; font-size: 13px; line-height: 23px; background-color: #d6d3d6; border-width: medium medium 1pt; border-style: none none solid; padding: 0cm 0cm 1pt; border-bottom-color: windowtext; "><p style="line-height: 19px; border: medium none; padding: 0cm; "><strong><span style="font-size: 14pt; ">2.&nbsp;</span></strong><strong><span style="font-size: 14pt; font-family: 宋体; ">调试日志</span></strong><strong></strong></p></div><p align="left" style="text-indent: 21pt; font-size: 13px; line-height: 19px; color: #333333; font-family: Verdana, Arial, sans-serif, 'Lucida Grande'; background-color: #d6d3d6; "><span style="font-family: 宋体; ">如果使用调试的方式来编译</span>MySQL<span style="font-family: 宋体; ">客户机或服务器，则可以生成一个调试日志文件。默认情况下，</span>MySQL<span style="font-family: 宋体; ">将调试日志写到</span>/tmp/mysql.trace<span style="font-family: 宋体; ">，也可以使用</span>debug<span style="font-family: 宋体; ">命令行选项来修改该位置。</span></p><p style="margin-left: 21pt; font-size: 13px; line-height: 19px; color: #333333; font-family: Verdana, Arial, sans-serif, 'Lucida Grande'; background-color: #d6d3d6; ">&nbsp;</p><div style="color: #333333; font-family: Verdana, Arial, sans-serif, 'Lucida Grande'; font-size: 13px; line-height: 23px; background-color: #d6d3d6; border-width: medium medium 1pt; border-style: none none solid; padding: 0cm 0cm 1pt; border-bottom-color: windowtext; "><p style="margin-left: 18pt; text-indent: -18pt; line-height: 19px; border: medium none; padding: 0cm; "><strong><span style="font-size: 14pt; color: black; ">3.<span style="font-weight: normal; font-size: 7pt; line-height: normal; font-family: 'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span></strong><strong><span style="font-size: 14pt; color: black; font-family: 宋体; ">错误日志</span></strong><strong></strong></p></div><p style="text-indent: 18pt; font-size: 13px; line-height: 19px; color: #333333; font-family: Verdana, Arial, sans-serif, 'Lucida Grande'; background-color: #d6d3d6; "><strong><span style="color: red; font-family: 宋体; ">该日志文件包含了当</span><span style="color: red; ">mysqld</span></strong><strong><span style="color: red; font-family: 宋体; ">启动和停止时，以及服务器在运行过程中发生任何严重错误时的相关信息。</span></strong><span style="color: black; font-family: 宋体; ">可以用</span><span style="color: black; ">--log-error[=file_name]</span><span style="color: black; font-family: 宋体; ">选项来指定</span><span style="color: black; ">mysqld</span><span style="color: black; font-family: 宋体; ">保存错误日志文件的位置。</span></p><p style="text-indent: 18pt; font-size: 13px; line-height: 19px; color: #333333; font-family: Verdana, Arial, sans-serif, 'Lucida Grande'; background-color: #d6d3d6; "><span style="color: black; font-family: 宋体; ">当使用</span><span style="color: black; ">mysqld_safe</span><span style="color: black; font-family: 宋体; ">启动服务器时，该脚本自动在启动项上加上</span><span style="color: black; ">--log-error</span><span style="color: black; font-family: 宋体; ">但没有加上</span><span style="color: black; ">file_name</span><span style="color: black; font-family: 宋体; ">，或者直接在</span><span style="color: black; ">libexec</span><span style="color: black; font-family: 宋体; ">目录下使用</span><span style="color: black; ">./mysqld --user=mysql&nbsp;&nbsp;--log-error</span><span style="color: black; font-family: 宋体; ">启动服务器，此时没有给定</span><span style="color: black; ">file_name</span><span style="color: black; font-family: 宋体; ">值，</span><span style="color: black; ">mysqld</span><span style="color: black; font-family: 宋体; ">将使用错误日志名</span><span style="color: black; ">host_name.err&nbsp;</span><span style="color: black; font-family: 宋体; ">并在数据目录中写入日志文件。</span></p><p style="text-indent: 18pt; font-size: 13px; line-height: 19px; color: #333333; font-family: Verdana, Arial, sans-serif, 'Lucida Grande'; background-color: #d6d3d6; "><span style="color: black; font-family: 宋体; ">将错误信息写入错误日志文件的原理是，服务器将对标准错误输出重定向到该日志文件，所以如果不指定</span><span style="color: black; ">--log-error</span><span style="color: black; font-family: 宋体; ">，错误被写入标准错误输出</span><span style="color: black; ">stderr</span><span style="color: black; font-family: 宋体; ">，通常标准输出为你的终端。如果在程序中有</span><span style="color: black; ">printf</span><span style="color: black; font-family: 宋体; ">等语句的话，这些函数打印出的信息也被写入该日志文件。</span></p><p style="text-indent: 18pt; font-size: 13px; line-height: 19px; color: #333333; font-family: Verdana, Arial, sans-serif, 'Lucida Grande'; background-color: #d6d3d6; "><span style="color: black; font-family: 宋体; ">如果执行</span><span style="color: black; ">FLUSH LOGS</span><span style="color: black; font-family: 宋体; ">，错误日志用</span><span style="color: black; ">-old</span><span style="color: black; font-family: 宋体; ">重新命名后缀并且</span><span style="color: black; ">mysqld</span><span style="color: black; font-family: 宋体; ">创建一个新的空日志文件。如第一次生成的错误日志为：</span><span style="color: black; ">linux-8tpn.err</span><span style="color: black; font-family: 宋体; ">。执行该命令后将该文件重命名为：</span><span style="color: black; ">linux-8tpn.err-old</span><span style="color: black; font-family: 宋体; ">。</span></p><p style="font-size: 13px; line-height: 19px; color: #333333; font-family: Verdana, Arial, sans-serif, 'Lucida Grande'; background-color: #d6d3d6; ">&nbsp;</p><div style="color: #333333; font-family: Verdana, Arial, sans-serif, 'Lucida Grande'; font-size: 13px; line-height: 23px; background-color: #d6d3d6; border-width: medium medium 1pt; border-style: none none solid; padding: 0cm 0cm 1pt; border-bottom-color: windowtext; "><p style="margin-left: 18pt; text-indent: -18pt; line-height: 19px; border: medium none; padding: 0cm; "><strong><span style="font-size: 14pt; color: black; ">4.<span style="font-weight: normal; font-size: 7pt; line-height: normal; font-family: 'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span></strong><strong><span style="font-size: 14pt; color: black; ">MyISAM</span></strong><strong><span style="font-size: 14pt; color: black; font-family: 宋体; ">日志</span></strong><strong></strong></p></div><p style="text-indent: 18pt; font-size: 13px; line-height: 19px; color: #333333; font-family: Verdana, Arial, sans-serif, 'Lucida Grande'; background-color: #d6d3d6; "><strong><span style="color: red; font-family: 宋体; ">该日志文件供</span><span style="color: red; ">MySQL</span></strong><strong><span style="color: red; font-family: 宋体; ">开发小组使用该日志来调试</span><span style="color: red; ">MyISAM</span></strong><strong><span style="color: red; font-family: 宋体; ">表处理器。</span></strong><span style="font-family: 宋体; ">使用</span>--log-isam<span style="font-family: 宋体; ">选项开启该日志类型，服务器在数据目录下创建</span>myisam.log<span style="font-family: 宋体; ">文件。</span></p><p style="text-indent: 18pt; font-size: 13px; line-height: 19px; color: #333333; font-family: Verdana, Arial, sans-serif, 'Lucida Grande'; background-color: #d6d3d6; "><span style="font-family: 宋体; ">可以使用</span>myisamlog<span style="font-family: 宋体; ">使用程序从</span>myisam.log<span style="font-family: 宋体; ">文件中提取统计信息，除非用户正在调试</span>MyISAM<span style="font-family: 宋体; ">表处理器，否则对该日志可能不感兴趣。</span></p><p style="text-indent: 18pt; font-size: 13px; line-height: 19px; color: #333333; font-family: Verdana, Arial, sans-serif, 'Lucida Grande'; background-color: #d6d3d6; "><span style="font-family: 宋体; ">下面为使用</span>myisamlog<span style="font-family: 宋体; ">的输出实例，暂不清楚各项是什么意思。</span></p><table cellspacing="0" cellpadding="0" border="0" style="margin: 0px auto; border-style: solid; border-color: #c0c0c0; border-collapse: collapse; color: #333333; font-family: Verdana, Arial, sans-serif, 'Lucida Grande'; font-size: 13px; line-height: 23px; text-align: left; background-color: #e6e6e6; "><tbody><tr><td valign="top" width="657" style="font-size: 10pt; border-style: solid; border-color: #c0c0c0; border-collapse: collapse; padding: 0cm 5.4pt; word-break: normal !important; width: 492.7pt; "><p style="line-height: 19px; ">linux-8tpn:/home/mysql/var # myisamlog myisam.log</p><p style="line-height: 19px; ">Commands&nbsp;&nbsp;&nbsp;Used count&nbsp;&nbsp;&nbsp;&nbsp;Errors&nbsp;&nbsp;&nbsp;Recover errors</p><p style="line-height: 19px; ">open&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;12&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0</p><p style="line-height: 19px; ">close&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;6&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0</p><p style="line-height: 19px; ">extra&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;53&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0</p><p style="line-height: 19px; ">Total&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;71&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;0</p></td></tr></tbody></table><div style="color: #333333; font-family: Verdana, Arial, sans-serif, 'Lucida Grande'; font-size: 13px; line-height: 23px; background-color: #d6d3d6; border-width: medium medium 1pt; border-style: none none solid; padding: 0cm 0cm 1pt; border-bottom-color: windowtext; "><p style="line-height: 19px; border: medium none; padding: 0cm; "><strong>&nbsp;</strong></p><p style="margin-left: 18pt; text-indent: -18pt; line-height: 19px; border: medium none; padding: 0cm; "><strong><span style="font-size: 14pt; color: black; ">5.<span style="font-weight: normal; font-size: 7pt; line-height: normal; font-family: 'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span></strong><strong><span style="font-size: 14pt; color: black; font-family: 宋体; ">查询日志</span></strong><strong></strong></p></div><p style="text-indent: 18pt; font-size: 13px; line-height: 19px; color: #333333; font-family: Verdana, Arial, sans-serif, 'Lucida Grande'; background-color: #d6d3d6; "><strong><span style="color: red; font-family: 宋体; ">该日志文件记录服务器上所做的所有查询。</span></strong><span style="color: black; font-family: 宋体; ">可以使用</span><span style="color: black; ">--log[=file_name]</span><span style="color: black; font-family: 宋体; ">或</span><span style="color: black; ">-l [file_name]</span><span style="color: black; font-family: 宋体; ">选项启动它。如果没有给定</span><span style="color: black; ">file_name</span><span style="color: black; font-family: 宋体; ">的值，</span>&nbsp;<span style="color: black; font-family: 宋体; ">默认名是</span><span style="color: black; ">host_name.log</span><span style="color: black; font-family: 宋体; ">；如果</span><span style="color: black; ">file_name</span><span style="color: black; font-family: 宋体; ">为绝对路径则在该目录下创建日志文件，否则在数据目录下创建该日志文件。</span></p><p style="text-indent: 18pt; font-size: 13px; line-height: 19px; color: #333333; font-family: Verdana, Arial, sans-serif, 'Lucida Grande'; background-color: #d6d3d6; "><span style="color: black; ">mysqld</span><span style="color: black; font-family: 宋体; ">按照它接收的顺序而不是按照语句执行的顺序记录语句到查询日志。这就有可能与执行的顺序不同。与更新日志和二进制日志不同，它们在查询执行后，但是任何一个锁释放之前记录日志。</span><span style="color: black; ">(</span><span style="color: black; font-family: 宋体; ">查询日志还包含所有语句，而二进制日志不包含只查询数据的语句）。</span></p><p style="text-indent: 18pt; font-size: 13px; line-height: 19px; color: #333333; font-family: Verdana, Arial, sans-serif, 'Lucida Grande'; background-color: #d6d3d6; "><span style="color: black; font-family: 宋体; ">服务器重新启动和日志刷新不会产生新的一般查询日志文件</span><span style="color: black; ">(</span><span style="color: black; font-family: 宋体; ">尽管刷新关闭并重新打开一般查询日志文件</span><span style="color: black; ">)</span><span style="color: black; font-family: 宋体; ">。在所有日志类型中查询日志增长的最快，不要不间断的运行查询日志。</span></p><table cellspacing="0" cellpadding="0" border="0" style="margin: 0px auto; border-style: solid; border-color: #c0c0c0; border-collapse: collapse; color: #333333; font-family: Verdana, Arial, sans-serif, 'Lucida Grande'; font-size: 13px; line-height: 23px; text-align: left; background-color: #e6e6e6; "><tbody><tr><td valign="top" width="657" style="font-size: 10pt; border-style: solid; border-color: #c0c0c0; border-collapse: collapse; padding: 0cm 5.4pt; word-break: normal !important; width: 492.7pt; "><p style="line-height: 19px; "><span style="color: black; ">./mysqld, Version: 5.0.41-debug-log (Source distribution). started with:</span></p><p style="line-height: 19px; "><span style="color: black; ">Tcp port: 3306&nbsp;&nbsp;Unix socket: /tmp/mysql.sock</span></p><p style="line-height: 19px; "><span style="color: black; ">Time&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Id Command&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Argument</span></p><p style="line-height: 19px; "><span style="color: black; ">080406&nbsp;&nbsp;2:05:52&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1 Connect&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;root@localhost on mysql</span></p><p style="line-height: 19px; "><span style="color: black; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1 Query&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;select * from user</span></p><p style="line-height: 19px; "><span style="color: black; ">080406&nbsp;&nbsp;2:21:09&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1 Query&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;desc user</span></p><p style="line-height: 19px; "><span style="color: black; ">080406&nbsp;&nbsp;2:21:43&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1 Query&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;select * from user a, user b where a.Host =&nbsp;&nbsp;b.User</span></p></td></tr></tbody></table><p style="font-size: 13px; line-height: 19px; color: #333333; font-family: Verdana, Arial, sans-serif, 'Lucida Grande'; background-color: #d6d3d6; ">&nbsp;</p><div style="color: #333333; font-family: Verdana, Arial, sans-serif, 'Lucida Grande'; font-size: 13px; line-height: 23px; background-color: #d6d3d6; border-width: medium medium 1pt; border-style: none none solid; padding: 0cm 0cm 1pt; border-bottom-color: windowtext; "><p style="margin-left: 18pt; text-indent: -18pt; line-height: 19px; border: medium none; padding: 0cm; "><strong><span style="font-size: 14pt; color: black; ">6.<span style="font-weight: normal; font-size: 7pt; line-height: normal; font-family: 'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span></strong><strong><span style="font-size: 14pt; color: black; font-family: 宋体; ">慢查询日志</span></strong><strong></strong></p></div><p style="text-indent: 18pt; font-size: 13px; line-height: 19px; color: #333333; font-family: Verdana, Arial, sans-serif, 'Lucida Grande'; background-color: #d6d3d6; "><span style="color: black; font-family: 宋体; ">该日志类型用来收集那些花费太长时间（超过指定时间）执行的</span><span style="color: black; ">SQL</span><span style="color: black; font-family: 宋体; ">语句，该指定时间由</span><span style="color: black; ">long_query_time</span><span style="color: black; font-family: 宋体; ">服务器变量设定。用</span><span style="color: black; ">--log-slow-queries[=file_name]</span><span style="color: black; font-family: 宋体; ">选项启动，如果没有给出</span><span style="color: black; ">file_name</span><span style="color: black; font-family: 宋体; ">值，默认未主机名，后缀为</span><span style="color: black; ">-slow.log</span><span style="color: black; font-family: 宋体; ">，如果给出了文件名，但不是绝对路径名，文件则写入数据目录。</span></p><p style="text-indent: 18pt; font-size: 13px; line-height: 19px; color: #333333; font-family: Verdana, Arial, sans-serif, 'Lucida Grande'; background-color: #d6d3d6; "><span style="color: black; font-family: 宋体; ">慢查询日志可以用来找到执行时间长的查询，可以用于优化</span><span style="color: black; ">\</span><span style="color: black; font-family: 宋体; ">，使用</span><span style="color: black; ">mysqldumpslow</span><span style="color: black; font-family: 宋体; ">命令获得日志中显示的查询摘要来处理慢查询日志。</span></p><p style="text-indent: 18pt; font-size: 13px; line-height: 19px; color: #333333; font-family: Verdana, Arial, sans-serif, 'Lucida Grande'; background-color: #d6d3d6; "><span style="color: black; font-family: 宋体; ">在</span><span style="color: black; ">MySQL 5.1</span><span style="color: black; font-family: 宋体; ">中</span><span style="color: black; ">,</span><span style="color: black; font-family: 宋体; ">通过</span><span style="color: black; ">--log-slow-admin-statements</span><span style="color: black; font-family: 宋体; ">服务器选项，可以请求将慢管理语句，例如</span><span style="color: black; ">OPTIMIZE TABLE</span><span style="color: black; font-family: 宋体; ">、</span><span style="color: black; ">ANALYZE TABLE</span><span style="color: black; font-family: 宋体; ">和</span><span style="color: black; ">&nbsp;ALTER TABLE</span><span style="color: black; font-family: 宋体; ">写入慢查询日志。</span></p><p style="text-indent: 18pt; font-size: 13px; line-height: 19px; color: #333333; font-family: Verdana, Arial, sans-serif, 'Lucida Grande'; background-color: #d6d3d6; "><span style="color: black; font-family: 宋体; ">在</span><span style="color: black; ">MySQL 5.1</span><span style="color: black; font-family: 宋体; ">的慢查询日志中，不使用索引的慢查询同使用索引的查询一样记录。要想防止不使用索引的慢查询记入慢查询日志，使用</span><span style="color: black; ">--log-short-format</span><span style="color: black; font-family: 宋体; ">选项。</span></p><p style="text-indent: 18pt; font-size: 13px; line-height: 19px; color: #333333; font-family: Verdana, Arial, sans-serif, 'Lucida Grande'; background-color: #d6d3d6; "><span style="color: black; font-family: 宋体; ">使用</span><span style="color: black; ">--log-long-format</span><span style="color: black; font-family: 宋体; ">选项，可以把不使用索引的查询也加入到慢查询日志中。</span></p><p style="font-size: 13px; line-height: 19px; color: #333333; font-family: Verdana, Arial, sans-serif, 'Lucida Grande'; background-color: #d6d3d6; "><span style="color: black; font-family: 宋体; ">注：</span></p><p style="font-size: 13px; line-height: 19px; color: #333333; font-family: Verdana, Arial, sans-serif, 'Lucida Grande'; background-color: #d6d3d6; "><span style="color: black; ">[1]&nbsp;</span><span style="color: black; font-family: 宋体; ">获得初使表锁定的时间不算作执行时间。</span></p><p style="font-size: 13px; line-height: 19px; color: #333333; font-family: Verdana, Arial, sans-serif, 'Lucida Grande'; background-color: #d6d3d6; "><span style="color: black; ">[2]&nbsp;</span><span style="color: black; font-family: 宋体; ">语句执行完并且所有锁释放后记入慢查询日志。记录顺序可以与执行顺序不相同</span></p><p style="font-size: 13px; line-height: 19px; color: #333333; font-family: Verdana, Arial, sans-serif, 'Lucida Grande'; background-color: #d6d3d6; "><span style="color: black; ">[3]&nbsp;</span><span style="color: black; font-family: 宋体; ">用查询缓存处理的查询不加到慢查询日志中，因为表有零行或一行而不能从索引中受益的查询也不写入慢查询日志</span></p><p style="font-size: 13px; line-height: 19px; color: #333333; font-family: Verdana, Arial, sans-serif, 'Lucida Grande'; background-color: #d6d3d6; ">&nbsp;</p><div style="color: #333333; font-family: Verdana, Arial, sans-serif, 'Lucida Grande'; font-size: 13px; line-height: 23px; background-color: #d6d3d6; border-width: medium medium 1pt; border-style: none none solid; padding: 0cm 0cm 1pt; border-bottom-color: windowtext; "><p style="margin-left: 18pt; text-indent: -18pt; line-height: 19px; border: medium none; padding: 0cm; "><strong><span style="font-size: 14pt; color: black; ">7.<span style="font-weight: normal; font-size: 7pt; line-height: normal; font-family: 'Times New Roman'; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span></strong><strong><span style="font-size: 14pt; color: black; font-family: 宋体; ">更新日志</span></strong><strong></strong></p></div><p style="text-indent: 21pt; font-size: 13px; line-height: 19px; color: #333333; font-family: Verdana, Arial, sans-serif, 'Lucida Grande'; background-color: #d6d3d6; "><span style="font-family: 宋体; ">更新日志提供查询信息，但只有修改数据库内容的查询。使用</span>--log-update<span style="font-family: 宋体; ">服务器选项，开启更新日志。当启用该日志类型后，</span>MySQL<span style="font-family: 宋体; ">将在数据目录下创建一个名称为：</span>HOSTNAME.nnn<span style="font-family: 宋体; ">的文件。但在</span>5.0<span style="font-family: 宋体; ">以上的</span>MySQL<span style="font-family: 宋体; ">上使用该选项的时候，会有如下的提示：</span></p><table cellspacing="0" cellpadding="0" border="0" style="margin: 0px auto; border-style: solid; border-color: #c0c0c0; border-collapse: collapse; color: #333333; font-family: Verdana, Arial, sans-serif, 'Lucida Grande'; font-size: 13px; line-height: 23px; text-align: left; background-color: #e6e6e6; "><tbody><tr><td valign="top" width="657" style="font-size: 10pt; border-style: solid; border-color: #c0c0c0; border-collapse: collapse; padding: 0cm 5.4pt; word-break: normal !important; width: 492.7pt; "><p style="line-height: 19px; ">080306 13:56:59 [ERROR] The update log is no longer supported by MySQL in version 5.0 and above. It is replaced by the binary log</p></td></tr></tbody></table><p style="font-size: 13px; line-height: 19px; color: #333333; font-family: Verdana, Arial, sans-serif, 'Lucida Grande'; background-color: #d6d3d6; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="font-family: 宋体; ">也就是说在</span>MySQL V5.0<span style="font-family: 宋体; ">以上，系统已经不在支持该日志类型，取而代之的是二进制日志。</span></p><img src ="http://www.blogjava.net/kelly859/aggbug/388453.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/kelly859/" target="_blank">maxchen</a> 2012-09-24 18:12 <a href="http://www.blogjava.net/kelly859/archive/2012/09/24/388453.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>MySQL主从复制建立</title><link>http://www.blogjava.net/kelly859/archive/2012/09/24/388451.html</link><dc:creator>maxchen</dc:creator><author>maxchen</author><pubDate>Mon, 24 Sep 2012 09:55:00 GMT</pubDate><guid>http://www.blogjava.net/kelly859/archive/2012/09/24/388451.html</guid><wfw:comment>http://www.blogjava.net/kelly859/comments/388451.html</wfw:comment><comments>http://www.blogjava.net/kelly859/archive/2012/09/24/388451.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/kelly859/comments/commentRss/388451.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/kelly859/services/trackbacks/388451.html</trackback:ping><description><![CDATA[<div></div><div>GRANT REPLICATION SLAVE ON *.* TO 'repl'@'%' IDENTIFIED BY 'repl';</div><div>FLUSH TABLES WITH READ LOCK;</div><div>tar -cvf /tmp/mysql-snapshot.tar ./this_db</div><div>SHOW MASTER STATUS;</div><div>UNLOCK TABLES;<br /><br /></div><div></div><div>tar -xvf /tmp/mysql-snapshot.tar</div><div>CHANGE MASTER TO MASTER_HOST='192.168.56.128',MASTER_PORT=3306,MASTER_USER='repl', MASTER_PASSWORD='repl', MASTER_LOG_FILE='mysql-bin.000001', MASTER_LOG_POS=13514175;</div><div>start slave;<br /><br /><a href="http://dev.mysql.com/doc/refman/5.1/zh/replication.html"><br />http://dev.mysql.com/doc/refman/5.1/zh/replication.html</a>&nbsp;<br /><p style="margin: 0px 0px 10px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; background-color: #ffffff; line-height: 25px; font-family: Helvetica, Arial, sans-serif; max-width: 720px; "><span style="margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; background-color: transparent; ">&#183;<span style="margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; background-color: transparent; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</span></span>如果某个在主服务器上成功的语句拒绝在从服务器上运行，并且不能执行完全的数据库重新同步<span style="margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; background-color: transparent; ">(</span>即删除从服务器的数据库并从主服务器复制新的快照<span style="margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; background-color: transparent; ">)</span>，尝试：</p><p style="margin: 0px 0px 10px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; background-color: #ffffff; line-height: 25px; font-family: Helvetica, Arial, sans-serif; max-width: 720px; "><span style="margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; background-color: transparent; ">1.<span style="margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; background-color: transparent; ">&nbsp;&nbsp;&nbsp;&nbsp;</span></span>确定是否从服务器的表与主服务器的不同。尽力了解发生的原因。然后让从服务器的表与主服务器的一样并运行<span style="margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; background-color: transparent; ">START SLAVE</span>。</p><p style="margin: 0px 0px 10px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; background-color: #ffffff; line-height: 25px; font-family: Helvetica, Arial, sans-serif; max-width: 720px; "><span style="margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; background-color: transparent; ">2.<span style="margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; background-color: transparent; ">&nbsp;&nbsp;&nbsp;&nbsp;</span></span>如果前面的步骤不工作或不适合，尽力了解手动更新是否安全<span style="margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; background-color: transparent; ">(</span>如果需要<span style="margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; background-color: transparent; ">)</span>，然后忽视来自主服务器的下一个语句。</p><p style="margin: 0px 0px 10px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; background-color: #ffffff; line-height: 25px; font-family: Helvetica, Arial, sans-serif; max-width: 720px; "><span style="margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; background-color: transparent; ">3.<span style="margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; background-color: transparent; ">&nbsp;&nbsp;&nbsp;&nbsp;</span></span>如果你确定可以跳过来自主服务器的下一个语句，执行下面的语句：</p><pre style="margin-top: 0px; margin-bottom: 0px; padding: 0px; border: 0px; outline: 0px; font-size: 13px; vertical-align: baseline; background-color: white; color: #a1520f; font-family: 'Courier New', Courier, fixed, monospace; line-height: 25px; "><span style="margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; background-color: transparent; ">4.<span style="margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; background-color: transparent; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>mysql&gt; </span><span style="margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; background-color: transparent; "><strong style="margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; background-color: transparent; "><span style="margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; background-color: transparent; ">SET GLOBAL SQL_slave_SKIP_COUNTER = <em style="margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; background-color: transparent; ">n</em></span><span style="margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; background-color: transparent; ">；</span></strong></span></pre><pre style="margin-top: 0px; margin-bottom: 0px; padding: 0px; border: 0px; outline: 0px; font-size: 13px; vertical-align: baseline; background-color: white; color: #a1520f; font-family: 'Courier New', Courier, fixed, monospace; line-height: 25px; "><span style="margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; background-color: transparent; ">5.<span style="margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; background-color: transparent; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </span>mysql&gt; </span><span style="margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; background-color: transparent; "><strong style="margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; background-color: transparent; "><span style="margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; background-color: transparent; ">START SLAVE</span><span style="margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; background-color: transparent; ">；</span></strong></span></pre><p style="margin: 0px 0px 10px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; background-color: #ffffff; line-height: 25px; font-family: Helvetica, Arial, sans-serif; max-width: 720px; ">如果来自主服务器的下一个语句不使用<span style="margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; background-color: transparent; ">AUTO_INCREMENT</span>或<span style="margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; background-color: transparent; ">LAST_INSERT_ID()</span>，<span style="margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; background-color: transparent; "><em style="margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; background-color: transparent; ">n</em></span>&nbsp;值应为<span style="margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; background-color: transparent; ">1</span>。否则，值应为<span style="margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; background-color: transparent; ">2</span>。使用<span style="margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; background-color: transparent; ">AUTO_INCREMENT</span>或<span style="margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; background-color: transparent; ">LAST_INSERT_ID()</span>的语句使用值<span style="margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; background-color: transparent; ">2</span>的原因是它们从主服务器的二进制日志中取两个事件。</p><p style="margin: 0px 0px 10px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; background-color: #ffffff; line-height: 25px; font-family: Helvetica, Arial, sans-serif; max-width: 720px; "><span style="margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; background-color: transparent; ">6.<span style="margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; background-color: transparent; ">&nbsp;&nbsp;&nbsp;&nbsp;</span></span>如果你确保从服务器启动时完好地与主服务器同步，并且没有更新从服务器线程之外的表，则大概诧异是由于<span style="margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; background-color: transparent; ">bug</span>。如果你正运行最近的版本，请通报该问题。如果你正运行旧版本<span style="margin: 0px; padding: 0px; border: 0px; outline: 0px; vertical-align: baseline; background-color: transparent; ">MySQL</span>，尽力升级到最新的产品版本。</p></div><div></div><img src ="http://www.blogjava.net/kelly859/aggbug/388451.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/kelly859/" target="_blank">maxchen</a> 2012-09-24 17:55 <a href="http://www.blogjava.net/kelly859/archive/2012/09/24/388451.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Linux下安装启动多个Mysql</title><link>http://www.blogjava.net/kelly859/archive/2012/09/13/387637.html</link><dc:creator>maxchen</dc:creator><author>maxchen</author><pubDate>Thu, 13 Sep 2012 06:40:00 GMT</pubDate><guid>http://www.blogjava.net/kelly859/archive/2012/09/13/387637.html</guid><wfw:comment>http://www.blogjava.net/kelly859/comments/387637.html</wfw:comment><comments>http://www.blogjava.net/kelly859/archive/2012/09/13/387637.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/kelly859/comments/commentRss/387637.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/kelly859/services/trackbacks/387637.html</trackback:ping><description><![CDATA[看到一篇不错的多mysql安装分享，转载一下<br />原文地址：<a href="http://www.linuxidc.com/Linux/2011-03/33426.htm">http://www.linuxidc.com/Linux/2011-03/33426.htm</a>&nbsp;<br /><a href="http://blog.csdn.net/swengineer/article/details/6239711"><br /></a><div><p style="color: #333333; font-family: 宋体, Arial; line-height: 19px; background-color: #efefef; "><span style="font-size: x-small; ">步骤如下：</span></p><p style="color: #333333; font-family: 宋体, Arial; line-height: 19px; background-color: #efefef; "><span style="font-size: x-small; ">一、编译安装两个mysql，步骤如下</span></p><p style="color: #333333; font-family: 宋体, Arial; line-height: 19px; background-color: #efefef; "><span style="font-size: x-small; ">下载Mysql&nbsp;，此处以<a href="http://download.softagency.net/MySQL/Downloads/MySQL-6.0/mysql-6.0.11-alpha.tar.gz" style="color: blue; ">Mysql-6.0.11-alpha.tar.gz</a>&nbsp;为例</span></p><p style="color: #333333; font-family: 宋体, Arial; line-height: 19px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: 宋体, Arial; line-height: 19px; background-color: #efefef; "><span style="font-size: x-small; ">安装第一个数据库(主数据库)</span></p><p style="color: #333333; font-family: 宋体, Arial; line-height: 19px; background-color: #efefef; "><span style="font-size: x-small; ">(<span style="color: #ff0000; ">红色</span>部分为默认数据库文件路径，可改成其他如：data、var等)</span></p><p style="color: #333333; font-family: 宋体, Arial; line-height: 19px; background-color: #efefef; "><span style="font-size: x-small; ">tar zxvf mysql-6.0.11-alpha.tar.gz</span></p><p style="color: #333333; font-family: 宋体, Arial; line-height: 19px; background-color: #efefef; "><span style="font-size: x-small; ">cd mysql-6.0.11-alpha</span></p><p style="color: #333333; font-family: 宋体, Arial; line-height: 19px; background-color: #efefef; "><span style="font-size: x-small; ">./configure --prefix=/usr/local/mysql --sysconfdir=/usr/local/mysql/etc --with-tcp-port=3306 --localstatedir=/usr/local/mysql/<span style="color: red; ">localstate&nbsp;--with-unix-socket-path=/tmp/mysql3306.sock --with-charset=utf8 --with-collation=utf8_general_ci --with-extra-charsets=gbk,gb2312,binary --enable-thread-safe-client --with-plugins=innobase --with-mysqld-user=mysql --with-charset=utf8&nbsp;&nbsp;--with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static</span></span></p><p style="color: #333333; font-family: 宋体, Arial; line-height: 19px; background-color: #efefef; "><span style="font-size: x-small; ">make &amp;&amp; make install</span></p><p style="color: #333333; font-family: 宋体, Arial; line-height: 19px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: 宋体, Arial; line-height: 19px; background-color: #efefef; "><span style="font-size: x-small; ">安装第二个数据库(从数据库)</span></p><p style="color: #333333; font-family: 宋体, Arial; line-height: 19px; background-color: #efefef; "><span style="font-size: x-small; ">tar zxvf mysql-6.0.11-alpha.tar.gz</span></p><p style="color: #333333; font-family: 宋体, Arial; line-height: 19px; background-color: #efefef; "><span style="font-size: x-small; ">cd mysql-6.0.11-alpha</span></p><p style="color: #333333; font-family: 宋体, Arial; line-height: 19px; background-color: #efefef; "><span style="font-size: x-small; ">./configure --prefix=/usr/local/mysql3307 --sysconfdir=/usr/local/mysql3307/etc --with-tcp-port=3307 --localstatedir=/usr/local/mysql3307/<span style="color: red; ">localstate&nbsp;--with-unix-socket-path=/tmp/mysql3307.sock --with-charset=utf8 --with-collation=utf8_general_ci --with-extra-charsets=gbk,gb2312,binary --enable-thread-safe-client --with-plugins=innobase --with-mysqld-user=mysql --with-charset=utf8&nbsp;&nbsp;--with-client-ldflags=-all-static --with-mysqld-ldflags=-all-static</span></span></p><p style="color: #333333; font-family: 宋体, Arial; line-height: 19px; background-color: #efefef; "><span style="font-size: x-small; ">make &amp;&amp; make install</span></p><p style="color: #333333; font-family: 宋体, Arial; line-height: 19px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: 宋体, Arial; line-height: 19px; background-color: #efefef; "><span style="font-size: x-small; ">如需支持所有字符集 修改为：--with-extra-charsets=<span style="color: #ff0000; ">all&nbsp;</span>即可</span></p><p style="color: #333333; font-family: 宋体, Arial; line-height: 19px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: 宋体, Arial; line-height: 19px; background-color: #efefef; "><span style="font-size: x-small; ">二、分别初始化数据库脚本（在编译目录执行下）</span></p><p style="color: #333333; font-family: 宋体, Arial; line-height: 19px; background-color: #efefef; "><span style="font-size: x-small; ">scripts/mysql_install_db --basedir=/usr/local/mysql/ --user=mysql</span></p><p style="color: #333333; font-family: 宋体, Arial; line-height: 19px; background-color: #efefef; "><span style="font-size: x-small; ">scripts/mysql_install_db --basedir=/usr/local/mysql3307/ --user=mysql</span></p><p style="color: #333333; font-family: 宋体, Arial; line-height: 19px; background-color: #efefef; "><span style="font-size: x-small; ">注：可用--datadir=PATH参数指定数据库文件路径，默认为编译时-- localstatedir</span></p><p style="color: #333333; font-family: 宋体, Arial; line-height: 19px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: 宋体, Arial; line-height: 19px; background-color: #efefef; "><span style="font-size: x-small; ">三、修改从库配置文件</span></p><p style="color: #333333; font-family: 宋体, Arial; line-height: 19px; background-color: #efefef; "><span style="font-size: x-small; ">拷贝配置文件：</span></p><p style="color: #333333; font-family: 宋体, Arial; line-height: 19px; background-color: #efefef; "><span style="font-size: x-small; ">cp /usr/local/software/mysql-6.0.11-alpha/support-files/my-medium.cnf /usr/local/mysql/etc/my.cnf</span></p><p style="color: #333333; font-family: 宋体, Arial; line-height: 19px; background-color: #efefef; "><span style="font-size: x-small; ">cp /usr/local/software/mysql-6.0.11-alpha/support-files/my-medium.cnf /usr/local/mysql3307/etc/my.cnf</span></p><p style="color: #333333; font-family: 宋体, Arial; line-height: 19px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: 宋体, Arial; line-height: 19px; background-color: #efefef; "><span style="font-size: x-small; ">四、修改各个数据库的my.cnf文件</span></p><p style="color: #333333; font-family: 宋体, Arial; line-height: 19px; background-color: #efefef; "><span style="font-size: x-small; ">主要内容如下：</span></p><p style="color: #333333; font-family: 宋体, Arial; line-height: 19px; background-color: #efefef; "><span style="font-size: x-small; ">添加InnoDB支持：</span></p><p style="color: #333333; font-family: 宋体, Arial; line-height: 19px; background-color: #efefef; "><span style="font-size: x-small; ">[client]</span></p><p style="color: #333333; font-family: 宋体, Arial; line-height: 19px; background-color: #efefef; "><span style="font-size: x-small; ">#password&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;= your_password</span></p><p style="color: #333333; font-family: 宋体, Arial; line-height: 19px; background-color: #efefef; "><span style="font-size: x-small; ">port&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;<span style="color: red; ">3307&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--</span><span style="color: red; ">数据库端口号</span></span></p><p style="color: #333333; font-family: 宋体, Arial; line-height: 19px; background-color: #efefef; "><span style="font-size: x-small; ">socket&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;<span style="color: red; ">/tmp/mysqls.sock&nbsp;&nbsp;&nbsp;&nbsp;--sock</span><span style="color: red; ">文件路径</span></span></p><p style="color: #333333; font-family: 宋体, Arial; line-height: 19px; background-color: #efefef; "><span style="font-size: x-small; ">default-character-set=utf8&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: red; ">--</span><span style="color: red; ">客户端UTF8连接</span></span></p><p style="color: #333333; font-family: 宋体, Arial; line-height: 19px; background-color: #efefef; "><span style="font-size: x-small; ">[mysqld]</span></p><p style="color: #333333; font-family: 宋体, Arial; line-height: 19px; background-color: #efefef; "><span style="font-size: x-small; ">port&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;<span style="color: red; ">3307&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--</span><span style="color: red; ">数据库端口号</span></span></p><p style="color: #333333; font-family: 宋体, Arial; line-height: 19px; background-color: #efefef; "><span style="font-size: x-small; ">socket&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;<span style="color: red; ">/tmp/mysqls.sock&nbsp;&nbsp;&nbsp;&nbsp;--sock</span><span style="color: red; ">文件路径</span></span></p><p style="color: #333333; font-family: 宋体, Arial; line-height: 19px; background-color: #efefef; "><span style="font-size: x-small; ">default-storage-engine=INNODB</span></p><p style="color: #333333; font-family: 宋体, Arial; line-height: 19px; background-color: #efefef; "><span style="font-size: x-small; ">default-character-set=UTF8&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: red; ">--</span><span style="color: red; ">默认字符集</span></span></p><p style="color: #333333; font-family: 宋体, Arial; line-height: 19px; background-color: #efefef; "><span style="font-size: x-small; ">init_connect='SET NAMES utf8'&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: red; ">--</span><span style="color: red; ">以UTF8连接</span></span></p><p style="color: #333333; font-family: 宋体, Arial; line-height: 19px; background-color: #efefef; "><span style="font-size: x-small; ">skip-name-resolve&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;<span style="color: red; ">--</span><span style="color: red; ">取消DNS反向解析</span></span></p><p style="color: #333333; font-family: 宋体, Arial; line-height: 19px; background-color: #efefef; "><span style="font-size: x-small; ">lower_case_table_names=1&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<span style="color: #ff0000; ">--</span><span style="color: red; ">不区分表名大小写</span></span></p><p style="color: #333333; font-family: 宋体, Arial; line-height: 19px; background-color: #efefef; ">&nbsp;</p><p style="color: #333333; font-family: 宋体, Arial; line-height: 19px; background-color: #efefef; "><span style="font-size: x-small; ">启动数据库（进入各自目录）</span></p><p style="color: #333333; font-family: 宋体, Arial; line-height: 19px; background-color: #efefef; "><span style="font-size: x-small; ">主：./mysqld_safe &amp;</span></p><p style="color: #333333; font-family: 宋体, Arial; line-height: 19px; background-color: #efefef; "><span style="font-size: x-small; ">从：./mysqld_safe &amp;</span></p><p style="color: #333333; font-family: 宋体, Arial; line-height: 19px; background-color: #efefef; ">配置开启自动：</p><p style="color: #333333; font-family: 宋体, Arial; line-height: 19px; background-color: #efefef; ">cp /usr/local/software/mysql-6.0.11-alpha/support-files/mysql.server /etc/init.d/mysql</p><p style="color: #333333; font-family: 宋体, Arial; line-height: 19px; background-color: #efefef; ">cp /usr/local/software/mysql-6.0.11-alpha/support-files/mysql.server /etc/init.d/mysql3307</p><p style="color: #333333; font-family: 宋体, Arial; line-height: 19px; background-color: #efefef; ">修改/etc/init.d/mysql3007中basedir与datadir为即可</p><p style="color: #333333; font-family: 宋体, Arial; line-height: 19px; background-color: #efefef; ">basedir=/usr/local/mysql3307<br />datadir=/usr/local/mysql3307/var</p><p style="color: #333333; font-family: 宋体, Arial; line-height: 19px; background-color: #efefef; "><span style="font-size: x-small; "><img alt="" src="http://www.linuxidc.com/upload/2011_03/110315083154282.gif" style="border: 0px; " /></span></p><p style="color: #333333; font-family: 宋体, Arial; line-height: 19px; background-color: #efefef; "><span style="font-size: x-small; "><img alt="" src="http://www.linuxidc.com/upload/2011_03/110315083154281.gif" style="border: 0px; " /></span></p><p style="color: #333333; font-family: 宋体, Arial; line-height: 19px; background-color: #efefef; "><span style="font-size: x-small; ">停止数据库</span></p><p style="color: #333333; font-family: 宋体, Arial; line-height: 19px; background-color: #efefef; "><span style="font-size: x-small; ">主：./mysqladmin shutdown</span></p><p style="color: #333333; font-family: 宋体, Arial; line-height: 19px; background-color: #efefef; "><span style="font-size: x-small; ">从：./mysqladmin shutdown</span></p><p style="color: #333333; font-family: 宋体, Arial; line-height: 19px; background-color: #efefef; "><span style="font-size: x-small; ">以上各项配置都可以自行修改，以满足业务需求。</span></p><p style="margin-bottom:0pt; margin-top:0pt; "></p></div><a href="http://blog.csdn.net/swengineer/article/details/6239711"></a><img src ="http://www.blogjava.net/kelly859/aggbug/387637.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/kelly859/" target="_blank">maxchen</a> 2012-09-13 14:40 <a href="http://www.blogjava.net/kelly859/archive/2012/09/13/387637.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>SuSe 安装多个 MySQL</title><link>http://www.blogjava.net/kelly859/archive/2012/09/05/387087.html</link><dc:creator>maxchen</dc:creator><author>maxchen</author><pubDate>Wed, 05 Sep 2012 06:05:00 GMT</pubDate><guid>http://www.blogjava.net/kelly859/archive/2012/09/05/387087.html</guid><wfw:comment>http://www.blogjava.net/kelly859/comments/387087.html</wfw:comment><comments>http://www.blogjava.net/kelly859/archive/2012/09/05/387087.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/kelly859/comments/commentRss/387087.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/kelly859/services/trackbacks/387087.html</trackback:ping><description><![CDATA[<p style="margin-bottom:0pt; margin-top:0pt; "><span style="color: #ff0000; font-weight: bold; font-size: 10.5pt; font-family: Verdana; "></span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="color: #ff0000; font-weight: bold; font-size: 10.5pt; font-family: Verdana; "></span></p><div><p style="margin-bottom:0pt; margin-top:0pt; "><span style="color: #ff0000; font-weight: bold; font-size: 10.5pt; font-family: Verdana; "></span></p><div><div><font color="#ff0000" face="Verdana"><strong>设置用户</strong></font><br /><div><strong>groupadd mysql</strong></div><div><strong>useradd -r -g mysql mysql</strong></div><div><strong>chown -R mysql.mysql /usr/local/mysql</strong></div><span style="color: #ff0000; font-family: Verdana; font-weight: bold;">安装cmake</span><br /><strong>1.wget http://www.cmake.org/files/v2.8/cmake-2.8.9.tar.gz<br /></strong><p style="margin-top: 0pt; margin-bottom: 0pt;"><span style="font-size: 10pt; font-family: Verdana;"><strong>2.tar&nbsp;zxvf&nbsp;cmake-2.8.9.tar.gz</strong></span></p><p style="margin-top: 0pt; margin-bottom: 0pt;"><span style="font-size: 10pt; font-family: Verdana;"><strong>3.cd&nbsp;cmake-2.8.9</strong></span></p><p style="margin-top: 0pt; margin-bottom: 0pt;"><span style="font-size: 10pt; font-family: Verdana;"><strong>4../configure</strong></span></p><p style="margin-top: 0pt; margin-bottom: 0pt;"><span style="font-size: 10pt; font-family: Verdana;"><strong>5.make&nbsp;&amp;&amp;&nbsp;make&nbsp;install</strong></span></p></div><p style="margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; line-height:15.7500pt; "><span style="color: #ff0000; font-weight: bold; font-size: 10.5pt; font-family: Verdana; ">安装mysql</span><span style="font-size: 10.5pt; font-family: Verdana; "><br /></span><span style="font-weight: bold; font-size: 10pt; font-family: Verdana; ">1.tar&nbsp;-zxvf&nbsp;mysql-5.5.27.tar.gz</span><span style="font-size: 10.5pt; font-family: Verdana; "><br /></span><span style="font-weight: bold; font-size: 10pt; font-family: Verdana; ">2.mkdir&nbsp;-p&nbsp;/usr/local/mysql/data</span><span style="font-size: 10.5pt; font-family: Verdana; "><br /></span><span style="font-weight: bold; font-size: 10pt; font-family: Verdana; ">3.cmake&nbsp;-DMYSQL_TCP_PORT=3306&nbsp;-DCMAKE_INSTALL_PREFIX=/usr/local/mysql&nbsp;-DMYSQL_DATADIR=/usr/local/mysql/data&nbsp;-DMYSQL_UNIX_ADDR=/tmp/mysql.sock&nbsp;</span><span style="color: #ff0000; font-weight: bold; font-size: 10pt; font-family: Verdana; ">-DDEFAULT_CHARSET=utf8&nbsp;-DDEFAULT_COLLATION=utf8_general_ci</span><span style="font-size: 10.5pt; font-family: Verdana; "><br /></span><span style="font-weight: bold; font-size: 10pt; font-family: Verdana; ">4.make</span><span style="font-weight: bold; font-size: 10pt; font-family: 宋体; ">&nbsp;&amp;&amp;&nbsp;make&nbsp;install</span></p><p style="margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; line-height:15.7500pt; "><span style="font-weight: bold; font-size: 10pt; font-family: 宋体; ">5.cd&nbsp;/usr/local/mysql</span></p><p style="margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; line-height:15.7500pt; "><span style="font-weight: bold; font-size: 10pt; font-family: Verdana; ">6../scripts/mysql_install_db&nbsp;--user=mysql&nbsp;--basedir=/usr/local/mysql&nbsp;--datadir=/usr/local/mysql/data</span><span style="font-size: 10.5pt; font-family: Verdana; "><br /></span><span style="font-weight: bold; font-size: 10pt; font-family: Verdana; ">7.cp&nbsp;./support-files/my-medium.cnf&nbsp;./etc/my.cnf&nbsp;</span></p><p style="margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; line-height:15.7500pt; ">&nbsp;&nbsp;<span style="color: #0000ff; font-size: 10pt; font-family: 宋体; ">mark:</span><span style="color: #0000ff; font-size: 10pt; font-family: Verdana; ">-DSYSCONFDIR</span>&nbsp;<span style="color: #0000ff; font-size: 10pt; font-family: Verdana; ">=/usr/local/mysql/etc&nbsp;mysql实例启动后的配置文件所在，默认是安装路径下的[PREFIX/etc]此处指定的目的是强调需为每个实例配置my.cnf，同时需要保证&nbsp;/etc/my.cnf不存在，因为启动脚本一般会先去读/etc/my.cnf</span>&nbsp;<span style="font-size: 10.5pt; font-family: Verdana; "><br /></span><span style="font-weight: bold; font-size: 10pt; font-family: Verdana; ">8../support-files/mysql.server&nbsp;start</span></p><p style="margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; line-height:15.7500pt; "><span style="color: #ff0000; font-weight: bold; font-size: 10.5pt; font-family: Verdana; ">安装mysql</span><span style="color: #ff0000; font-weight: bold; font-size: 10.5pt; font-family: 宋体; ">1</span><span style="font-size: 10.5pt; font-family: Verdana; "><br /></span><span style="font-weight: bold; font-size: 10pt; font-family: Verdana; ">1.tar&nbsp;-zxvf&nbsp;mysql-5.5.27.tar.gz</span><span style="font-size: 10.5pt; font-family: Verdana; "><br /></span><span style="font-weight: bold; font-size: 10pt; font-family: Verdana; ">2.mkdir&nbsp;-p&nbsp;/usr/local/mysql</span><span style="font-weight: bold; font-size: 10pt; font-family: 宋体; ">1</span><span style="font-weight: bold; font-size: 10pt; font-family: Verdana; ">/data</span><span style="font-size: 10.5pt; font-family: Verdana; "><br /></span><span style="font-weight: bold; font-size: 10pt; font-family: Verdana; ">3.cmake&nbsp;-DMYSQL_TCP_PORT=330</span><span style="font-weight: bold; font-size: 10pt; font-family: 宋体; ">7</span><span style="font-weight: bold; font-size: 10pt; font-family: Verdana; ">&nbsp;-DCMAKE_INSTALL_PREFIX=/usr/local/mysql</span><span style="font-weight: bold; font-size: 10pt; font-family: 宋体; ">1</span><span style="font-weight: bold; font-size: 10pt; font-family: Verdana; ">&nbsp;-DMYSQL_DATADIR=/usr/local/mysql</span><span style="font-weight: bold; font-size: 10pt; font-family: 宋体; ">1</span><span style="font-weight: bold; font-size: 10pt; font-family: Verdana; ">/data&nbsp;-DMYSQL_UNIX_ADDR=/tmp/mysql</span><span style="font-weight: bold; font-size: 10pt; font-family: 宋体; ">3307</span><span style="font-weight: bold; font-size: 10pt; font-family: Verdana; ">.sock&nbsp;</span>&nbsp;<span style="color: #ff0000; font-weight: bold; font-size: 9.5pt; font-family: Verdana; ">-DDEFAULT_CHARSET=utf8&nbsp;-DDEFAULT_COLLATION=utf8_general_ci</span>&nbsp;<span style="font-size: 10.5pt; font-family: Verdana; "><br /></span><span style="font-weight: bold; font-size: 10pt; font-family: Verdana; ">4.make</span><span style="font-weight: bold; font-size: 10pt; font-family: 宋体; ">&nbsp;&amp;&amp;&nbsp;make&nbsp;install</span></p><p style="margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; line-height:15.7500pt; "><span style="font-weight: bold; font-size: 10pt; font-family: 宋体; ">5.cd&nbsp;/usr/local/mysql1</span></p><p style="margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; line-height:15.7500pt; "><span style="font-weight: bold; font-size: 10pt; font-family: Verdana; ">6../scripts/mysql_install_db&nbsp;--user=mysql&nbsp;--basedir=/usr/local/mysql</span><span style="font-weight: bold; font-size: 10pt; font-family: 宋体; ">1</span><span style="font-weight: bold; font-size: 10pt; font-family: Verdana; ">&nbsp;--datadir=/usr/local/mysql</span><span style="font-weight: bold; font-size: 10pt; font-family: 宋体; ">1</span><span style="font-weight: bold; font-size: 10pt; font-family: Verdana; ">/data</span><span style="font-size: 10.5pt; font-family: Verdana; "><br /></span><span style="font-weight: bold; font-size: 10pt; font-family: Verdana; ">7.cp&nbsp;./support-files/my-medium.cnf&nbsp;</span><span style="font-weight: bold; font-size: 9.5pt; font-family: Verdana; ">./etc/my.cnf</span>&nbsp;</p><p style="margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; line-height:15.7500pt; "><span style="font-size: 10.5pt; font-family: Verdana; ">&nbsp;&nbsp;&nbsp;</span><span style="color: #0000ff; font-size: 10pt; font-family: Verdana; ">&nbsp;[client]</span></p><p style="margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; line-height:15.7500pt; "><span style="color: #0000ff; font-size: 10pt; font-family: Verdana; ">&nbsp;&nbsp;&nbsp;&nbsp;port&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;3307 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;--数据库端口号</span></p><p style="margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; line-height:15.7500pt; "><span style="color: #0000ff; font-size: 10pt; font-family: Verdana; ">&nbsp;&nbsp;&nbsp;&nbsp;socket&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;/tmp/mysql3307.sock&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--sock文件路径</span></p><p style="margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; line-height:15.7500pt; "><span style="color: #0000ff; font-size: 10pt; font-family: Verdana; ">&nbsp;&nbsp;&nbsp;&nbsp;[mysqld]</span></p><p style="margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; line-height:15.7500pt; "><span style="color: #0000ff; font-size: 10pt; font-family: Verdana; ">&nbsp;&nbsp;&nbsp;&nbsp;port&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;3307 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;--数据库端口号</span></p><p style="margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; line-height:15.7500pt; "><span style="color: #0000ff; font-size: 10pt; font-family: Verdana; ">&nbsp;&nbsp;&nbsp;&nbsp;socket&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;/tmp/mysql3307.sock&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--sock文件路径</span><span style="color: #0000ff; font-size: 10pt; font-family: Verdana; "><br /></span><span style="font-weight: bold; font-size: 10pt; font-family: Verdana; ">8../support-files/mysql.server&nbsp;start</span></p><p style="margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; line-height:15.7500pt; "><span style="color: #ff0000; font-weight: bold; font-size: 10.5pt; font-family: Verdana; ">安装mysql</span><span style="color: #ff0000; font-weight: bold; font-size: 10.5pt; font-family: 宋体; ">2</span><span style="font-size: 10.5pt; font-family: Verdana; "><br /></span><span style="font-weight: bold; font-size: 10pt; font-family: Verdana; ">1.tar&nbsp;-zxvf&nbsp;mysql-5.5.27.tar.gz</span><span style="font-size: 10.5pt; font-family: Verdana; "><br /></span><span style="font-weight: bold; font-size: 10pt; font-family: Verdana; ">2.mkdir&nbsp;-p&nbsp;/usr/local/mysql</span><span style="font-weight: bold; font-size: 10pt; font-family: 宋体; ">2</span><span style="font-weight: bold; font-size: 10pt; font-family: Verdana; ">/data</span><span style="font-size: 10.5pt; font-family: Verdana; "><br /></span><span style="font-weight: bold; font-size: 10pt; font-family: Verdana; ">3.cmake&nbsp;-DMYSQL_TCP_PORT=330</span><span style="font-weight: bold; font-size: 10pt; font-family: 宋体; ">8</span><span style="font-weight: bold; font-size: 10pt; font-family: Verdana; ">&nbsp;-DCMAKE_INSTALL_PREFIX=/usr/local/mysql</span><span style="font-weight: bold; font-size: 10pt; font-family: 宋体; ">2</span><span style="font-weight: bold; font-size: 10pt; font-family: Verdana; ">&nbsp;-DMYSQL_DATADIR=/usr/local/mysql</span><span style="font-weight: bold; font-size: 10pt; font-family: 宋体; ">2</span><span style="font-weight: bold; font-size: 10pt; font-family: Verdana; ">/data&nbsp;-DMYSQL_UNIX_ADDR=/tmp/mysql</span><span style="font-weight: bold; font-size: 10pt; font-family: 宋体; ">3308</span><span style="font-weight: bold; font-size: 10pt; font-family: Verdana; ">.sock&nbsp;</span>&nbsp;<span style="color: #ff0000; font-weight: bold; font-size: 9.5pt; font-family: Verdana; ">-DDEFAULT_CHARSET=utf8&nbsp;-DDEFAULT_COLLATION=utf8_general_ci</span>&nbsp;<span style="font-size: 10.5pt; font-family: Verdana; "><br /></span><span style="font-weight: bold; font-size: 10pt; font-family: Verdana; ">4.make</span><span style="font-weight: bold; font-size: 10pt; font-family: 宋体; ">&nbsp;&amp;&amp;&nbsp;make&nbsp;install</span></p><p style="margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; line-height:15.7500pt; "><span style="font-weight: bold; font-size: 10pt; font-family: 宋体; ">5.cd&nbsp;/usr/local/mysql2</span></p><p style="margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; line-height:15.7500pt; "><span style="font-weight: bold; font-size: 10pt; font-family: Verdana; ">6../scripts/mysql_install_db&nbsp;--user=mysql&nbsp;--basedir=/usr/local/mysql</span><span style="font-weight: bold; font-size: 10pt; font-family: 宋体; ">2</span><span style="font-weight: bold; font-size: 10pt; font-family: Verdana; ">&nbsp;--datadir=/usr/local/mysql</span><span style="font-weight: bold; font-size: 10pt; font-family: 宋体; ">2</span><span style="font-weight: bold; font-size: 10pt; font-family: Verdana; ">/data</span><span style="font-size: 10.5pt; font-family: Verdana; "><br /></span><span style="font-weight: bold; font-size: 10pt; font-family: Verdana; ">7.cp&nbsp;./support-files/my-medium.cnf&nbsp;</span><span style="font-weight: bold; font-size: 9.5pt; font-family: Verdana; ">./etc/my.cnf</span></p><p style="margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; line-height:15.7500pt; "><span style="color: #0000ff; font-size: 10pt; font-family: Verdana; ">&nbsp;&nbsp;&nbsp;&nbsp;[client]</span></p><p style="margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; line-height:15.7500pt; "><span style="color: #0000ff; font-size: 10pt; font-family: Verdana; ">&nbsp;&nbsp;&nbsp;&nbsp;port&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;3308 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;--数据库端口号</span></p><p style="margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; line-height:15.7500pt; "><span style="color: #0000ff; font-size: 10pt; font-family: Verdana; ">&nbsp;&nbsp;&nbsp;&nbsp;socket&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;/tmp/mysql3308.sock&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--sock文件路径</span></p><p style="margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; line-height:15.7500pt; "><span style="color: #0000ff; font-size: 10pt; font-family: Verdana; ">&nbsp;&nbsp;&nbsp;&nbsp;[mysqld]</span></p><p style="margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; line-height:15.7500pt; "><span style="color: #0000ff; font-size: 10pt; font-family: Verdana; ">&nbsp;&nbsp;&nbsp;&nbsp;port&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;3308 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;--数据库端口号</span></p><p style="margin-bottom:0pt; margin-top:0pt; text-autospace:ideograph-other; line-height:15.7500pt; "><span style="color: #0000ff; font-size: 10pt; font-family: Verdana; ">&nbsp;&nbsp;&nbsp;&nbsp;socket&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=&nbsp;/tmp/mysql3308.sock&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--sock文件路径</span><span style="font-size: 10.5pt; font-family: Verdana; "><br /></span><span style="font-weight: bold; font-size: 10pt; font-family: Verdana; ">8../support-files/mysql.server&nbsp;start</span><span style="font-size: 10.5pt; font-family: Verdana; "><br /></span><span style="font-size: 10.5pt; font-family: Verdana; "><br /></span><span style="font-weight: bold; font-size: 10pt; font-family: Verdana; ">打完收工。</span></p><p style="margin-bottom:0pt; margin-top:0pt; "></p></div><p style="margin-bottom: 0pt; margin-top: 0pt; "><font face="Verdana" size="2"><strong><br /></strong></font><br /></p><div>UPDATE mysql.user SET password=PASSWORD("123456") WHERE user='root';<br /><div>FLUSH PRIVILEGES;</div></div><div>GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'broadengate' WITH GRANT OPTION;</div><p>&nbsp;</p><div><strong></strong></div><div>mysql&gt; SHOW VARIABLES LIKE 'character_set_%';&nbsp;</div><div>+--------------------------+----------------------------------+</div><div>| Variable_name &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;| Value &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;|</div><div>+--------------------------+----------------------------------+</div><div>| character_set_client &nbsp; &nbsp; | utf8 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; |</div><div>| character_set_connection | utf8 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; |</div><div>| character_set_database &nbsp; | utf8 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; |</div><div>| character_set_filesystem | binary &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; |</div><div>| character_set_results &nbsp; &nbsp;| utf8 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; |</div><div>| character_set_server &nbsp; &nbsp; | utf8 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; |</div><div>| character_set_system &nbsp; &nbsp; | utf8 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; |</div><div>| character_sets_dir &nbsp; &nbsp; &nbsp; | /usr/local/mysql/share/charsets/ |</div><div>+--------------------------+----------------------------------+</div><div>8 rows in set (0.00 sec)</div><div></div><div>mysql&gt; SHOW VARIABLES LIKE 'collation_%';&nbsp;</div><div>+----------------------+-----------------+</div><div>| Variable_name &nbsp; &nbsp; &nbsp; &nbsp;| Value &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; |</div><div>+----------------------+-----------------+</div><div>| collation_connection | utf8_general_ci |</div><div>| collation_database &nbsp; | utf8_general_ci |</div><div>| collation_server &nbsp; &nbsp; | utf8_general_ci |</div><div>+----------------------+-----------------+</div><div>3 rows in set (0.00 sec)</div><div><strong></strong></div><br /><br /><p>&nbsp;</p><p style="margin-bottom:0pt; margin-top:0pt; "></p><p style="margin-bottom:0pt; margin-top:0pt; "></p><p style="margin-bottom:0pt; margin-top:0pt; "></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-weight: bold; font-size: 10pt; font-family: 宋体; ">参考了一下两篇文章：</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-weight: bold; font-size: 10pt; font-family: 宋体; ">1.</span><a href="http://xin23.blog.51cto.com/1827266/457370"><span style="color: #0000ff; font-weight: bold; font-size: 10.5pt; font-family: 'Times New Roman'; ">http://xin23.blog.51cto.com/1827266/457370</span></a>&nbsp;</p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: 宋体; ">安装的时候需要将套接字文件,监听端口,数据目录区分.我是采用源码编译安装的方式</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: 宋体; ">第一台MYSQL服务器</span></p><p style="margin-bottom:0pt; margin-top:0pt; ">&nbsp;</p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: 宋体; ">./configure&nbsp;\</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: 宋体; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--with-tcp-port=3307&nbsp;\</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: 宋体; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--prefix=/mysql1&nbsp;\</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: 宋体; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--localstatedir=/mysql1/data&nbsp;\</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: 宋体; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--with-unix-socket-path=/mysql1/mysql.sock&nbsp;\</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: 宋体; ">第二台MYSQL服务器</span></p><p style="margin-bottom:0pt; margin-top:0pt; ">&nbsp;</p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: 宋体; ">./configure&nbsp;\</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: 宋体; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--with-tcp-port=3308&nbsp;\</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: 宋体; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--prefix=/mysql2&nbsp;\</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: 宋体; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--localstatedir=/mysql2/data&nbsp;\</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: 宋体; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;--with-unix-socket-path=/mysql2/mysql.sock&nbsp;\</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: 宋体; ">可以看见我将安装路径，监听端口，数据目录和套接字文件都分开了.这样就一目了然了.</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: 宋体; ">启动MYSQL服务器指定参数</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: 宋体; ">mysqld_safe&nbsp;--user=mysql&nbsp;--socket=file_name&nbsp;--port=port_number</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: 宋体; ">需要其他参数的请自行加上</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: 宋体; ">也可以使用mysqld_multi方式.请参照</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><a href="http://xin23.blog.51cto.com/1827266/491336"><span style="color: #0000ff; font-size: 10pt; font-family: 宋体; ">http://xin23.blog.51cto.com/1827266/491336<br /><br /></span></a></p><p style="margin-bottom:0pt; margin-top:0pt; "></p><p style="margin-bottom:0pt; margin-top:0pt; "></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-weight: bold; font-size: 10pt; font-family: 宋体; ">2.</span><a href="http://down.51cto.com/data/489283"><span style="color: #0000ff; font-weight: bold; font-size: 10.5pt; font-family: 'Times New Roman'; ">http://down.51cto.com/data/489283</span></a>&nbsp;</p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">Redhat&nbsp;Linux&nbsp;6.2(x64)下编译安装MySQL-5.5.27</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">软件源码包存放位置&nbsp;/usr/local</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">源码包编译安装位置&nbsp;/usr/local/mysql</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">现在的MySQL都使用Cmake进行编译安装，所以在安装MySQL之前我们首先要把Cmake装在我们的系统上。</span></p><p style="margin-bottom:0pt; margin-top:0pt; "></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">我们所需要的软件源码包有以下：</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">cmake-2.8.9.tar.gz</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">mysql-5.5.27.tar.gz</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">1、安装Cmake</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">#安装所需依赖关系</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">yum&nbsp;-y&nbsp;install&nbsp;ntp&nbsp;vim-enhanced&nbsp;gcc&nbsp;gcc-c++&nbsp;flex&nbsp;bison&nbsp;autoconf&nbsp;automake&nbsp;bzip2-devel&nbsp;ncurses-devel&nbsp;zlib-devel&nbsp;libjpeg-devel&nbsp;libpng-devel&nbsp;libtiff-devel&nbsp;freetype-devel&nbsp;libXpm-devel&nbsp;gettext-devel&nbsp;&nbsp;pam-devel&nbsp;libtool&nbsp;libtool-ltdl&nbsp;openssl&nbsp;openssl-devel&nbsp;fontconfig-devel&nbsp;libxml2-devel&nbsp;curl-devel&nbsp;&nbsp;libicu&nbsp;libicu-devel&nbsp;libmcrypt&nbsp;libmcrypt-devel&nbsp;libmhash&nbsp;libmhash-devel</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">#下载Cmake的源码包</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">#编译安装</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">tar&nbsp;zxvf&nbsp;cmake-2.8.9.tar.gz</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">cd&nbsp;cmake-2.8.9</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">./configure</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">make&nbsp;&amp;&amp;&nbsp;make&nbsp;install</span></p><p style="margin-bottom:0pt; margin-top:0pt; "></p><p style="margin-bottom:0pt; margin-top:0pt; "></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">2、编译安装配置MySQL</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">#创建所需目录</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">mkdir&nbsp;-pv&nbsp;/usr/local/mysql/data</span></p><p style="margin-bottom:0pt; margin-top:0pt; "></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">#创建mysql用户和mysql组</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">groupadd&nbsp;mysql</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">useradd&nbsp;-g&nbsp;mysql&nbsp;-s&nbsp;/usr/sbin/nologin&nbsp;mysql</span></p><p style="margin-bottom:0pt; margin-top:0pt; "></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">#解压源码包</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">mysql-5.5.27.tar.gz</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">cd&nbsp;mysql-5.5.27</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">#cmake编译</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">cmake&nbsp;-DCMAKE_INSTALL_PREFIX=/usr/local/mysql&nbsp;-DMYSQL_DATADIR=/usr/local/mysql/data&nbsp;-DDEFAULT_CHARSET=utf8&nbsp;-DDEFAULT_COLLATION=utf8_unicode_ci&nbsp;-DWITH_READLINE=1&nbsp;-DWITH_SSL=system&nbsp;-DWITH_EMBEDDED_SERVER=1&nbsp;-DENABLED_LOCAL_INFILE=1&nbsp;-DDEFAULT_COLLATION=utf8_general_ci&nbsp;-DWITH_MYISAM_STORAGE_ENGINE=1&nbsp;-DWITH_INNOBASE_STORAGE_ENGINE=1&nbsp;-DWITH_DEBUG=0</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">#安装</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">make&nbsp;&amp;&amp;&nbsp;make&nbsp;install</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">#复制配置文件</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">cp&nbsp;support-files/my-medium.cnf&nbsp;/etc/my.cnf</span></p><p style="margin-bottom:0pt; margin-top:0pt; "></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">#设置权限</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">chmod&nbsp;+x&nbsp;/usr/local/mysql</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">chown&nbsp;-R&nbsp;mysql:mysql&nbsp;/usr/local/mysql</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">chown&nbsp;-R&nbsp;mysql:mysql&nbsp;/usr/local/mysql/data</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">#配置开机自动启动</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">cp&nbsp;support-files/mysql.server&nbsp;/etc/init.d/mysqld</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">chmod&nbsp;+x&nbsp;/etc/init.d/mysqld</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">chkconfig&nbsp;--add&nbsp;mysqld</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">chkconfig&nbsp;mysqld&nbsp;on</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">#修改配置文件</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">vim&nbsp;/etc/my.cnf</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">#在[mysqld]中添加：</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">datadir&nbsp;=&nbsp;/usr/local/mysql/data</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">log-error&nbsp;=&nbsp;/usr/local/mysql/data/error.log</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">pid-file&nbsp;=&nbsp;/usr/local/mysql/data/mysql.pid</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">user&nbsp;=&nbsp;mysql</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">tmpdir&nbsp;=&nbsp;/tmp</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">#保存退出</span></p><p style="margin-bottom:0pt; margin-top:0pt; "></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">#初始化数据库</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">/usr/local/mysql/scripts/mysql_install_db&nbsp;--user=mysql&nbsp;--basedir=/usr/local/mysql&nbsp;--datadir=/usr/local/mysql/data</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">#手动启动MySQL</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">service&nbsp;mysqld&nbsp;start</span></p><p style="margin-bottom:0pt; margin-top:0pt; "></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">#测试MySQL是否启动</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">#查看是否有mysql进程</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">ps&nbsp;-ef&nbsp;|&nbsp;grep&nbsp;mysql</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">#查看是否有mysql端口</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">netstat&nbsp;-tnlp&nbsp;|&nbsp;grep&nbsp;3306</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">ln&nbsp;-sv&nbsp;/usr/local/mysql/bin/mysql&nbsp;mysql</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">ln&nbsp;-sv&nbsp;/usr/local/mysql/bin/mysqladmin&nbsp;mysqladmin</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">ln&nbsp;-sv&nbsp;/usr/local/mysql/bin/mysqldump&nbsp;mysqldump</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">或者编辑/etc/profile在最后添加&nbsp;&nbsp;&nbsp;&nbsp;#如果添加软连接还是找不到命令，就写到环境变量中。</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">PATH=$PATH:/usr/local/mysql/bin</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">#重读/etc/profile文件</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">source&nbsp;/etc/profile</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">#读取MySQL的版本信息</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">mysqladmin&nbsp;version</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">#测试登录mysql</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">mysql&nbsp;-u&nbsp;root&nbsp;-p</span><span style="font-size: 10pt; font-family: Verdana; ">	</span><span style="font-size: 10pt; font-family: Verdana; ">	</span><span style="font-size: 10pt; font-family: Verdana; ">	</span><span style="font-size: 10pt; font-family: Verdana; ">	</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">mysql&gt;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;#可以登录，mysql编译安装成功</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10pt; font-family: Verdana; ">到此MySQL编译安装完成</span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-size: 10.5pt; font-family: 'Times New Roman'; "><br /></span></p></div><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-weight: bold; font-size: 10pt; font-family: Verdana; "></span></p><p style="margin-bottom:0pt; margin-top:0pt; "><span style="font-weight: bold; font-size: 10pt; font-family: Verdana; "></span></p><img src ="http://www.blogjava.net/kelly859/aggbug/387087.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/kelly859/" target="_blank">maxchen</a> 2012-09-05 14:05 <a href="http://www.blogjava.net/kelly859/archive/2012/09/05/387087.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>MySQL CMake参数说明手册</title><link>http://www.blogjava.net/kelly859/archive/2012/09/04/387005.html</link><dc:creator>maxchen</dc:creator><author>maxchen</author><pubDate>Tue, 04 Sep 2012 12:31:00 GMT</pubDate><guid>http://www.blogjava.net/kelly859/archive/2012/09/04/387005.html</guid><wfw:comment>http://www.blogjava.net/kelly859/comments/387005.html</wfw:comment><comments>http://www.blogjava.net/kelly859/archive/2012/09/04/387005.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/kelly859/comments/commentRss/387005.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/kelly859/services/trackbacks/387005.html</trackback:ping><description><![CDATA[<div style="margin: 0px; line-height: 25px; color: #333333; font-family: Verdana, Arial, Tahoma; background-color: #ffffff; "><p style="padding: 0px; margin: 1em 0px 0.5em; text-indent: 2em; ">MySQL自5.5版本以后，就开始使用CMake编译工具了，因此，你在安装源文件中找不到configure文件是正常的。很多人下到了新版的MySQL，因为找不到configure文件，不知道该怎么继续下去。有没有一篇可供参考的文章呢？其实在<a href="http://forge.mysql.com/" target="_blank" style="padding: 0px; margin: 0px; color: #256eb1; text-decoration: none; ">http://forge.mysql.com</a>网站上有一篇文章，专门介绍了如何用CMake工具进行新版MySQL的编译安装。</p><p style="padding: 0px; margin: 1em 0px 0.5em; text-indent: 2em; ">原文地址为：<a target="_blank" href="http://forge.mysql.com/wiki/Autotools_to_CMake_Transition_Guide" style="padding: 0px; margin: 0px; color: #256eb1; text-decoration: none; ">http://forge.mysql.com/wiki/Autotools_to_CMake_Transition_Guide</a>。</p><div style="padding: 5px; margin: 0px; background-color: #f7f8ff; border: 1px solid #bbbbaa; width: 300px; "><a href="http://www.sunchis.com/html/db/mysql/2012/0612/419.html#Introduction" style="padding: 0px; margin: 0px; color: #256eb1; text-decoration: none; ">1、介绍</a><br style="padding: 0px; margin: 0px; " /><a href="http://www.sunchis.com/html/db/mysql/2012/0612/419.html#Command_Invocation_Syntax" style="padding: 0px; margin: 0px; color: #256eb1; text-decoration: none; ">2、命令调用语法</a><br style="padding: 0px; margin: 0px; " /><a href="http://www.sunchis.com/html/db/mysql/2012/0612/419.html#Installation_Layout_Options" style="padding: 0px; margin: 0px; color: #256eb1; text-decoration: none; ">3、安装参数选项</a><br style="padding: 0px; margin: 0px; " /><a href="http://www.sunchis.com/html/db/mysql/2012/0612/419.html#Storage_Engine_Options" style="padding: 0px; margin: 0px; color: #256eb1; text-decoration: none; ">4、存储引擎选项</a><br style="padding: 0px; margin: 0px; " /><a href="http://www.sunchis.com/html/db/mysql/2012/0612/419.html#Library_Options" style="padding: 0px; margin: 0px; color: #256eb1; text-decoration: none; ">5、库文件加载选项</a><br style="padding: 0px; margin: 0px; " /><a href="http://www.sunchis.com/html/db/mysql/2012/0612/419.html#Miscellaneous_Options" style="padding: 0px; margin: 0px; color: #256eb1; text-decoration: none; ">6、其他选项</a></div><h4><a name="Introduction" style="padding: 0px; margin: 0px; color: #256eb1; "><span style="padding: 0px; margin: 0px; color: #006486; ">介绍</span></a></h4><p style="padding: 0px; margin: 1em 0px 0.5em; text-indent: 2em; ">本页将介绍常用编译工具的一些配置选项和这些配置选项在CMake中又是如何进行配置的，然后介绍如何使用CMake工具来构建编译MySQL。</p><h4><a name="Command_Invocation_Syntax" style="padding: 0px; margin: 0px; color: #256eb1; "><span style="padding: 0px; margin: 0px; color: #006486; ">命令调用语法</span></a></h4><p style="padding: 0px; margin: 1em 0px 0.5em; text-indent: 2em; ">下表列出了常用编译工具的调用语法和等效的CMake命令。&#8220;.&#8221;表示你当前的工作目录路径，请根据你所在的目录，适当的替换掉路径&#8220;.&#8221;。</p><table width="360px" border="1" style="padding: 0px; margin: 0px 0px 0px 2em; border-spacing: 0px; border-collapse: collapse; font-size: 13px; "><tbody style="padding: 0px; margin: 0px; height: 20px; "><tr style="padding: 0px; margin: 0px; "><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; text-align: center; ">configure命令</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; text-align: center; ">CMake命令</td></tr><tr style="padding: 0px; margin: 0px; "><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">./configure</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">cmake .</td></tr><tr style="padding: 0px; margin: 0px; "><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">./configure --help</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">cmake . -LH or ccmake .</td></tr></tbody></table><p style="padding: 0px; margin: 1em 0px 0.5em; text-indent: 2em; ">在重新配置或重新构建之前，需要先清除旧的对象文件和缓存信息，方法如下：</p><p style="padding: 0px; margin: 1em 0px 0.5em; text-indent: 2em; ">Autotools：</p><pre style="padding: 0px; margin-top: 0px; font-family: 'Courier New', monospace; font-size: 12px; width: 712px; overflow: auto; background-color: #f7f7f7; "><div id="codeCtrl_1" style="padding-left: 10px; margin: 0px 0px 0px 3em !important; border-left-width: 3px; border-left-style: solid; border-left-color: #146b00; color: #999999; "><a href="http://www.sunchis.com/html/db/mysql/2012/0612/419.html" id="view_1" style="padding: 0px; margin: 0px; color: #999999; text-decoration: none; background-image: none; border: none; background-position: initial initial; background-repeat: initial initial; ">view plain</a>&nbsp;&nbsp;&nbsp;<span id="clipinner" style="padding: 0px; margin: 0px; position: relative; width: 100px; "><a href="http://www.sunchis.com/html/db/mysql/2012/0612/419.html#" style="padding: 0px; margin: 0px; color: #999999; text-decoration: none; background-image: none; border: none; background-position: initial initial; background-repeat: initial initial; ">copy</a><embed width="100" height="20" name="clipboardswf_1" id="clipboardswf_1" devicefont="false" src="http://www.sunchis.com/public/clipboard.swf" menu="false" allowscriptaccess="sameDomain" swliveconnect="true" wmode="transparent" type="application/x-shockwave-flash" style="padding: 0px; margin: 0px; position: absolute; left: 0px; top: 0px; "></span></div><ol style="padding: 5px 0px; margin: 0px 0px 1px 3em !important; border-style: none none none solid; border-left-width: 3px; border-left-color: #146b00; list-style-position: initial; list-style-image: initial; color: #5c5c5c; "><li style="padding: 0px 3px 0px 10px !important; margin: 0px !important; border: none; list-style: decimal-leading-zero outside; color: inherit; line-height: 1.3em; "><span style="padding: 0px; margin: 0px; border: none; color: black; background-color: inherit; ">make&nbsp;clean&nbsp;</span></li><li style="padding: 0px 3px 0px 10px !important; margin: 0px !important; border: none; list-style: decimal-leading-zero outside; line-height: 1.3em; "><span style="padding: 0px; margin: 0px; border: none; color: black; background-color: inherit; ">rm&nbsp;config.cache&nbsp;</span></li></ol></pre><p style="padding: 0px; margin: 1em 0px 0.5em; text-indent: 2em; ">CMake (Unix/Linux)：</p><pre style="padding: 0px; margin-top: 0px; font-family: 'Courier New', monospace; font-size: 12px; width: 712px; overflow: auto; background-color: #f7f7f7; "><div id="codeCtrl_2" style="padding-left: 10px; margin: 0px 0px 0px 3em !important; border-left-width: 3px; border-left-style: solid; border-left-color: #146b00; color: #999999; "><a href="http://www.sunchis.com/html/db/mysql/2012/0612/419.html" id="view_2" style="padding: 0px; margin: 0px; color: #999999; text-decoration: none; background-image: none; border: none; background-position: initial initial; background-repeat: initial initial; ">view plain</a>&nbsp;&nbsp;&nbsp;<span id="clipinner" style="padding: 0px; margin: 0px; position: relative; width: 100px; "><a href="http://www.sunchis.com/html/db/mysql/2012/0612/419.html#" style="padding: 0px; margin: 0px; color: #999999; text-decoration: none; background-image: none; border: none; background-position: initial initial; background-repeat: initial initial; ">copy</a><embed width="100" height="20" name="clipboardswf_2" id="clipboardswf_2" devicefont="false" src="http://www.sunchis.com/public/clipboard.swf" menu="false" allowscriptaccess="sameDomain" swliveconnect="true" wmode="transparent" type="application/x-shockwave-flash" style="padding: 0px; margin: 0px; position: absolute; left: 0px; top: 0px; "></span></div><ol style="padding: 5px 0px; margin: 0px 0px 1px 3em !important; border-style: none none none solid; border-left-width: 3px; border-left-color: #146b00; list-style-position: initial; list-style-image: initial; color: #5c5c5c; "><li style="padding: 0px 3px 0px 10px !important; margin: 0px !important; border: none; list-style: decimal-leading-zero outside; color: inherit; line-height: 1.3em; "><span style="padding: 0px; margin: 0px; border: none; color: black; background-color: inherit; ">make&nbsp;clean&nbsp;</span></li><li style="padding: 0px 3px 0px 10px !important; margin: 0px !important; border: none; list-style: decimal-leading-zero outside; line-height: 1.3em; "><span style="padding: 0px; margin: 0px; border: none; color: black; background-color: inherit; ">rm&nbsp;CMakeCache.txt&nbsp;</span></li></ol></pre><p style="padding: 0px; margin: 1em 0px 0.5em; text-indent: 2em; ">CMake (Windows)：</p><pre style="padding: 0px; margin-top: 0px; font-family: 'Courier New', monospace; font-size: 12px; width: 712px; overflow: auto; background-color: #f7f7f7; "><div id="codeCtrl_3" style="padding-left: 10px; margin: 0px 0px 0px 3em !important; border-left-width: 3px; border-left-style: solid; border-left-color: #146b00; color: #999999; "><a href="http://www.sunchis.com/html/db/mysql/2012/0612/419.html" id="view_3" style="padding: 0px; margin: 0px; color: #999999; text-decoration: none; background-image: none; border: none; background-position: initial initial; background-repeat: initial initial; ">view plain</a>&nbsp;&nbsp;&nbsp;<span id="clipinner" style="padding: 0px; margin: 0px; position: relative; width: 100px; "><a href="http://www.sunchis.com/html/db/mysql/2012/0612/419.html#" style="padding: 0px; margin: 0px; color: #999999; text-decoration: none; background-image: none; border: none; background-position: initial initial; background-repeat: initial initial; ">copy</a><embed width="100" height="20" name="clipboardswf_3" id="clipboardswf_3" devicefont="false" src="http://www.sunchis.com/public/clipboard.swf" menu="false" allowscriptaccess="sameDomain" swliveconnect="true" wmode="transparent" type="application/x-shockwave-flash" style="padding: 0px; margin: 0px; position: absolute; left: 0px; top: 0px; "></span></div><ol style="padding: 5px 0px; margin: 0px 0px 1px 3em !important; border-style: none none none solid; border-left-width: 3px; border-left-color: #146b00; list-style-position: initial; list-style-image: initial; color: #5c5c5c; "><li style="padding: 0px 3px 0px 10px !important; margin: 0px !important; border: none; list-style: decimal-leading-zero outside; color: inherit; line-height: 1.3em; "><span style="padding: 0px; margin: 0px; border: none; color: black; background-color: inherit; ">devenv&nbsp;MySQL.sln&nbsp;/clean&nbsp;</span></li><li style="padding: 0px 3px 0px 10px !important; margin: 0px !important; border: none; list-style: decimal-leading-zero outside; line-height: 1.3em; "><span style="padding: 0px; margin: 0px; border: none; color: black; background-color: inherit; ">del&nbsp;CMakeCache.txt&nbsp;</span></li></ol></pre><h4><a name="Installation_Layout_Options" style="padding: 0px; margin: 0px; color: #256eb1; "><span style="padding: 0px; margin: 0px; color: #006486; ">安装参数选项</span></a></h4><p style="padding: 0px; margin: 1em 0px 0.5em; text-indent: 2em; ">在下表中，&#8220;CMAKE_INSTALL_PREFIX&#8221;的值表示的是安装根目录，其他参数值的路径都是相对于根目录的，当然你也可以直接使用绝对路径，具体如下：</p><table width="100%" border="1" style="padding: 0px; margin: 0px; border-spacing: 0px; border-collapse: collapse; font-size: 13px; "><thead style="padding: 0px; margin: 0px; height: 22px; background-color: #edebe0; border: none; background-position: initial initial; background-repeat: initial initial; "><tr style="padding: 0px; margin: 0px; "><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #7e7d68; font-weight: bold; ">参数值说明</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #7e7d68; font-weight: bold; ">配置选项</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #7e7d68; font-weight: bold; ">CMak选项</td></tr></thead><tbody style="padding: 0px; margin: 0px; height: 20px; "><tr style="padding: 0px; margin: 0px; "><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">安装根目录</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">--prefix=/usr</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">-DCMAKE_INSTALL_PREFIX=/usr</td></tr><tr style="padding: 0px; margin: 0px; "><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">mysqld目录</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">--libexecdir=/usr/sbin</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">-DINSTALL_SBINDIR=sbin</td></tr><tr style="padding: 0px; margin: 0px; "><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">数据存储目录</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">--localstatedir=/var/lib/mysql</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">-DMYSQL_DATADIR=/var/lib/mysql</td></tr><tr style="padding: 0px; margin: 0px; "><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">配置文件(my.cnf)目录</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">--sysconfdir=/etc/mysql</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">-DSYSCONFDIR=/etc/mysql</td></tr><tr style="padding: 0px; margin: 0px; "><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">插件目录</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">--with-plugindir=/usr/lib64/mysql/plugin</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">-DINSTALL_PLUGINDIR=lib64/mysql/plugin</td></tr><tr style="padding: 0px; margin: 0px; "><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">手册文件目录</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">--mandir=/usr/share/man</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">-DINSTALL_MANDIR=share/man</td></tr><tr style="padding: 0px; margin: 0px; "><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">共享数据目录</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">--sharedstatedir=/usr/share/mysql</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">-DINSTALL_SHAREDIR=share</td></tr><tr style="padding: 0px; margin: 0px; "><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">Library库目录</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">--libdir=/usr/lib64/mysql</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">-DINSTALL_LIBDIR=lib64/mysql</td></tr><tr style="padding: 0px; margin: 0px; "><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">Header安装目录</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">--includedir=/usr/include/mysql</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">-DINSTALL_INCLUDEDIR=include/mysql</td></tr><tr style="padding: 0px; margin: 0px; "><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">信息文档目录</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">--infodir=/usr/share/info</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">-DINSTALL_INFODIR=share/info</td></tr></tbody></table><h4><a name="Storage_Engine_Options" style="padding: 0px; margin: 0px; color: #256eb1; "><span style="padding: 0px; margin: 0px; color: #006486; ">存储引擎选项</span></a></h4><p style="padding: 0px; margin: 1em 0px 0.5em; text-indent: 2em; ">存储引擎是以插件的形式存在的，所以，该选项可以控制插件的构建，比如指定使用某个特定的引擎。</p><p style="padding: 0px; margin: 1em 0px 0.5em; text-indent: 2em; ">--with-plugins配置选项接受两种形式的参数值，它没有对应的CMake配置参数：</p><p style="padding: 0px; margin: 1em 0px 0.5em; text-indent: 2em; ">&#9312; 以逗号(,)分隔的引擎名称列表；</p><p style="padding: 0px; margin: 1em 0px 0.5em; text-indent: 2em; ">&#9313; a "group name" value that is shorthand for a set of engines</p><p style="padding: 0px; margin: 1em 0px 0.5em; text-indent: 2em; ">在CMake中，引擎被作为单个的选项来进行控制。假设有以下配置选项：</p><pre style="padding: 0px; margin-top: 0px; font-family: 'Courier New', monospace; font-size: 12px; width: 712px; overflow: auto; background-color: #f7f7f7; "><div id="codeCtrl_4" style="padding-left: 10px; margin: 0px 0px 0px 3em !important; border-left-width: 3px; border-left-style: solid; border-left-color: #146b00; color: #999999; "><a id="view_4" href="http://www.sunchis.com/html/db/mysql/2012/0612/419.html" style="padding: 0px; margin: 0px; color: #999999; text-decoration: none; background-image: none; border: none; background-position: initial initial; background-repeat: initial initial; ">view plain</a>&nbsp;&nbsp;&nbsp;<span id="clipinner" style="padding: 0px; margin: 0px; position: relative; width: 100px; "><a href="http://www.sunchis.com/html/db/mysql/2012/0612/419.html#" style="padding: 0px; margin: 0px; color: #999999; text-decoration: none; background-image: none; border: none; background-position: initial initial; background-repeat: initial initial; ">copy</a><embed width="100" height="20" type="application/x-shockwave-flash" wmode="transparent" swliveconnect="true" allowscriptaccess="sameDomain" menu="false" src="http://www.sunchis.com/public/clipboard.swf" devicefont="false" id="clipboardswf_4" name="clipboardswf_4" style="padding: 0px; margin: 0px; position: absolute; left: 0px; top: 0px; "></span></div><ol style="padding: 5px 0px; margin: 0px 0px 1px 3em !important; border-style: none none none solid; border-left-width: 3px; border-left-color: #146b00; list-style-position: initial; list-style-image: initial; color: #5c5c5c; "><li style="padding: 0px 3px 0px 10px !important; margin: 0px !important; border: none; list-style: decimal-leading-zero outside; color: inherit; line-height: 1.3em; "><span style="padding: 0px; margin: 0px; border: none; color: black; background-color: inherit; "><span style="padding: 0px; margin: 0px; border: none; color: red; background-color: inherit; ">--with-plugins</span><span style="padding: 0px; margin: 0px; border: none; background-color: inherit; ">=</span><span style="padding: 0px; margin: 0px; border: none; color: blue; background-color: inherit; ">csv</span><span style="padding: 0px; margin: 0px; border: none; background-color: inherit; ">,myisam,myisammrg,heap,innobase,archive,blackhole&nbsp;&nbsp;</span></span></li></ol></pre><p style="padding: 0px; margin: 1em 0px 0.5em; text-indent: 2em; ">上面的参数指定MySQL数据库可以支持哪些数据库引擎，将上述编译选项转换成CMake编译选项时，下面的几个引擎名字可以被省略，因为编译时，默认就支持：</p><pre style="padding: 0px; margin-top: 0px; font-family: 'Courier New', monospace; font-size: 12px; width: 712px; overflow: auto; background-color: #f7f7f7; "><div id="codeCtrl_5" style="padding-left: 10px; margin: 0px 0px 0px 3em !important; border-left-width: 3px; border-left-style: solid; border-left-color: #146b00; color: #999999; "><a id="view_5" href="http://www.sunchis.com/html/db/mysql/2012/0612/419.html" style="padding: 0px; margin: 0px; color: #999999; text-decoration: none; background-image: none; border: none; background-position: initial initial; background-repeat: initial initial; ">view plain</a>&nbsp;&nbsp;&nbsp;<span id="clipinner" style="padding: 0px; margin: 0px; position: relative; width: 100px; "><a href="http://www.sunchis.com/html/db/mysql/2012/0612/419.html#" style="padding: 0px; margin: 0px; color: #999999; text-decoration: none; background-image: none; border: none; background-position: initial initial; background-repeat: initial initial; ">copy</a><embed width="100" height="20" type="application/x-shockwave-flash" wmode="transparent" swliveconnect="true" allowscriptaccess="sameDomain" menu="false" src="http://www.sunchis.com/public/clipboard.swf" devicefont="false" id="clipboardswf_5" name="clipboardswf_5" style="padding: 0px; margin: 0px; position: absolute; left: 0px; top: 0px; "></span></div><ol style="padding: 5px 0px; margin: 0px 0px 1px 3em !important; border-style: none none none solid; border-left-width: 3px; border-left-color: #146b00; list-style-position: initial; list-style-image: initial; color: #5c5c5c; "><li style="padding: 0px 3px 0px 10px !important; margin: 0px !important; border: none; list-style: decimal-leading-zero outside; color: inherit; line-height: 1.3em; "><span style="padding: 0px; margin: 0px; border: none; color: black; background-color: inherit; ">csv&nbsp;myisam&nbsp;myisammrg&nbsp;heap&nbsp;</span></li></ol></pre><p style="padding: 0px; margin: 1em 0px 0.5em; text-indent: 2em; ">然后使用下面的编译参数，以启用InnoDB、ARCHIVE和BLACKHOLE引擎支持：</p><pre style="padding: 0px; margin-top: 0px; font-family: 'Courier New', monospace; font-size: 12px; width: 712px; overflow: auto; background-color: #f7f7f7; "><div id="codeCtrl_6" style="padding-left: 10px; margin: 0px 0px 0px 3em !important; border-left-width: 3px; border-left-style: solid; border-left-color: #146b00; color: #999999; "><a id="view_6" href="http://www.sunchis.com/html/db/mysql/2012/0612/419.html" style="padding: 0px; margin: 0px; color: #999999; text-decoration: none; background-image: none; border: none; background-position: initial initial; background-repeat: initial initial; ">view plain</a>&nbsp;&nbsp;&nbsp;<span id="clipinner" style="padding: 0px; margin: 0px; position: relative; width: 100px; "><a href="http://www.sunchis.com/html/db/mysql/2012/0612/419.html#" style="padding: 0px; margin: 0px; color: #999999; text-decoration: none; background-image: none; border: none; background-position: initial initial; background-repeat: initial initial; ">copy</a><embed width="100" height="20" type="application/x-shockwave-flash" wmode="transparent" swliveconnect="true" allowscriptaccess="sameDomain" menu="false" src="http://www.sunchis.com/public/clipboard.swf" devicefont="false" id="clipboardswf_6" name="clipboardswf_6" style="padding: 0px; margin: 0px; position: absolute; left: 0px; top: 0px; "></span></div><ol style="padding: 5px 0px; margin: 0px 0px 1px 3em !important; border-style: none none none solid; border-left-width: 3px; border-left-color: #146b00; list-style-position: initial; list-style-image: initial; color: #5c5c5c; "><li style="padding: 0px 3px 0px 10px !important; margin: 0px !important; border: none; list-style: decimal-leading-zero outside; color: inherit; line-height: 1.3em; "><span style="padding: 0px; margin: 0px; border: none; color: black; background-color: inherit; "><span style="padding: 0px; margin: 0px; border: none; color: red; background-color: inherit; ">-DWITH_INNOBASE_STORAGE_ENGINE</span><span style="padding: 0px; margin: 0px; border: none; background-color: inherit; ">=</span><span style="padding: 0px; margin: 0px; border: none; color: blue; background-color: inherit; ">1</span>&nbsp;</span></li><li style="padding: 0px 3px 0px 10px !important; margin: 0px !important; border: none; list-style: decimal-leading-zero outside; line-height: 1.3em; "><span style="padding: 0px; margin: 0px; border: none; color: black; background-color: inherit; "><span style="padding: 0px; margin: 0px; border: none; color: red; background-color: inherit; ">-DWITH_ARCHIVE_STORAGE_ENGINE</span><span style="padding: 0px; margin: 0px; border: none; background-color: inherit; ">=</span><span style="padding: 0px; margin: 0px; border: none; color: blue; background-color: inherit; ">1</span>&nbsp;</span></li><li style="padding: 0px 3px 0px 10px !important; margin: 0px !important; border: none; list-style: decimal-leading-zero outside; color: inherit; line-height: 1.3em; "><span style="padding: 0px; margin: 0px; border: none; color: black; background-color: inherit; "><span style="padding: 0px; margin: 0px; border: none; color: red; background-color: inherit; ">-DWITH_BLACKHOLE_STORAGE_ENGINE</span><span style="padding: 0px; margin: 0px; border: none; background-color: inherit; ">=</span><span style="padding: 0px; margin: 0px; border: none; color: blue; background-color: inherit; ">1</span>&nbsp;</span></li></ol></pre><p style="padding: 0px; margin: 1em 0px 0.5em; text-indent: 2em; ">当然也可以使用&#8220;ON&#8221;来替代数字1，它们是等效的。</p><p style="padding: 0px; margin: 1em 0px 0.5em; text-indent: 2em; ">如果你想除去对某种引擎的支持，则在CMake编译选项中使用-DWITHOUT_&lt;ENGINE&gt;_STORAGE_ENGINE，例如：</p><pre style="padding: 0px; margin-top: 0px; font-family: 'Courier New', monospace; font-size: 12px; width: 712px; overflow: auto; background-color: #f7f7f7; "><div id="codeCtrl_7" style="padding-left: 10px; margin: 0px 0px 0px 3em !important; border-left-width: 3px; border-left-style: solid; border-left-color: #146b00; color: #999999; "><a id="view_7" href="http://www.sunchis.com/html/db/mysql/2012/0612/419.html" style="padding: 0px; margin: 0px; color: #999999; text-decoration: none; background-image: none; border: none; background-position: initial initial; background-repeat: initial initial; ">view plain</a>&nbsp;&nbsp;&nbsp;<span id="clipinner" style="padding: 0px; margin: 0px; position: relative; width: 100px; "><a href="http://www.sunchis.com/html/db/mysql/2012/0612/419.html#" style="padding: 0px; margin: 0px; color: #999999; text-decoration: none; background-image: none; border: none; background-position: initial initial; background-repeat: initial initial; ">copy</a><embed width="100" height="20" type="application/x-shockwave-flash" wmode="transparent" swliveconnect="true" allowscriptaccess="sameDomain" menu="false" src="http://www.sunchis.com/public/clipboard.swf" devicefont="false" id="clipboardswf_7" name="clipboardswf_7" style="padding: 0px; margin: 0px; position: absolute; left: 0px; top: 0px; "></span></div><ol style="padding: 5px 0px; margin: 0px 0px 1px 3em !important; border-style: none none none solid; border-left-width: 3px; border-left-color: #146b00; list-style-position: initial; list-style-image: initial; color: #5c5c5c; "><li style="padding: 0px 3px 0px 10px !important; margin: 0px !important; border: none; list-style: decimal-leading-zero outside; color: inherit; line-height: 1.3em; "><span style="padding: 0px; margin: 0px; border: none; color: black; background-color: inherit; "><span style="padding: 0px; margin: 0px; border: none; color: red; background-color: inherit; ">-DWITHOUT_EXAMPLE_STORAGE_ENGINE</span><span style="padding: 0px; margin: 0px; border: none; background-color: inherit; ">=</span><span style="padding: 0px; margin: 0px; border: none; color: blue; background-color: inherit; ">1</span>&nbsp;</span></li><li style="padding: 0px 3px 0px 10px !important; margin: 0px !important; border: none; list-style: decimal-leading-zero outside; line-height: 1.3em; "><span style="padding: 0px; margin: 0px; border: none; color: black; background-color: inherit; "><span style="padding: 0px; margin: 0px; border: none; color: red; background-color: inherit; ">-DWITHOUT_FEDERATED_STORAGE_ENGINE</span><span style="padding: 0px; margin: 0px; border: none; background-color: inherit; ">=</span><span style="padding: 0px; margin: 0px; border: none; color: blue; background-color: inherit; ">1</span>&nbsp;</span></li><li style="padding: 0px 3px 0px 10px !important; margin: 0px !important; border: none; list-style: decimal-leading-zero outside; color: inherit; line-height: 1.3em; "><span style="padding: 0px; margin: 0px; border: none; color: black; background-color: inherit; "><span style="padding: 0px; margin: 0px; border: none; color: red; background-color: inherit; ">-DWITHOUT_PARTITION_STORAGE_ENGINE</span><span style="padding: 0px; margin: 0px; border: none; background-color: inherit; ">=</span><span style="padding: 0px; margin: 0px; border: none; color: blue; background-color: inherit; ">1</span>&nbsp;</span></li></ol></pre><h4><a name="Library_Options" style="padding: 0px; margin: 0px; color: #256eb1; "><span style="padding: 0px; margin: 0px; color: #006486; ">库文件加载选项</span></a></h4><p style="padding: 0px; margin: 1em 0px 0.5em; text-indent: 2em; ">该选项指明Mysql使用库的情况：</p><table width="100%" border="1" style="padding: 0px; margin: 0px; border-spacing: 0px; border-collapse: collapse; font-size: 13px; "><thead style="padding: 0px; margin: 0px; height: 22px; background-color: #edebe0; border: none; background-position: initial initial; background-repeat: initial initial; "><tr style="padding: 0px; margin: 0px; "><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #7e7d68; font-weight: bold; ">参数值说明</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #7e7d68; font-weight: bold; ">配置选项</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #7e7d68; font-weight: bold; ">CMak选项</td></tr></thead><tbody style="padding: 0px; margin: 0px; height: 20px; "><tr style="padding: 0px; margin: 0px; "><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">readline库</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">--with-readline</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">-DWITH_READLINE=1</td></tr><tr style="padding: 0px; margin: 0px; "><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">SSL库</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">--with-ssl=/usr</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">-DWITH_SSL=system</td></tr><tr style="padding: 0px; margin: 0px; "><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">zlib库</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">--with-zlib-dir=/usr</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">-DWITH_ZLIB=system</td></tr><tr style="padding: 0px; margin: 0px; "><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">libwrap库</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">--without-libwrap</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">-DWITH_LIBWRAP=0</td></tr></tbody></table><h4><a name="Miscellaneous_Options" style="padding: 0px; margin: 0px; color: #256eb1; "><span style="padding: 0px; margin: 0px; color: #006486; ">其他选项</span></a></h4><p style="padding: 0px; margin: 1em 0px 0.5em; text-indent: 2em; ">CMake编译选项支持大部分之前版本的MySQL编译选项，新老编译选项的差别在于：之前的是小写，现在全部变成了大写，之前采用双横线，现在使用单横线，之前使用的破折号，现在取而代之的是使用下划线，例如：</p><pre style="padding: 0px; margin-top: 0px; font-family: 'Courier New', monospace; font-size: 12px; width: 712px; overflow: auto; background-color: #f7f7f7; "><div id="codeCtrl_8" style="padding-left: 10px; margin: 0px 0px 0px 3em !important; border-left-width: 3px; border-left-style: solid; border-left-color: #146b00; color: #999999; "><a id="view_8" href="http://www.sunchis.com/html/db/mysql/2012/0612/419.html" style="padding: 0px; margin: 0px; color: #999999; text-decoration: none; background-image: none; border: none; background-position: initial initial; background-repeat: initial initial; ">view plain</a>&nbsp;&nbsp;&nbsp;<span id="clipinner" style="padding: 0px; margin: 0px; position: relative; width: 100px; "><a href="http://www.sunchis.com/html/db/mysql/2012/0612/419.html#" style="padding: 0px; margin: 0px; color: #999999; text-decoration: none; background-image: none; border: none; background-position: initial initial; background-repeat: initial initial; ">copy</a><embed width="100" height="20" type="application/x-shockwave-flash" wmode="transparent" swliveconnect="true" allowscriptaccess="sameDomain" menu="false" src="http://www.sunchis.com/public/clipboard.swf" devicefont="false" id="clipboardswf_8" name="clipboardswf_8" style="padding: 0px; margin: 0px; position: absolute; left: 0px; top: 0px; "></span></div><ol style="padding: 5px 0px; margin: 0px 0px 1px 3em !important; border-style: none none none solid; border-left-width: 3px; border-left-color: #146b00; list-style-position: initial; list-style-image: initial; color: #5c5c5c; "><li style="padding: 0px 3px 0px 10px !important; margin: 0px !important; border: none; list-style: decimal-leading-zero outside; color: inherit; line-height: 1.3em; "><span style="padding: 0px; margin: 0px; border: none; color: black; background-color: inherit; "><span style="padding: 0px; margin: 0px; border: none; color: red; background-color: inherit; ">--with-debug</span><span style="padding: 0px; margin: 0px; border: none; background-color: inherit; ">&nbsp;=</span><span style="padding: 0px; margin: 0px; border: none; color: #006699; background-color: inherit; font-weight: bold; ">&gt;</span>&nbsp;<span style="padding: 0px; margin: 0px; border: none; color: red; background-color: inherit; ">WITH_DEBUG</span><span style="padding: 0px; margin: 0px; border: none; background-color: inherit; ">=</span><span style="padding: 0px; margin: 0px; border: none; color: blue; background-color: inherit; ">1</span>&nbsp;</span></li><li style="padding: 0px 3px 0px 10px !important; margin: 0px !important; border: none; list-style: decimal-leading-zero outside; line-height: 1.3em; "><span style="padding: 0px; margin: 0px; border: none; color: black; background-color: inherit; "><span style="padding: 0px; margin: 0px; border: none; color: red; background-color: inherit; ">--with-embedded-server</span><span style="padding: 0px; margin: 0px; border: none; background-color: inherit; ">&nbsp;=</span><span style="padding: 0px; margin: 0px; border: none; color: #006699; background-color: inherit; font-weight: bold; ">&gt;</span><span style="padding: 0px; margin: 0px; border: none; background-color: inherit; ">&nbsp;WITH_EMBEDDED_SERVER&nbsp;</span></span></li></ol></pre><p style="padding: 0px; margin: 1em 0px 0.5em; text-indent: 2em; ">下面是编译MySQL的新老参数对照表：</p><table width="100%" border="1" style="padding: 0px; margin: 0px; border-spacing: 0px; border-collapse: collapse; font-size: 13px; "><thead style="padding: 0px; margin: 0px; height: 22px; background-color: #edebe0; border: none; background-position: initial initial; background-repeat: initial initial; "><tr style="padding: 0px; margin: 0px; "><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #7e7d68; font-weight: bold; ">参数值说明</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #7e7d68; font-weight: bold; ">配置选项</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #7e7d68; font-weight: bold; ">CMak选项</td></tr></thead><tbody style="padding: 0px; margin: 0px; height: 20px; "><tr style="padding: 0px; margin: 0px; "><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">TCP/IP端口</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">--with-tcp-port-=3306</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">-DMYSQL_TCP_PORT=3306</td></tr><tr style="padding: 0px; margin: 0px; "><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">UNIX socket文件</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">--with-unix-socket-path=/tmp/mysqld.sock</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">-DMYSQL_UNIX_ADDR=/tmp/mysqld.sock</td></tr><tr style="padding: 0px; margin: 0px; "><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">启用加载本地数据</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">--enable-local-infile</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">-DENABLED_LOCAL_INFILE=1</td></tr><tr style="padding: 0px; margin: 0px; "><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">扩展字符支持</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">--with-extra-charsets=all（默认：all）</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">-DEXTRA_CHARSETS=all（默认：all）</td></tr><tr style="padding: 0px; margin: 0px; "><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">默认字符集</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">--with-charset=utf8</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">-DDEFAULT_CHARSET=utf8</td></tr><tr style="padding: 0px; margin: 0px; "><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">默认字符校对</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">--with-collation=utf8_general_ci</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">-DDEFAULT_COLLATION=utf8_general_ci</td></tr><tr style="padding: 0px; margin: 0px; "><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">Build the server</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">--with-server</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">无</td></tr><tr style="padding: 0px; margin: 0px; "><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">嵌入式服务器</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">--with-embedded-server</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">-DWITH_EMBEDDED_SERVER=1</td></tr><tr style="padding: 0px; margin: 0px; "><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">libmysqld权限控制</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">--with-embedded-privilege-control</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">无</td></tr><tr style="padding: 0px; margin: 0px; "><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">安装文档</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">--without-docs</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">无</td></tr><tr style="padding: 0px; margin: 0px; "><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">Big tables支持</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">--with-big-tables, --without-big-tables</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">无</td></tr><tr style="padding: 0px; margin: 0px; "><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">mysqld运行用户</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">--with-mysqld-user=mysql</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">-DMYSQL_USER=mysql</td></tr><tr style="padding: 0px; margin: 0px; "><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">调试模式</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">--without-debug（默认禁用）</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">-DWITH_DEBUG=0（默认禁用）</td></tr><tr style="padding: 0px; margin: 0px; "><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">GIS支持</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">--with-geometry</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">无</td></tr><tr style="padding: 0px; margin: 0px; "><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">社区功能</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">--enable-community-features</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">无</td></tr><tr style="padding: 0px; margin: 0px; "><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">Profiling</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">--disable-profiling（默认启用）</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">-DENABLE_PROFILING=0（默认启用）</td></tr><tr style="padding: 0px; margin: 0px; "><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">pstack</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">--without-pstack</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">无（新版移除该功能）</td></tr><tr style="padding: 0px; margin: 0px; "><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">汇编字符串函数</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">--enable-assembler</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">无</td></tr><tr style="padding: 0px; margin: 0px; "><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">构建类型</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">--build=x86_64-pc-linux-gnu</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">没有等效参数</td></tr><tr style="padding: 0px; margin: 0px; "><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">交叉编译主机</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">--host=x86_64-pc-linux-gnu</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">没有等效参数</td></tr><tr style="padding: 0px; margin: 0px; "><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">客户端标志</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">--with-client-ldflags=-lstdc++</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">无</td></tr><tr style="padding: 0px; margin: 0px; "><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">线程安全标志</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">--enable-thread-safe-client</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">无</td></tr><tr style="padding: 0px; margin: 0px; "><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">注释存储类型</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">--with-comment='string'</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">-DWITH_COMMENT='string'</td></tr><tr style="padding: 0px; margin: 0px; "><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">Shared/static binaries</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">--enable-shared --enable-static</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">无</td></tr><tr style="padding: 0px; margin: 0px; "><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">内存使用控制</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">--with-low-memory</td><td style="padding: 2px 5px; margin: 0px; border-style: solid; border-color: #c0c0c0; ">无</td></tr></tbody></table></div><div style="margin: 0px; width: 712px; float: none; overflow: hidden; text-align: center; font-family: Verdana, Arial, Tahoma; font-size: 12px; line-height: normal; background-color: #ffffff; "></div><img src ="http://www.blogjava.net/kelly859/aggbug/387005.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/kelly859/" target="_blank">maxchen</a> 2012-09-04 20:31 <a href="http://www.blogjava.net/kelly859/archive/2012/09/04/387005.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>Mysql参数配置优化说明</title><link>http://www.blogjava.net/kelly859/archive/2012/08/28/386420.html</link><dc:creator>maxchen</dc:creator><author>maxchen</author><pubDate>Tue, 28 Aug 2012 03:45:00 GMT</pubDate><guid>http://www.blogjava.net/kelly859/archive/2012/08/28/386420.html</guid><wfw:comment>http://www.blogjava.net/kelly859/comments/386420.html</wfw:comment><comments>http://www.blogjava.net/kelly859/archive/2012/08/28/386420.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.blogjava.net/kelly859/comments/commentRss/386420.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/kelly859/services/trackbacks/386420.html</trackback:ping><description><![CDATA[原文：<a href="http://blog.csdn.net/maria57/article/details/2963410">http://blog.csdn.net/maria57/article/details/2963410<br /></a><div><br /><br /><strong style="color: #333333; font-family: Arial; line-height: 26px; ">1．获取当前配置参数</strong><p style="margin-bottom:0pt; margin-top:0pt; "></p></div><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; ">要优化配置参数，首先要了解当前的配置参数以及运行情况。使用下列命令可以获得目前服务器使用的配置参数：<br /><span style="color: #339966; ">mysqld &#8211;verbose &#8211;help<br />mysqladmin variables extended-status &#8211;u root &#8211;p</span></p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; ">在MySQL控制台里面，运行下列命令可以获取状态变量的值：<br /><span style="color: #339966; ">mysql&gt; SHOW STATUS;</span></p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; ">如果只要检查某几个状态变量，可以使用下列命令：<br /><span style="color: #339966; ">mysql&gt; SHOW STATUS LIKE &#8216;[匹配模式]&#8217;;&nbsp;</span>( 可以使用%、?等 )</p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; "><strong>2．优化参数</strong></p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; ">参数优化基于一个前提，就是在我们的数据库中通常都使用InnoDB表，而不使用MyISAM表。在优化MySQL时，有两个配置参数是最重要的，即<span style="color: #00ff00; ">table_cache</span>和<span style="color: #00ff00; ">key_buffer_size</span>。</p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; "><strong>table_cache</strong><br /><span style="color: #00ff00; ">table_cache</span>指定表高速缓存的大小。每当MySQL访问一个表时，如果在表缓冲区中还有空间，该表就被打开并放入其中，这样可以更快地访问表内容。通过检查峰值时间的状态值<span style="color: #00ff00; ">Open_tables</span>和<span style="color: #00ff00; ">Opened_tables</span>，可以决定是否需要增加<span style="color: #00ff00; ">table_cache</span>的值。如果你发现<span style="color: #00ff00; ">open_tables</span>等于<span style="color: #00ff00; ">table_cache</span>，并且<span style="color: #00ff00; ">opened_tables</span>在不断增长，那么你就需要增加<span style="color: #00ff00; ">table_cache</span>的值了（上述状态值可以使用<span style="color: #339966; ">SHOW STATUS LIKE &#8216;Open%tables&#8217;</span>获得）。注意，不能盲目地把<span style="color: #00ff00; ">table_cache</span>设置成很大的值。如果设置得太高，可能会造成文件描述符不足，从而造成性能不稳定或者连接失败。</p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; ">对于有1G内存的机器，推荐值是128－256。</p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; ">案例1：该案例来自一个不是特别繁忙的服务器<br /><span style="color: #00ff00; ">table_cache &#8211; 512<br />open_tables &#8211; 103<br />opened_tables &#8211; 1273<br />uptime &#8211; 4021421 (measured in seconds)</span><br />该案例中table_cache似乎设置得太高了。在峰值时间，打开表的数目比table_cache要少得多。<br />案例2：该案例来自一台开发服务器。<br /><span style="color: #00ff00; ">table_cache &#8211; 64<br />open_tables &#8211; 64<br />opened-tables &#8211; 431<br />uptime &#8211; 1662790 (measured in seconds)</span><br />虽然<span style="color: #00ff00; ">open_tables</span>已经等于<span style="color: #00ff00; ">table_cache</span>，但是相对于服务器运行时间来说，<span style="color: #00ff00; ">opened_tables</span>的值也非常低。因此，增加<span style="color: #00ff00; ">table_cache</span>的值应该用处不大。<br />案例3：该案例来自一个性能不佳的服务器<br /><span style="color: #00ff00; ">table_cache &#8211; 64<br />open_tables &#8211; 64<br />opened_tables &#8211; 22423<br />uptime &#8211; 19538</span><br />该案例中<span style="color: #00ff00; ">table_cache</span>设置得太低了。虽然运行时间不到6小时，<span style="color: #00ff00; ">open_tables</span>达到了最大值，<span style="color: #00ff00; ">opened_tables</span>的值也非常高。这样就需要增加<span style="color: #00ff00; ">table_cache</span>的值。</p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; "><strong>key_buffer_size</strong><br /><span style="color: #00ff00; ">key_buffer_size</span>指定索引缓冲区的大小，它决定索引处理的速度，尤其是索引读的速度。通过检查状态值<span style="color: #00ff00; ">Key_read_requests</span>和<span style="color: #00ff00; ">Key_reads</span>，可以知道key_buffer_size设置是否合理。比例key_reads / key_read_requests应该尽可能的低，至少是1:100，1:1000更好（上述状态值可以使用<span style="color: #339966; ">SHOW STATUS LIKE &#8216;key_read%&#8217;</span>获得）。</p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; ">key_buffer_size只对MyISAM表起作用。即使你不使用MyISAM表，但是内部的临时磁盘表是MyISAM表，也要使用该值。可以使用检查状态值created_tmp_disk_tables得知详情。</p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; ">对于1G内存的机器，如果不使用MyISAM表，推荐值是16M（8-64M）。</p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; ">案例1：健康状况<br /><span style="color: #00ff00; ">key_buffer_size &#8211; 402649088 (384M)<br />key_read_requests &#8211; 597579931<br />key_reads - 56188</span><br />案例2：警报状态<br /><span style="color: #00ff00; ">key_buffer_size &#8211; 16777216 (16M)<br />key_read_requests &#8211; 597579931<br />key_reads - 53832731</span><br />案例1中比例低于1:10000，是健康的情况；案例2中比例达到1:11，警报已经拉响。</p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; "><strong>query_cache_size</strong><br />从4.0.1开始，MySQL提供了查询缓冲机制。使用查询缓冲，MySQL将SELECT语句和查询结果存放在缓冲区中，今后对于同样的SELECT语句（区分大小写），将直接从缓冲区中读取结果。根据MySQL用户手册，使用查询缓冲最多可以达到238％的效率。<br />通过检查状态值Qcache_*，可以知道<span style="color: #00ff00; ">query_cache_size</span>设置是否合理（上述状态值可以使用<span style="color: #339966; ">SHOW STATUS LIKE &#8216;Qcache%&#8217;</span>获得）。如果<span style="color: #00ff00; ">Qcache_lowmem_prunes</span>的值非常大，则表明经常出现缓冲不够的情况，如果<span style="color: #00ff00; ">Qcache_hits</span>的值也非常大，则表明查询缓冲使用非常频繁，此时需要增加缓冲大小；如果<span style="color: #00ff00; ">Qcache_hits</span>的值不大，则表明你的查询重复率很低，这种情况下使用查询缓冲反而会影响效率，那么可以考虑不用查询缓冲。此外，在SELECT语句中加入<span style="color: #339966; ">SQL_NO_CACHE</span>可以明确表示不使用查询缓冲。<br />与查询缓冲有关的参数还有<span style="color: #00ff00; ">query_cache_type、query_cache_limit、query_cache_min_res_unit。query_cache_type</span>指定是否使用查询缓冲，可以设置为0、1、2，该变量是SESSION级的变量。query_cache_limit指定单个查询能够使用的缓冲区大小，缺省为1M。<span style="color: #00ff00; ">query_cache_min_res_unit</span>是在4.1版本以后引入的，它指定分配缓冲区空间的最小单位，缺省为4K。检查状态值<span style="color: #00ff00; ">Qcache_free_blocks</span>，如果该值非常大，则表明缓冲区中碎片很多，这就表明查询结果都比较小，此时需要减小<span style="color: #00ff00; ">query_cache_min_res_unit</span>。</p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; "><strong>开启二进制日志( Binary Log )</strong><br />二进制日志包含所有更新数据的语句，其目的是在恢复数据库时用它来把数据尽可能恢复到最后的状态。另外，如果做同步复制( Replication )的话，也需要使用二进制日志传送修改情况。<br />开启二进制日志，需要设置参数log-bin。log_bin指定日志文件，如果不提供文件名，MySQL将自己产生缺省文件名。MySQL会在文件名后面自动添加数字索引，每次启动服务时，都会重新生成一个新的二进制文件。<br />此外，使用log-bin-index可以指定索引文件；使用binlog-do-db可以指定记录的数据库；使用binlog-ignore-db可以指定不记录的数据库。注意的是：binlog-do-db和binlog-ignore-db一次只指定一个数据库，指定多个数据库需要多个语句。而且，MySQL会将所有的数据库名称改成小写，在指定数据库时必须全部使用小写名字，否则不会起作用。<br />在MySQL中使用<span style="color: #339966; ">SHOW MASTER STATUS</span>命令可以查看目前的二进制日志状态。</p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; "><strong>开启慢查询日志( slow query log )</strong><br />慢查询日志对于跟踪有问题的查询非常有用。它记录所有查过long_query_time的查询，如果需要，还可以记录不使用索引的记录。下面是一个慢查询日志的例子：<br />开启慢查询日志，需要设置参数<span style="color: #00ff00; ">log_slow_queries、long_query_times、log-queries-not-using-indexes</span>。<span style="color: #00ff00; ">log_slow_queries</span>指定日志文件，如果不提供文件名，MySQL将自己产生缺省文件名。long_query_times指定慢查询的阈值，缺省是10秒。<span style="color: #00ff00; ">log-queries-not-using-indexes</span>是4.1.0以后引入的参数，它指示记录不使用索引的查询。</p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; "><strong>配置InnoDB</strong><br />相对于MyISAM表来说，正确配置参数对于InnoDB表更加关键。其中，最重要的参数是innodb_data_file_path。它指定表数据和索引存储的空间，可以是一个或者多个文件。最后一个数据文件必须是自动扩充的，也只有最后一个文件允许自动扩充。这样，当空间用完后，自动扩充数据文件就会自动增长（以8MB为单位）以容纳额外的数据。例如：<br /><span style="color: #00ff00; ">innodb_data_file_path=/disk1/ibdata1:900M;/disk2/ibdata2:50M:autoextend</span></p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; ">两个数据文件放在不同的磁盘上。数据首先放在ibdata1中，当达到900M以后，数据就放在ibdata2中。一旦达到50MB，ibdata2将以8MB为单位自动增长。</p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; ">如果磁盘满了，你需要在另外的磁盘上面增加一个数据文件。为此，你需要查看最后一个文件的尺寸，然后计算最接近的整数（MB）。然后手工修改该文件的大小，并添加新的数据文件。例如：假设ibdata2已经有109MB数据，那么可以修改如下：<br /><span style="color: #00ff00; ">innodb_data_file_path=/disk1/ibdata1:900M;/disk2/ibdata2:109M;/disk3/ibdata3:500M:autoextend</span></p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; "><strong>flush_time</strong><br />如果系统有问题并且经常锁死或重新引导，应将该变量设置为非零值，这将导致服务器按flush_time 秒来刷新表的高速缓存。用这种方法来写出对表的修改将降低性能，但可减少表讹误或数据丢失的机会。<br />一般使用缺省值。</p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; "><strong>Binlog_cache_size</strong><br />The size of the cache to hold the&nbsp;<a title="sql" href="http://www.google.cn/search?sbi=sql&amp;q=sql&amp;sbb=%E6%90%9C%E7%B4%A2&amp;sa=%E6%90%9C%E7%B4%A2&amp;client=pub-6430022987645146&amp;forid=1&amp;prog=aff&amp;ie=GB2312&amp;oe=GB2312&amp;hl=zh-CN" target="_blank" style="color: #336699; text-decoration: none; ">sql</a>&nbsp;statements for the binary log during a transaction. A binary log cache is allocated for each client if the&nbsp;<a title="server" href="http://www.google.cn/search?sbi=server&amp;q=server&amp;sbb=%E6%90%9C%E7%B4%A2&amp;sa=%E6%90%9C%E7%B4%A2&amp;client=pub-6430022987645146&amp;forid=1&amp;prog=aff&amp;ie=GB2312&amp;oe=GB2312&amp;hl=zh-CN" target="_blank" style="color: #336699; text-decoration: none; ">server</a>&nbsp;supports any transactional storage engines and if the&nbsp;<a title="server" href="http://www.google.cn/search?sbi=server&amp;q=server&amp;sbb=%E6%90%9C%E7%B4%A2&amp;sa=%E6%90%9C%E7%B4%A2&amp;client=pub-6430022987645146&amp;forid=1&amp;prog=aff&amp;ie=GB2312&amp;oe=GB2312&amp;hl=zh-CN" target="_blank" style="color: #336699; text-decoration: none; ">server</a>&nbsp;has binary log enabled(&#8211;log-bin option). If you often use big, multiple-statement transactions, you can increase this to get more performance. The Binlog_cache_use and Binlog_cache_disk_use status variables can be useful for tuning the size of this variable.</p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; "><strong>3．存储引擎</strong></p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; ">在MYSQL 3.23.0版本中，引入了MyISAM存储引擎。它是一个非事务型的存储引擎，成为了MYSQL的缺省存储引擎。但是，如果使用设置向导来设置参数，则它会把InnoDB作为缺省的存储引擎。InnoDB是一个事务型的存储引擎。</p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; ">创建表的时候，可以为表指定存储引擎，语法如下：<br /><span style="color: #339966; ">CREATE&nbsp;<a title="table" href="http://www.alimama.com/membersvc/buyadzone/buy_ad_zone.htm?adzoneid=892989" target="_blank" style="color: #336699; text-decoration: none; ">table</a>&nbsp;t (i INT) ENGINE = MyISAM<br />CREATE&nbsp;<a title="table" href="http://www.alimama.com/membersvc/buyadzone/buy_ad_zone.htm?adzoneid=892989" target="_blank" style="color: #336699; text-decoration: none; ">table</a>&nbsp;t (i INT) TYPE = MyISAM</span></p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; ">如果没有指定，则使用缺省的存储引擎。也可以使用ALTER TABLE来更换表引擎，语法如下：<br /><span style="color: #339966; ">ALTER&nbsp;<a title="table" href="http://www.alimama.com/membersvc/buyadzone/buy_ad_zone.htm?adzoneid=892989" target="_blank" style="color: #336699; text-decoration: none; ">table</a>&nbsp;t ENGINE = MyISAM</span></p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; ">同一数据库中可以包含不同存储引擎的表。</p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; ">事务型表具有以下特点：<br />&#216; Safer. Even if MySQL crashes or you get hardware problems, you can get your data back, either by automatic recovery or from a backup plus the transaction log.<br />&#216; You can combine many statements and accept them all at the same time with the COMMIT statement (if autocommit is disabled).<br />&#216; You can execute ROLLBACK to ignore your changes (if autocommit is disabled).<br />&#216; If an update fails, all your changes will be restored. (With non-transaction-safe tables, all changes that have taken place are permanent.)<br />&#216; Transaction-safe storage engines can provide better concurrency for tables that get many updates concurrently with reads.</p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; ">非事务型表具有以下优点：<br />&#216; Much faster<br />&#216; Lower disk space requirements<br />&#216; Less memory required to perform updates</p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; "><strong>4．MyISAM存储引擎</strong></p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; ">下面MyISAM的参数是MySQL手册推荐的参数，据说适应于大部分情况。对于如何监视参数设置是否合理，仍然没有头绪。<br /><span style="color: #00ff00; ">max_connections=200<br />read_buffer_size=1M<br />read_rnd_buffer_size＝8M<br />sort_buffer_size=1M<br />Read_buffer_size</span></p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; ">Each thread that does a sequential scan allocates a buffer of this size for each&nbsp;<a title="table" href="http://www.alimama.com/membersvc/buyadzone/buy_ad_zone.htm?adzoneid=892989" target="_blank" style="color: #336699; text-decoration: none; ">table</a>&nbsp;it scans. If you do many sequential scans, you might want to increse this value.</p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; "><strong>Read_rnd_buffer_size</strong><br />When reading rows in sorted order after a sort, the rows are read through this buffer to avoid disk seeks. Setting the variable to a large value can improve ORDER BY performance by a lot. However, this is a buffer allocated for each client, so you should not set the global variable to a large value. Instead, change the session variable only from within those clients that need to run large queries.</p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; "><strong>Bulk_insert_buffer_size</strong><br />该参数于4.0.3中引入。MyISAM使用一个树型的缓冲区来加速大量的插入，如<span style="color: #339966; ">INSERT&#8230;SELECT，INSERT&#8230;VALUES(&#8230;),VALUES(&#8230;),&#8230;,LOAD DATA INFILE</span>等。该参数指定了缓冲区的大小。缺省值为8M，设置为0则表示不使用该优化。<br />如果不使用MyISAM表，则可以将其设置为0。</p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; "><strong>5．InnoDB存储引擎</strong></p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; ">参考了很多资料，都没有明确地表明如何优化InnoDB参数，以及如何监视这些参数设置是否合理，只有根据MySQL用户手册上面的介绍来进行设置。</p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; "><strong>innodb_buffer_pool_size</strong><br />对于InnoDB表来说，<span style="color: #00ff00; ">innodb_buffer_pool_size</span>的作用就相当于<span style="color: #00ff00; ">key_buffer_size</span>对于MyISAM表的作用一样。InnoDB使用该参数指定大小的内存来缓冲数据和索引。对于单独的MySQL数据库服务器，最大可以把该值设置成物理内存的80%。</p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; ">根据MySQL手册，对于2G内存的机器，推荐值是1G（50%）。</p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; "><strong>innodb_flush_log_at_trx_commit</strong><br />该值指定InnoDB记录日志的方式。如果设置为1，则每个事务提交的时候，MySQL都会将事务日志写入磁盘。如果设置为0或者2，则大概每秒中将日志写入磁盘一次。（还不清楚0和2的区别）</p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; ">实际测试发现，该值对插入数据的速度影响非常大，设置为2时插入10000条记录只需要2秒，设置为0时只需要1秒，而设置为1时则需要229秒。因此，MySQL手册也建议尽量将插入操作合并成一个事务，这样可以大幅提高速度。</p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; ">根据MySQL手册，在存在丢失最近部分事务的危险的前提下，可以把该值设为0。</p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; "><strong>innodb_log_file_size</strong><br />The size of each log file in a log group. The default is 5MB. The larger the value, the less checkpoint flush activity is needed in the buffer pool, saving disk I/O. But large log files also mean that recovery will be slower in case of a crash.</p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; ">根据MySQL手册，推荐值是innodb_buffer_pool_size的25%。</p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; ">注意：在重新设置该值时，好像要把原来的文件删除掉。</p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; "><strong>innodb_log_buffer_size</strong><br />The size of the buffer that InnoDB uses to write to the log files on disk. Sensible values range from 1MB to 8MB. The default is 1MB. A large log buffer allows large transactions to run without a need to write the log to disk before the transactions commit. Thus, if you have big transactions, making the log buffer larger will save disk I/O.<br />根据MySQL手册，推荐值是8M。</p><p style="color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff; "><strong>innodb_additional_mem_pool_size</strong><br />该参数指定InnoDB用来存储数据字典和其他内部数据结构的内存池大小。缺省值是1M。通常不用太大，只要够用就行，应该与表结构的复杂度有关系。如果不够用，MySQL会在错误日志中写入一条警告信息。<br />根据MySQL手册，对于2G内存的机器，推荐值是20M。</p><img src ="http://www.blogjava.net/kelly859/aggbug/386420.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/kelly859/" target="_blank">maxchen</a> 2012-08-28 11:45 <a href="http://www.blogjava.net/kelly859/archive/2012/08/28/386420.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>mysql分表的3种方法</title><link>http://www.blogjava.net/kelly859/archive/2012/06/08/380369.html</link><dc:creator>maxchen</dc:creator><author>maxchen</author><pubDate>Fri, 08 Jun 2012 09:59:00 GMT</pubDate><guid>http://www.blogjava.net/kelly859/archive/2012/06/08/380369.html</guid><wfw:comment>http://www.blogjava.net/kelly859/comments/380369.html</wfw:comment><comments>http://www.blogjava.net/kelly859/archive/2012/06/08/380369.html#Feedback</comments><slash:comments>2</slash:comments><wfw:commentRss>http://www.blogjava.net/kelly859/comments/commentRss/380369.html</wfw:commentRss><trackback:ping>http://www.blogjava.net/kelly859/services/trackbacks/380369.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 一，先说一下为什么要分表当一张的数据达到几百万时，你查询一次所花的时间会变多，如果有联合查询的话，我想有可能会死在那儿了。分表的目的就在于此，减小数据库的负担，缩短查询时间。根据个人经验，mysql执行一个sql的过程如下：1,接收到sql;2,把sql放到排队队列中 ;3,执行sql;4,返回执行结果。在这个执行过程中最花时间在什么地方呢？第一，是排队等待的时间，第二，sql的执行时间。其实这二...&nbsp;&nbsp;<a href='http://www.blogjava.net/kelly859/archive/2012/06/08/380369.html'>阅读全文</a><img src ="http://www.blogjava.net/kelly859/aggbug/380369.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.blogjava.net/kelly859/" target="_blank">maxchen</a> 2012-06-08 17:59 <a href="http://www.blogjava.net/kelly859/archive/2012/06/08/380369.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>