﻿<?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>C++博客-兔子的技术博客-随笔分类-数据库，MIS系统</title><link>http://www.cppblog.com/flyinghare/category/11478.html</link><description>兔子</description><language>zh-cn</language><lastBuildDate>Fri, 11 Oct 2013 10:25:05 GMT</lastBuildDate><pubDate>Fri, 11 Oct 2013 10:25:05 GMT</pubDate><ttl>60</ttl><item><title>C++操作mysql数据库文章资料汇总</title><link>http://www.cppblog.com/flyinghare/archive/2013/10/11/203664.html</link><dc:creator>会飞的兔子</dc:creator><author>会飞的兔子</author><pubDate>Fri, 11 Oct 2013 09:56:00 GMT</pubDate><guid>http://www.cppblog.com/flyinghare/archive/2013/10/11/203664.html</guid><wfw:comment>http://www.cppblog.com/flyinghare/comments/203664.html</wfw:comment><comments>http://www.cppblog.com/flyinghare/archive/2013/10/11/203664.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/flyinghare/comments/commentRss/203664.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/flyinghare/services/trackbacks/203664.html</trackback:ping><description><![CDATA[<table border="0" cellspacing="1" cellpadding="1" align="center" style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; background-color: #ffffff; width: 680px;"><tbody><tr><td><table border="0" cellspacing="0" cellpadding="5" style="width: 676px;"><tbody><tr><td><strong>usidc5</strong></td><td align="right">2010-07-19 00:19</td></tr><tr bgcolor="#ffffff"><td colspan="2"><h1>C++操作mysql数据库文章资料汇总</h1><span style="font-family: tahoma; font-size: 14px; color: #222222; line-height: 23px;"><p style="margin: 15px 0pt; padding: 0px;">VC的MySQL编程<br />在你的程式中使用数据库是个不做的注意。如果已经有可用的MySQL服务 器，在VC中可以按照如下方法实现与数据库的连接。</p><p style="margin: 15px 0pt; padding: 0px;">1、 找來MySQL(Win32)安裝目录下的include文件夾， 將其添加到VC头文件目录列表中；</p><p style="margin: 15px 0pt; padding: 0px;">（VC6 -&gt; Options -&gt; Directories -&gt; 加入此目录）</p><p style="margin: 15px 0pt; padding: 0px;">（VC2005 -&gt; 工具 -&gt;&nbsp;选项 -&gt; 项目和解決方案 -&gt; VC++目录 -&gt; 显示以下内容的目录 -&gt; 包含文件 -&gt; 加入此目录）</p><p style="margin: 15px 0pt; padding: 0px;">2、找到MySQL(Win32)安裝目 录下的lib文件夹， 將其添加到VC库文件目录列表中；</p><p style="margin: 15px 0pt; padding: 0px;">（VC6 -&gt; Options -&gt; Directories -&gt; 加入此目录）</p><p style="margin: 15px 0pt; padding: 0px;">（VC2005 -&gt; 工具 -&gt; 选项 -&gt; 项目和解决方案 -&gt; VC++目录 -&gt; 显示以下内容的目录 -&gt; 库文件 -&gt; 加入此目录，注意是lib/debug或lib/opt）</p><p style="margin: 15px 0pt; padding: 0px;">3、新建一个工程，参考如下代码；</p><p style="margin: 15px 0pt; padding: 0px;">// mysql.cpp : Defines the entry point for the console application.<br />//</p><p style="margin: 15px 0pt; padding: 0px;">#include "stdafx.h"<br />#include &lt;stdio.h&gt;<br />#include &lt;winsock.h&gt;<br />#include &lt;mysql.h&gt;<br />#include &lt;windows.h&gt;</p><p style="margin: 15px 0pt; padding: 0px;">#pragma comment(lib, "libmysql.lib")</p><p style="margin: 15px 0pt; padding: 0px;"><br />int main(int argc, char* argv[])<br />...{<br />unsigned short Port = 3306;<br />char *IPAddress = "192.168.31.56";<br />char *UserName = "root";<br />char *Password = "";<br />char *DBName = "SAS_1_2_0";</p><p style="margin: 15px 0pt; padding: 0px;">printf("Start... ");<br /><br />MYSQL *ssock;<br />//char execsql[500];</p><p style="margin: 15px 0pt; padding: 0px;">ssock = (MYSQL *)malloc(sizeof(MYSQL));<br /><br />// 在某些版本中，不需要该初始化工作，可观看mysql.H以及readme<br />mysql_init(ssock);<br />if(ssock == NULL)<br />...{<br />printf("EROR: MySQL ssock init error. ");<br />return FALSE;<br />}</p><p style="margin: 15px 0pt; padding: 0px;">//连接指定数据库<br />ssock = mysql_real_connect(ssock, IPAddress, UserName, Password, NULL, Port, NULL, 0);<br />if(!ssock)<br />...{<br />printf("conn fail... ");</p><p style="margin: 15px 0pt; padding: 0px;">//memcpy(eee, mysql_error(ssock), 20);<br />//fprintf(stderr, "Failed to connect to database: Error: %s ", mysql_error(ssock));</p><p style="margin: 15px 0pt; padding: 0px;">//printf("%c ", eee);<br />unsigned int mtint = mysql_errno(ssock);<br />//printf("%d ");<br />return FALSE;<br />}</p><p style="margin: 15px 0pt; padding: 0px;">if(mysql_select_db(ssock, DBName) != 0)<br />...{<br />printf("select db error. ");<br />return FALSE;<br />}</p><p style="margin: 15px 0pt; padding: 0px;">printf("version=%d ", mysql_get_server_version(ssock));<br />//exec my execsql string<br />//sprintf(execsql,"create table girls (name char(10),age int)");<br />//mysql_real_query(ssock,execsql,strlen(execsql));<br />mysql_close(ssock);</p><p style="margin: 15px 0pt; padding: 0px;">printf("End... ");<br />return TRUE;<br />}<br />4、编译连接，运行即可。</p><p style="margin: 15px 0pt; padding: 0px;">&nbsp;</p></span></td></tr></tbody></table></td></tr></tbody></table><p style="margin: 0px; padding: 0px; color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;">&nbsp;</p><table border="0" cellspacing="1" cellpadding="1" align="center" style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; background-color: #ffffff; width: 680px;"><tbody><tr><td><table border="0" cellspacing="0" cellpadding="5" style="width: 676px;"><tbody><tr><td><strong>usidc5</strong></td><td align="right">2010-07-19 00:21</td></tr><tr bgcolor="#ffffff"><td colspan="2">这里归纳了C API可使用的函数，并在下一节详细介绍了它们。<br /><br />函数<br />描述<br /><br />mysql_affected_rows()<br />返 回上次UPDATE、DELETE或INSERT查询更改／删除／插入的行数。<br /><br />mysql_autocommit()<br />切换 autocommit模式，ON/OFF<br /><br />mysql_change_user()<br />更改打开连接上的用户和数据库。<br /><br />mysql_charset_name()<br />返 回用于连接的默认字符集的名称。<br /><br />mysql_close()<br />关闭服务器连接。<br /><br />mysql_commit()<br />提 交事务。<br /><br />mysql_connect()<br />连接到MySQL服务器。该函数已不再被重视，使用 mysql_real_connect()取代。<br /><br />mysql_create_db()<br />创建数据库。该函数已不再被重视，使用 SQL语句CREATE DATABASE取而代之。<br /><br />mysql_data_seek()<br />在查询结果集中查找属性行编号。<br /><br />mysql_debug()<br />用 给定的字符串执行DBUG_PUSH。<br /><br />mysql_drop_db()<br />撤销数据库。该函数已不再被重视，使用SQL语句DROP DATABASE取而代之。<br /><br />mysql_dump_debug_info()<br />让服务器将调试信息写入日志。<br /><br />mysql_eof()<br />确 定是否读取了结果集的最后一行。该函数已不再被重视，可以使用mysql_errno()或mysql_error()取而代之。<br /><br />mysql_errno()<br />返 回上次调用的MySQL函数的错误编号。<br /><br />mysql_error()<br />返回上次调用的MySQL函数的错误消息。<br /><br />mysql_escape_string()<br />为 了用在SQL语句中，对特殊字符进行转义处理。<br /><br />mysql_fetch_field()<br />返回下一个表字段的类型。<br /><br />mysql_fetch_field_direct()<br />给 定字段编号，返回表字段的类型。<br /><br />mysql_fetch_fields()<br />返回所有字段结构的数组。<br /><br />mysql_fetch_lengths()<br />返 回当前行中所有列的长度。<br /><br />mysql_fetch_row()<br />从结果集中获取下一行<br /><br />mysql_field_seek()<br />将 列光标置于指定的列。<br /><br />mysql_field_count()<br />返回上次执行语句的结果列的数目。<br /><br />mysql_field_tell()<br />返 回上次mysql_fetch_field()所使用字段光标的位置。<br /><br />mysql_free_result()<br />释放结果集使用的 内存。<br />mysql_get_client_info()<br />以字符串形式返回客户端版本信息。<br /><br />mysql_get_client_version()<br />以 整数形式返回客户端版本信息。<br /><br />mysql_get_host_info()<br />返回描述连接的字符串。<br /><br />mysql_get_server_version()<br />以 整数形式返回服务器的版本号。<br /><br />mysql_get_proto_info()<br />返回连接所使用的协议版本。<br /><br />mysql_get_server_info()<br />返 回服务器的版本号。<br /><br />mysql_info()<br />返回关于最近所执行查询的信息。<br /><br />mysql_init()<br />获 取或初始化MYSQL结构。<br /><br />mysql_insert_id()<br />返回上一个查询为AUTO_INCREMENT列生成的ID。<br /><br />mysql_kill()<br />杀 死给定的线程。<br /><br />mysql_library_end()<br />最终确定MySQL C API库。<br /><br />mysql_library_init()<br />初 始化MySQL C API库。<br /><br />mysql_list_dbs()<br />返回与简单正则表达式匹配的数据库名称。<br /><br />mysql_list_fields()<br />返 回与简单正则表达式匹配的字段名称。<br /><br />mysql_list_processes()<br />返回当前服务器线程的列表。<br /><br />mysql_list_tables()<br />返 回与简单正则表达式匹配的表名。<br /><br />mysql_more_results()<br />检查是否还存在其他结果。<br /><br />mysql_next_result()<br />在 多语句执行过程中返回/初始化下一个结果。<br /><br />mysql_num_fields()<br />返回结果集中的列数。<br /><br />mysql_num_rows()<br />返 回结果集中的行数。<br /><br />mysql_options()<br />为mysql_connect()设置连接选项。<br /><br />mysql_ping()<br />检 查与服务器的连接是否工作，如有必要重新连接。<br /><br />mysql_query()<br />执行指定为&#8220;以Null终结的字符串&#8221;的SQL查询。<br /><br />mysql_real_connect()<br />连 接到MySQL服务器。<br /><br />mysql_real_escape_string()<br />考虑到连接的当前字符集，为了在SQL语句中使 用，对字符串中的特殊字符进行转义处理。<br /><br />mysql_real_query()<br />执行指定为计数字符串的SQL查询。<br /><br />mysql_refresh()<br />刷 新或复位表和高速缓冲。<br /><br />mysql_reload()<br />通知服务器再次加载授权表。<br />mysql_rollback()<br />回 滚事务。<br /><br />mysql_row_seek()<br />使用从mysql_row_tell()返回的值，查找结果集中的行偏移。<br /><br />mysql_row_tell()<br />返 回行光标位置。<br /><br />mysql_select_db()<br />选择数据库。<br /><br />mysql_server_end()<br />最 终确定嵌入式服务器库。<br /><br />mysql_server_init()<br />初始化嵌入式服务器库。<br /><br />mysql_set_server_option()<br />为 连接设置选项（如多语句）。<br /><br />mysql_sqlstate()<br />返回关于上一个错误的SQLSTATE错误代码。<br /><br />mysql_shutdown()<br />关 闭数据库服务器。<br /><br />mysql_stat()<br />以字符串形式返回服务器状态。<br /><br />mysql_store_result()<br />检 索完整的结果集至客户端。<br /><br />mysql_thread_id()<br />返回当前线程ID。<br /><br />mysql_thread_safe()<br />如 果客户端已编译为线程安全的，返回1。<br /><br />mysql_use_result()<br />初始化逐行的结果集检索。<br /><br />mysql_warning_count()<br />返 回上一个SQL语句的告警数。<br />&nbsp;<br /></td></tr></tbody></table></td></tr></tbody></table><p style="margin: 0px; padding: 0px; color: #333333; font-family: Arial; line-height: 26px; background-color: #ffffff;">&nbsp;</p><table border="0" cellspacing="0" cellpadding="5" style="color: #333333; font-family: Arial; font-size: 14px; line-height: 26px; background-color: #ffffff; width: 694px;"><tbody><tr><td><strong>usidc5</strong></td><td align="right">2010-07-19 00:22</td></tr><tr bgcolor="#ffffff"><td colspan="2"><span style="font-size: small;"><span style="font-family: tahoma;"><span style="color: #222222;"><div>与MySQL交互时， 应用程序应使用该一般性原则：</div><div></div><div>1. 通过调用mysql_library_init()，初始化MySQL库。库可以是mysqlclient C客户端库，或mysqld嵌入式服务器库，具体情况取决于应用程序是否与&#8220;-libmysqlclient&#8221;或&#8220;-libmysqld&#8221;标志链接。</div><div></div><div>2. 通过调用mysql_init()初始化连接处理程序，并通过调用mysql_real_connect()连接到服务器。</div><div></div><div>3. 发出SQL语句并处理其结果。（在下面的讨论中，详细介绍了使用它的方法）。</div><div></div><div>4. 通过调用mysql_close()，关闭与MySQL服务器的连接。</div><div></div><div>5. 通过调用mysql_library_end()，结束MySQL库的使用。</div><div></div><div>调用 mysql_library_init()和mysql_library_end()的目的在于，为MySQL库提供恰当的初始化和结束处理。对于与客户 端库链接的应用程序，它们提供了改进的内存管理功能。如果不调用mysql_library_end()，内存块仍将保持分配状态（这不会增加应用程序使 用的内存量，但某些内存泄漏检测器将抗议它）。对于与嵌入式服务器链接的应用程序，这些调用会启动并停止服务器。</div><div></div><div>mysql_library_init() 和mysql_library_end()实际上是#define符号，这类符号使得它们等效于mysql_server_init()和 mysql_server_end()，但其名称更清楚地指明，无论应用程序使用的是mysqlclient或mysqld库，启动或结束MySQL库 时，应调用它们。对于早期的MySQL版本，可调用mysql_server_init()和mysql_server_end()取而代之。</div><div></div><div>如 果愿意，可省略对mysql_library_init()的调用，这是因为，必要时，mysql_init()会自动调用它。</div><div></div><div>要 想连接到服务器，可调用mysql_init()来初始化连接处理程序，然后用该处理程序（以及其他信息，如主机名、用户名和密码）调用 mysql_real_connect()。建立连接后，在低于5.0.3版的API中，mysql_real_connect()会将再连接标志 （MYSQL结构的一部分）设置为1，或在较新的版本中，将其设置为0。对于该标志，值&#8220;1&#8221;指明，如果因连接丢失而无法执行语句，放弃之前，会尝试再次 连接到服务器。从MySQL 5.0.13开始，可以在mysql_options()上使用MYSQL_OPT_RECONNECT选项，以控制再连接行为。完成连接后，调用 mysql_close()中止它。</div><div></div><div>当连接处于活动状态时，客户端或许会使用 mysql_query()或mysql_real_query()向服务器发出SQL查询。两者的差别在于，mysql_query()预期的查询为指 定的、由Null终结的字符串，而mysql_real_query()预期的是计数字符串。如果字符串包含二进制数据（其中可能包含Null字节），就 必须使用mysql_real_query()。</div><div></div><div>对于每个非SELECT查询（例如INSERT、 UPDATE、DELETE），通过调用mysql_affected_rows()，可发现有多少行已被改变（影响）。</div><div></div><div>对 于SELECT查询，能够检索作为结果集的行。注意，某些语句因其返回行，类似与SELECT。包括SHOW、DESCRIBE和EXPLAIN。应按照 对待SELECT语句的方式处理它们。</div><div></div><div>客户端处理结果集的方式有两种。一种方式是，通过调用 mysql_store_result()，一次性地检索整个结果集。该函数能从服务器获得查询返回的所有行，并将它们保存在客户端。第二种方式是针对客 户端的，通过调用mysql_use_result()，对&#8220;按行&#8221;结果集检索进行初始化处理。该函数能初始化检索结果，但不能从服务器获得任何实际行。</div><div></div><div>在 这两种情况下，均能通过调用mysql_fetch_row()访问行。通过 mysql_store_result()，mysql_fetch_row()能够访问以前从服务器获得的行。通过 mysql_use_result()，mysql_fetch_row()能够实际地检索来自服务器的行。通过调用 mysql_fetch_lengths()，能获得关于各行中数据大小的信息。</div><div></div><div>完成结果集操作 后，请调用mysql_free_result()释放结果集使用的内存。</div><div></div><div>这两种检索机制是互补 的。客户端程序应选择最能满足其要求的方法。实际上，客户端最常使用的是mysql_store_result()。</div><div></div><div>mysql_store_result() 的1个优点在于，由于将行全部提取到了客户端上，你不仅能连续访问行，还能使用mysql_data_seek()或mysql_row_seek()在 结果集中向前或向后移动，以更改结果集内当前行的位置。通过调用mysql_num_rows()，还能发现有多少行。另一方面，对于大的结果 集，mysql_store_result()所需的内存可能会很大，你很可能遇到内存溢出状况。</div><div></div><div>mysql_use_result() 的1个优点在于，客户端所需的用于结果集的内存较少，原因在于，一次它仅维护一行（由于分配开销较低，mysql_use_result()能更快）。它 的缺点在于，你必须快速处理每一行以避免妨碍服务器，你不能随机访问结果集中的行（只能连续访问行），你不知道结果集中有多少行，直至全部检索了它们为 止。不仅如此，即使在检索过程中你判定已找到所寻找的信息，也必须检索所有的行。</div><div></div><div>通过API，客户 端能够恰当地对查询作出响应（仅在必要时检索行），而无需知道查询是否是SELECT查询。可以在每次mysql_query()或 mysql_real_query()后，通过调用mysql_store_result()完成该操作。如果结果集调用成功，查询为SELECT，而且 能够读取行。如果结果集调用失败，可调用mysql_field_count()来判断结果是否的确是所预期的。如果 mysql_field_count()返回0，查询不返回数据（表明它是INSERT、UPDATE、DELETE等），而且不返回行。如果 mysql_field_count()是非0值，查询应返回行，但没有返回行。这表明查询是失败了的SELECT。关于如何实现该操作的示例，请参见关 于mysql_field_count()的介绍。</div><div></div><div>无论是 mysql_store_result()还是mysql_use_result()，均允许你获取关于构成结果集的字段的信息（字段数目，它们的名称和 类型等）。通过重复调用mysql_fetch_field()，可以按顺序访问行内的字段信息，或者，通过调用 mysql_fetch_field_direct()，能够在行内按字段编号访问字段信息。通过调用mysql_field_seek()，可以改变当 前字段的光标位置。对字段光标的设置将影响后续的mysql_fetch_field()调用。此外，你也能通过调用 mysql_fetch_fields()，一次性地获得关于字段的所有信息。</div><div></div><div>为了检测和通报错 误，MySQL提供了使用mysql_errno()和mysql_error()函数访问错误信息的机制。它们能返回关于最近调用的函数的错误代码或错 误消息，最近调用的函数可能成功也可能失败，这样，你就能判断错误是在何时出现的，以及错误是什么。</div></span></span></span></td></tr></tbody></table>转自：<a href="http://blog.csdn.net/ghost1236/article/details/5746905">http://blog.csdn.net/ghost1236/article/details/5746905</a><img src ="http://www.cppblog.com/flyinghare/aggbug/203664.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/flyinghare/" target="_blank">会飞的兔子</a> 2013-10-11 17:56 <a href="http://www.cppblog.com/flyinghare/archive/2013/10/11/203664.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>且将新火试新茶 - MySQL Benchmark（全文）</title><link>http://www.cppblog.com/flyinghare/archive/2013/07/24/202096.html</link><dc:creator>会飞的兔子</dc:creator><author>会飞的兔子</author><pubDate>Wed, 24 Jul 2013 10:03:00 GMT</pubDate><guid>http://www.cppblog.com/flyinghare/archive/2013/07/24/202096.html</guid><wfw:comment>http://www.cppblog.com/flyinghare/comments/202096.html</wfw:comment><comments>http://www.cppblog.com/flyinghare/archive/2013/07/24/202096.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/flyinghare/comments/commentRss/202096.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/flyinghare/services/trackbacks/202096.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 且将新火试新茶&nbsp;- MySQL Benchmark公司内部最流行的数据库就是MySQL，而关于MySQL性能，我听过种种传说和流言。而对于数据库的性能优化和测试，我一直有强烈的兴趣，曾经见过一篇Oracle的性能优化文章，Linux Journal的Bert Scalzo所著的《Linux Maximus, Part 1: Gladiator-like Oracle Performanc...&nbsp;&nbsp;<a href='http://www.cppblog.com/flyinghare/archive/2013/07/24/202096.html'>阅读全文</a><img src ="http://www.cppblog.com/flyinghare/aggbug/202096.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/flyinghare/" target="_blank">会飞的兔子</a> 2013-07-24 18:03 <a href="http://www.cppblog.com/flyinghare/archive/2013/07/24/202096.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>MYSQL数据库管理之权限管理</title><link>http://www.cppblog.com/flyinghare/archive/2013/05/22/200500.html</link><dc:creator>会飞的兔子</dc:creator><author>会飞的兔子</author><pubDate>Wed, 22 May 2013 03:40:00 GMT</pubDate><guid>http://www.cppblog.com/flyinghare/archive/2013/05/22/200500.html</guid><wfw:comment>http://www.cppblog.com/flyinghare/comments/200500.html</wfw:comment><comments>http://www.cppblog.com/flyinghare/archive/2013/05/22/200500.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/flyinghare/comments/commentRss/200500.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/flyinghare/services/trackbacks/200500.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 经常遇到有网友在QQ群或者论坛上问关于mysql权限的问题,今天抽空总结一下关于这几年使用MYSQL的时候关于MYSQL数据库的权限管理的经验,也希望能对使用mysql的网友有所帮助!一、MYSQL权限简介关于mysql的权限简单的理解就是mysql允许你做你权利以内的事情,不可以越界。比如只允许你执行select操作，那么你就不能执行update操作。只允许你从某台机器上连接mysql，那么你就...&nbsp;&nbsp;<a href='http://www.cppblog.com/flyinghare/archive/2013/05/22/200500.html'>阅读全文</a><img src ="http://www.cppblog.com/flyinghare/aggbug/200500.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/flyinghare/" target="_blank">会飞的兔子</a> 2013-05-22 11:40 <a href="http://www.cppblog.com/flyinghare/archive/2013/05/22/200500.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>MYSQL 安装federated存储引擎  </title><link>http://www.cppblog.com/flyinghare/archive/2013/05/05/199996.html</link><dc:creator>会飞的兔子</dc:creator><author>会飞的兔子</author><pubDate>Sun, 05 May 2013 14:07:00 GMT</pubDate><guid>http://www.cppblog.com/flyinghare/archive/2013/05/05/199996.html</guid><wfw:comment>http://www.cppblog.com/flyinghare/comments/199996.html</wfw:comment><comments>http://www.cppblog.com/flyinghare/archive/2013/05/05/199996.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/flyinghare/comments/commentRss/199996.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/flyinghare/services/trackbacks/199996.html</trackback:ping><description><![CDATA[<p style="line-height: 25px; padding: 0px; color: #336699; font-family: Arial, Helvetica, simsun, u5b8bu4f53; background-color: #95d2ef; text-indent: 21pt;"><span style="font-family: 宋体;">Federated</span><span style="font-family: 宋体;">存储引擎可以使你在本地数据库中访问远程数据库中的数据，针对federated存储引擎表的查询会被发送到远程数据库的表上执行，本地是不存储任何数据的。</span></p><p style="line-height: 25px; padding: 0px; color: #336699; font-family: Arial, Helvetica, simsun, u5b8bu4f53; background-color: #95d2ef; text-indent: 21pt;"><span style="font-family: 宋体;">简要介绍后，是不是发现它和Oracle的database link(数据库链接)非常相似，它所实现的功能和db link类似，要在MySQL下找寻db link替代品的，federated存储引擎是不二的选择。</span></p><p style="line-height: 25px; margin: 0cm 0cm 0pt 14.2pt; padding: 0px; color: #336699; font-family: Arial, Helvetica, simsun, u5b8bu4f53; background-color: #95d2ef; text-indent: -14.2pt;"><span style="font-family: 宋体;">1.<span style="line-height: normal; font-size: 7pt; font-family: 'Times New Roman';">&nbsp;&nbsp;&nbsp;</span></span><span style="font-family: 宋体;">查看当前支持的存储引擎</span></p><p style="line-height: 25px; padding: 0px; color: #336699; font-family: Arial, Helvetica, simsun, u5b8bu4f53; background-color: #95d2ef;"><span style="font-family: 宋体;">SQL&gt;show engines;</span></p><p style="line-height: 25px; padding: 0px; color: #336699; font-family: Arial, Helvetica, simsun, u5b8bu4f53; background-color: #95d2ef;">&nbsp;</p><pre style="line-height: 25px; color: #336699; background-color: #95d2ef;"><ol style="margin: 5px 0px 5px 40px; padding: 0px;"><li><span style="line-height: 21px; font-size: 12px;">+------------+---------+------------------------------------------------------------+--------------+------+------------+ &nbsp;</span></li><li>&nbsp;</li><li><span style="line-height: 21px; font-size: 12px;">|&nbsp;Engine&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;Support&nbsp;|&nbsp;Comment&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;Transactions&nbsp;|&nbsp;XA&nbsp;&nbsp;&nbsp;|&nbsp;Savepoints&nbsp;| &nbsp;</span></li><li>&nbsp;</li><li><span style="line-height: 21px; font-size: 12px;">+------------+---------+------------------------------------------------------------+--------------+------+------------+ &nbsp;</span></li><li>&nbsp;</li><li><span style="line-height: 21px; font-size: 12px;">|&nbsp;CSV&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;YES&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;CSV&nbsp;storage&nbsp;engine&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;NO&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;NO&nbsp;&nbsp;&nbsp;|&nbsp;NO&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| &nbsp;</span></li><li>&nbsp;</li><li><span style="line-height: 21px; font-size: 12px;">|&nbsp;MRG_MYISAM&nbsp;|&nbsp;YES&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;Collection&nbsp;of&nbsp;identical&nbsp;MyISAM&nbsp;tables&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;NO&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;NO&nbsp;&nbsp;&nbsp;|&nbsp;NO&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| &nbsp;</span></li><li>&nbsp;</li><li><span style="line-height: 21px; font-size: 12px;">|&nbsp;MEMORY&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;YES&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;Hash&nbsp;based,&nbsp;stored&nbsp;in&nbsp;memory,&nbsp;useful&nbsp;for&nbsp;temporary&nbsp;tables&nbsp;&nbsp;|&nbsp;NO&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;NO&nbsp;&nbsp;&nbsp;|&nbsp;NO&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| &nbsp;</span></li><li>&nbsp;</li><li><span style="line-height: 21px; font-size: 12px;">|&nbsp;InnoDB&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;DEFAULT&nbsp;|&nbsp;Supports&nbsp;transactions,&nbsp;row-level&nbsp;locking,&nbsp;and&nbsp;foreign&nbsp;keys&nbsp;|&nbsp;YES&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;YES&nbsp;&nbsp;|&nbsp;YES&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| &nbsp;</span></li><li>&nbsp;</li><li><span style="line-height: 21px; font-size: 12px;">|&nbsp;MyISAM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;YES&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;Default&nbsp;engine&nbsp;as&nbsp;of&nbsp;MySQL&nbsp;3.23&nbsp;with&nbsp;great&nbsp;performance&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;NO&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;NO&nbsp;&nbsp;&nbsp;|&nbsp;NO&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| &nbsp;</span></li><li>&nbsp;</li><li><span style="line-height: 21px; font-size: 12px;">+------------+---------+------------------------------------------------------------+--------------+------+------------+ &nbsp;</span></li><li>&nbsp;</li><li><span style="line-height: 21px; font-size: 12px;">5&nbsp;rows&nbsp;in&nbsp;set&nbsp;(0.00&nbsp;sec)&nbsp;</span></li></ol></pre><p style="line-height: 25px; padding: 0px; color: #336699; font-family: Arial, Helvetica, simsun, u5b8bu4f53; background-color: #95d2ef;"><span style="font-family: 宋体;">发现安装MySQL时没有编译进来，只能现安装了。</span></p><p style="line-height: 25px; margin: 0cm 0cm 0pt 14.2pt; padding: 0px; color: #336699; font-family: Arial, Helvetica, simsun, u5b8bu4f53; background-color: #95d2ef; text-indent: -14.2pt;"><span style="font-family: 宋体;">2.<span style="line-height: normal; font-size: 7pt; font-family: 'Times New Roman';">&nbsp;&nbsp;&nbsp;</span></span><span style="font-family: 宋体;">安装federated存储引擎</span></p><p style="line-height: 25px; padding: 0px; color: #336699; font-family: Arial, Helvetica, simsun, u5b8bu4f53; background-color: #95d2ef; text-indent: 21pt;"><span style="font-family: 宋体;">由于编译时没有选择federated，所以打算通过INSTALL PLUGIN的方式安装，正常情况下，federated是支持动态安装的：</span></p><p style="line-height: 25px; padding: 0px; color: #336699; font-family: Arial, Helvetica, simsun, u5b8bu4f53; background-color: #95d2ef;"><span style="line-height: 21px; font-family: 宋体; font-size: 9pt;">&nbsp;&nbsp;&nbsp;=== Federated Storage Engine ===</span></p><p style="line-height: 25px; padding: 0px; color: #336699; font-family: Arial, Helvetica, simsun, u5b8bu4f53; background-color: #95d2ef;"><span style="line-height: 21px; font-family: 宋体; font-size: 9pt;">&nbsp;&nbsp;Plugin Name:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;federated</span></p><p style="line-height: 25px; padding: 0px; color: #336699; font-family: Arial, Helvetica, simsun, u5b8bu4f53; background-color: #95d2ef;"><span style="line-height: 21px; font-family: 宋体; font-size: 9pt;">&nbsp;&nbsp;Description:&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Connects to tables on remote MySQL servers</span></p><p style="line-height: 25px; padding: 0px; color: #336699; font-family: Arial, Helvetica, simsun, u5b8bu4f53; background-color: #95d2ef;"><span style="line-height: 21px; font-family: 宋体; font-size: 9pt;">&nbsp;&nbsp;Supports build:&nbsp;&nbsp;&nbsp;static and dynamic</span></p><p style="line-height: 25px; padding: 0px; color: #336699; font-family: Arial, Helvetica, simsun, u5b8bu4f53; background-color: #95d2ef;"><span style="line-height: 21px; font-family: 宋体; font-size: 9pt;">&nbsp;&nbsp;Configurations:&nbsp;&nbsp;&nbsp;max, max-no-ndb</span></p><p style="line-height: 25px; padding: 0px; color: #336699; font-family: Arial, Helvetica, simsun, u5b8bu4f53; background-color: #95d2ef; text-indent: 21pt;"><span style="font-family: 宋体;">可是执行以下命令时报错：</span></p><p style="line-height: 25px; padding: 0px; color: #336699; font-family: Arial, Helvetica, simsun, u5b8bu4f53; background-color: #95d2ef; word-break: break-all;"><span style="font-family: 宋体;">SQL&gt;install plugin federated soname 'ha_federated.so';</span></p><p style="line-height: 25px; padding: 0px; color: #336699; font-family: Arial, Helvetica, simsun, u5b8bu4f53; background-color: #95d2ef; word-break: break-all;"><span style="font-family: 宋体;">ERROR 1126 (HY000): Can't open shared library '/usr/local/mysql/lib/mysql/plugin/ha_federated.so' (errno: 2 undefined symbol: dynstr_append_mem)</span></p><p style="line-height: 25px; padding: 0px; color: #336699; font-family: Arial, Helvetica, simsun, u5b8bu4f53; background-color: #95d2ef; text-indent: 21pt;"><span style="font-family: 宋体;">搜了一下，发现是个老问题，竟然到现在都没解决，可见MySQL团队的效率和管理的混乱。<a rel="nofollow" href="http://bugs.mysql.com/bug.php?id=40942" style="text-decoration: none; color: #0c4468;">http://bugs.mysql.com/bug.php?id=40942</a></span></p><p style="line-height: 25px; padding: 0px; color: #336699; font-family: Arial, Helvetica, simsun, u5b8bu4f53; background-color: #95d2ef; text-indent: 21pt;"><span style="font-family: 宋体;">没有办法了，只有重新编译MySQL源码了,</span>&nbsp;<span style="font-family: 宋体;">加上--with-plugins=federated。从5.1.26开始，默认MySQL不启用federated存储引擎，所以需要在my.cnf中加入federated选项或是在命令行用</span><span style="font-family: 宋体;">--federated</span><span style="font-family: 宋体;">选项启动mysqld。编译后的结果如下：</span></p><p style="line-height: 25px; padding: 0px; color: #336699; font-family: Arial, Helvetica, simsun, u5b8bu4f53; background-color: #95d2ef;"><span style="font-family: 宋体;">SQL&gt;show engines;</span></p><p style="line-height: 25px; padding: 0px; color: #336699; font-family: Arial, Helvetica, simsun, u5b8bu4f53; background-color: #95d2ef;">&nbsp;</p><pre style="line-height: 25px; color: #336699; background-color: #95d2ef;"><ol style="margin: 5px 0px 5px 40px; padding: 0px;"><li><span style="line-height: 21px; font-size: 12px;">+------------+---------+----------------------------------------------------------------------------+--------------+------+------------+ &nbsp;</span></li><li>&nbsp;</li><li><span style="line-height: 21px; font-size: 12px;">|&nbsp;Engine&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;Support&nbsp;|&nbsp;Comment&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;Transactions&nbsp;|&nbsp;XA&nbsp;&nbsp;&nbsp;|&nbsp;Savepoints&nbsp;| &nbsp;</span></li><li>&nbsp;</li><li><span style="line-height: 21px; font-size: 12px;">+------------+---------+----------------------------------------------------------------------------+--------------+------+------------+ &nbsp;</span></li><li>&nbsp;</li><li><span style="line-height: 21px; font-size: 12px;">|&nbsp;CSV&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;YES&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;CSV&nbsp;storage&nbsp;engine&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;NO&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;NO&nbsp;&nbsp;&nbsp;|&nbsp;NO&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| &nbsp;</span></li><li>&nbsp;</li><li><span style="line-height: 21px; font-size: 12px;">|&nbsp;MRG_MYISAM&nbsp;|&nbsp;YES&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;Collection&nbsp;of&nbsp;identical&nbsp;MyISAM&nbsp;tables&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;NO&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;NO&nbsp;&nbsp;&nbsp;|&nbsp;NO&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| &nbsp;</span></li><li>&nbsp;</li><li><span style="line-height: 21px; font-size: 12px;">|&nbsp;FEDERATED&nbsp;&nbsp;|&nbsp;YES&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;Federated&nbsp;MySQL&nbsp;storage&nbsp;engine&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;NO&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;NO&nbsp;&nbsp;&nbsp;|&nbsp;NO&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| &nbsp;</span></li><li>&nbsp;</li><li><span style="line-height: 21px; font-size: 12px;">|&nbsp;MyISAM&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;YES&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;Default&nbsp;engine&nbsp;as&nbsp;of&nbsp;MySQL&nbsp;3.23&nbsp;with&nbsp;great&nbsp;performance&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;NO&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;NO&nbsp;&nbsp;&nbsp;|&nbsp;NO&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| &nbsp;</span></li><li>&nbsp;</li><li><span style="line-height: 21px; font-size: 12px;">|&nbsp;InnoDB&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;DEFAULT&nbsp;|&nbsp;Percona-XtraDB,&nbsp;Supports&nbsp;transactions,&nbsp;row-level&nbsp;locking,&nbsp;and&nbsp;foreign&nbsp;keys&nbsp;|&nbsp;YES&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;YES&nbsp;&nbsp;|&nbsp;YES&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| &nbsp;</span></li><li>&nbsp;</li><li><span style="line-height: 21px; font-size: 12px;">|&nbsp;MEMORY&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;YES&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;Hash&nbsp;based,&nbsp;stored&nbsp;in&nbsp;memory,&nbsp;useful&nbsp;for&nbsp;temporary&nbsp;tables&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;NO&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;|&nbsp;NO&nbsp;&nbsp;&nbsp;|&nbsp;NO&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;| &nbsp;</span></li><li>&nbsp;</li><li><span style="line-height: 21px; font-size: 12px;">+------------+---------+----------------------------------------------------------------------------+--------------+------+------------+ &nbsp;</span></li></ol></pre>转自：<a href="http://blog.163.com/ji_1006/blog/static/106123412011116265531/">http://blog.163.com/ji_1006/blog/static/106123412011116265531/</a><img src ="http://www.cppblog.com/flyinghare/aggbug/199996.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/flyinghare/" target="_blank">会飞的兔子</a> 2013-05-05 22:07 <a href="http://www.cppblog.com/flyinghare/archive/2013/05/05/199996.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>SQL Error (1130): Host IP is not allowed to connect to this MySQL server</title><link>http://www.cppblog.com/flyinghare/archive/2013/05/05/199986.html</link><dc:creator>会飞的兔子</dc:creator><author>会飞的兔子</author><pubDate>Sun, 05 May 2013 10:02:00 GMT</pubDate><guid>http://www.cppblog.com/flyinghare/archive/2013/05/05/199986.html</guid><wfw:comment>http://www.cppblog.com/flyinghare/comments/199986.html</wfw:comment><comments>http://www.cppblog.com/flyinghare/archive/2013/05/05/199986.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/flyinghare/comments/commentRss/199986.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/flyinghare/services/trackbacks/199986.html</trackback:ping><description><![CDATA[<p style="word-break: break-all; line-height: 21.59375px; margin: 10px 0px; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">通过HeidiSQL连接<a href="" target="_self" style="word-break: break-all; color: #009999; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">MYSQL</strong></u></a>数据库报错：</p><p style="word-break: break-all; line-height: 21.59375px; margin: 10px 0px; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">&nbsp;SQL Error (1130): Host '192.168.1.100' is not allowed to connect to this MySQL&nbsp;<a href="" target="_self" style="word-break: break-all; color: #009999; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">server</strong></u></a></p><p style="word-break: break-all; line-height: 21.59375px; margin: 10px 0px; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">说明所连接的用户帐号没有远程连接的权限，只能在本机(localhost)登录。<br style="word-break: break-all; line-height: normal !important;" /><br style="word-break: break-all; line-height: normal !important;" />需更改 mysql&nbsp;<a href="" target="_self" style="word-break: break-all; color: #009999; line-height: normal !important;"><u style="word-break: break-all;"><strong style="word-break: break-all;">数据库</strong></u></a>里的 user表里的 host项<br style="word-break: break-all; line-height: normal !important;" />把localhost改称%<br style="word-break: break-all; line-height: normal !important;" /><br style="word-break: break-all; line-height: normal !important;" />首先按下面的步骤登录Mysql服务器<br style="word-break: break-all; line-height: normal !important;" /><br style="word-break: break-all; line-height: normal !important;" />登录mysql需要切换到dos下的mysql的bin目录，进行如下操作：<br style="word-break: break-all; line-height: normal !important;" /><br style="word-break: break-all; line-height: normal !important;" />mysql&gt;use mysql;<br style="word-break: break-all; line-height: normal !important;" /><br style="word-break: break-all; line-height: normal !important;" />mysql&gt;update user set host = '%'&nbsp;&nbsp;where user ='root';<br style="word-break: break-all; line-height: normal !important;" /><br style="word-break: break-all; line-height: normal !important;" />mysql&gt;flush privileges;<br style="word-break: break-all; line-height: normal !important;" /><br style="word-break: break-all; line-height: normal !important;" />mysql&gt;select 'host','user' from user where user='root';<br style="word-break: break-all; line-height: normal !important;" /><br style="word-break: break-all; line-height: normal !important;" />mysql&gt;quit<br style="word-break: break-all; line-height: normal !important;" /></p><p style="word-break: break-all; line-height: 21.59375px; margin: 10px 0px; font-family: Arial, Helvetica, sans-serif; font-size: 12px; background-color: #ffffff;">OK。远程连接成功！</p>转自：<a href="http://space.itpub.net/8183550/viewspace-680756">http://space.itpub.net/8183550/viewspace-680756</a><img src ="http://www.cppblog.com/flyinghare/aggbug/199986.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/flyinghare/" target="_blank">会飞的兔子</a> 2013-05-05 18:02 <a href="http://www.cppblog.com/flyinghare/archive/2013/05/05/199986.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>InnoDB的行锁模式及加锁方法和实现方式</title><link>http://www.cppblog.com/flyinghare/archive/2012/10/15/193301.html</link><dc:creator>会飞的兔子</dc:creator><author>会飞的兔子</author><pubDate>Mon, 15 Oct 2012 03:59:00 GMT</pubDate><guid>http://www.cppblog.com/flyinghare/archive/2012/10/15/193301.html</guid><wfw:comment>http://www.cppblog.com/flyinghare/comments/193301.html</wfw:comment><comments>http://www.cppblog.com/flyinghare/archive/2012/10/15/193301.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/flyinghare/comments/commentRss/193301.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/flyinghare/services/trackbacks/193301.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 摘自&nbsp;《深入浅出MySQL&#8212;&#8212;数据库开发、优化与管理维护》20.3.3 InnoDB的行锁模式及加锁方法InnoDB实现了以下两种类型的行锁。&nbsp;&nbsp;共享锁（S）：允许一个事务去读一行，阻止其他事务获得相同数据集的排他锁。&nbsp;排他锁（X)：允许获得排他锁的事务更新数据，阻止其他事务取得相同数据集的共享读锁和排他写锁。另外，为了允许行锁和...&nbsp;&nbsp;<a href='http://www.cppblog.com/flyinghare/archive/2012/10/15/193301.html'>阅读全文</a><img src ="http://www.cppblog.com/flyinghare/aggbug/193301.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/flyinghare/" target="_blank">会飞的兔子</a> 2012-10-15 11:59 <a href="http://www.cppblog.com/flyinghare/archive/2012/10/15/193301.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>跑步的好处</title><link>http://www.cppblog.com/flyinghare/archive/2012/05/15/174954.html</link><dc:creator>会飞的兔子</dc:creator><author>会飞的兔子</author><pubDate>Tue, 15 May 2012 03:36:00 GMT</pubDate><guid>http://www.cppblog.com/flyinghare/archive/2012/05/15/174954.html</guid><wfw:comment>http://www.cppblog.com/flyinghare/comments/174954.html</wfw:comment><comments>http://www.cppblog.com/flyinghare/archive/2012/05/15/174954.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/flyinghare/comments/commentRss/174954.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/flyinghare/services/trackbacks/174954.html</trackback:ping><description><![CDATA[<span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; ">1.告别臃肿身材。&nbsp;</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; ">许多人开始跑步就是因为减肥，跑步确实减肥的最好运动方式，跑步每分钟比起其他运动燃烧更多的卡路里。&nbsp;</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; ">2.防止你的骨骼，肌肉退化。&nbsp;</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; ">我们的骨骼是和你的身体需求相互协调的。长期坐在显示器前的我们让我们的骨骼越来越脆弱。而长期的，经常的运动会使你的骨骼保持健康。更进一步说就是防止我们身体内部老化的更快。经常的高强度锻炼，例如跑步，被证明可以促进人体荷尔蒙的生长，荷尔蒙就是那些名人为了看起来更年轻而持续注射的药剂。&nbsp;</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; ">3.抵抗疾病&nbsp;</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; ">跑步可以降低得中风和乳腺癌的风险。经常的跑步已经成为医生对那些容易引发或在已经处在早期的骨质疏松，糖尿病，高血压病人的治疗建议。&nbsp;</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; ">4.维持并提高总体的身体水平。&nbsp;</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; ">跑步是是人们可以采取的最好的锻炼身体的运动。它可以提高胆固醇,降低血液凝块的危险，锻炼你的50%的经常处于闲置状态的肺。跑步还可以通过增加你的淋巴细胞来增强你的免疫力。&nbsp;</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; ">5.让你更加自信。&nbsp;</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; ">慢跑像其他一些单人运动一样，它可以增强你的自信心。跑步让你完成一次又一次的尝试，让你变得更强大，更加肯定自己。他让你真实的越过某个山峰，穿过某个障碍.在意识到你的身体已经更加强壮，更加有用，你会得到被赋予力量和自由的感觉。自信更是那些通过跑步成功的减肥并得到自己心中理想身材的跑步者的宝贵财富。&nbsp;</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; ">6.放松自己，减轻压力。&nbsp;</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; ">慢跑可以转移聂注意力，沐浴在路旁的风景中，你的烦恼一定会消失殆尽。&nbsp;</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; ">长跑适合那些正处在一堆头疼，恼人的烦心事的人。还有比在两个小时的长跑中，清理的的头脑、舒缓自己的神经更好的主意了吗。&nbsp;</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; ">如果你此时觉得异常压抑，何不快跑一下呢，之后你会一个好的心情。&nbsp;</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; ">7.著名的&#8220;跑步者高峰体验&#8221;&nbsp;</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; ">包括释放压力，慢跑被证明提高你的心态。跑步，特别在户外和旅行中,会使身体释放一种物质让你产生一种幸福愉悦感（跑步者高峰体验）或者就是快乐的感觉。跑步已经被采用了多年来治疗临床抑郁症，上瘾等。更少的压力，更少的压抑，更少的疲劳，更少的混乱，经过一段时间的经常跑步，病人很快就有了变化。跑步让他们有了注意的对象，让他们看到了除了他们消极的状态和沉溺的事务，还有一些美好的东西的存在。&nbsp;</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; ">8.锻炼你的头脑。&nbsp;</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; ">像对你的身体有所帮助一样，跑步同样对你的头脑很有帮助。通过在跑步中克服一系列的障碍，你学会了专注和决心.在经历那些你几乎要放弃的长跑或其他项目后你会发现：你在跑步过程中产生的意志和体魄的增强让你在其他方面有着同样的专注和决心。&nbsp;</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; ">9.增强合作精神。&nbsp;</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; ">又是一个非常值得去做的好处。这点好处或许让很多人感到惊奇，因为人们认为跑步不可能得到这种益处，仅仅由于跑步是单人运动。但是跑步确实有时涉及到互相合作。旅行跑步，特别是在那些路况不好的地方，需要极大的合作意识。这些路面经常会有一些 障碍如石头、灌木让跑步进行的很困难。&nbsp;</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; ">10.随时随地，简单。&nbsp;</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; ">不是很多的运动可以在任何地方，几乎不需要设备的。我敢肯定古代希腊人会争辩说甚至是鞋子和衣服也不需要。今天，我们只是需要一双好点的跑步鞋然后就可以出发了。从市中心到郊区,整个世界的地方等待你的探索。经常出差吗？你的旅行箱里肯定会有空间来装你的运动鞋的。这个世界就是你的健身房，去再次发现它吧。&nbsp;</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; ">Here are some tips for how to make running a practice:&nbsp;</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; ">Be consistent in your running program. Plan your weekly workout schedule and stick to it. This will teach you persistence.&nbsp;</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; ">Know which focuses you'll use during every run. This will teach you planning and mindfulness, and improve your mind/body connection.&nbsp;</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; ">Constantly practice relaxing your muscles. This will help to relieve tension and train you to relax no matter what activity you're doing.&nbsp;</span><br style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; " /><span style="color: #111111; font-family: Arial, Helvetica, sans-serif; font-size: 13px; background-color: #ffffff; ">At the end of your run, spend a few minutes doing an "end-of-run review." Ask yourself how well you did with keeping your focuses, how your body felt during the run. What did you come away with that will help your next run? Then, the next time you go out for a run, you'll have something to work on that you brought forward from your last run. In this way you'll build a healthy, growing and sustainable running program.&nbsp;</span>&nbsp;<br />转自：<a href="http://www.douban.com/group/topic/20749798/">http://www.douban.com/group/topic/20749798/</a><img src ="http://www.cppblog.com/flyinghare/aggbug/174954.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/flyinghare/" target="_blank">会飞的兔子</a> 2012-05-15 11:36 <a href="http://www.cppblog.com/flyinghare/archive/2012/05/15/174954.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>用命令行设置MYSQL字符集 </title><link>http://www.cppblog.com/flyinghare/archive/2012/05/08/174001.html</link><dc:creator>会飞的兔子</dc:creator><author>会飞的兔子</author><pubDate>Tue, 08 May 2012 09:12:00 GMT</pubDate><guid>http://www.cppblog.com/flyinghare/archive/2012/05/08/174001.html</guid><wfw:comment>http://www.cppblog.com/flyinghare/comments/174001.html</wfw:comment><comments>http://www.cppblog.com/flyinghare/archive/2012/05/08/174001.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/flyinghare/comments/commentRss/174001.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/flyinghare/services/trackbacks/174001.html</trackback:ping><description><![CDATA[<span style="color: #555555; font-family: 'ms shell dlg'; font-size: 12px; line-height: 22px; text-align: justify; background-color: #ffffff; ">MySQL 4.1的字符集支持(Character Set Support)有两个方面：字符集(Character set)和排序方式(Collation)。对于字符集的支持细化到四个层次: 服务器(server)，数据库(database)，数据表(table)和连接(connection)。</span><br style="clear: both; color: #555555; font-family: 'ms shell dlg'; font-size: 12px; line-height: 22px; text-align: justify; background-color: #ffffff; " /><br style="clear: both; color: #555555; font-family: 'ms shell dlg'; font-size: 12px; line-height: 22px; text-align: justify; background-color: #ffffff; " /><p style="color: #555555; font-family: 'ms shell dlg'; font-size: 12px; line-height: 22px; text-align: justify; background-color: #ffffff; ">查看系统的字符集和排序方式的设定可以通过下面的两条命令：<br style="clear: both; " /></p><blockquote style="color: #555555; font-family: 'ms shell dlg'; font-size: 12px; line-height: 22px; text-align: justify; background-color: #ffffff; "><em>mysql&gt; SHOW VARIABLES LIKE 'character_set_%';</em><br style="clear: both; " /><em>+--------------------------+----------------------------+</em><br style="clear: both; " /><em>| Variable_name | Value |</em><br style="clear: both; " /><em>+--------------------------+----------------------------+</em><br style="clear: both; " /><em>| character_set_client | latin1 |</em><br style="clear: both; " /><em>| character_set_connection | latin1 |</em><br style="clear: both; " /><em>| character_set_database | latin1 |</em><br style="clear: both; " /><em>| character_set_results | latin1 |</em><br style="clear: both; " /><em>| character_set_server | latin1 |</em><br style="clear: both; " /><em>| character_set_system | utf8 |</em><br style="clear: both; " /><em>| character_sets_dir | /usr/share/mysql/charsets/ |</em><br style="clear: both; " /><em>+--------------------------+----------------------------+</em><br style="clear: both; " /><em>7 rows in set (0.00 sec)</em><p style="font-style: italic; ">mysql&gt; SHOW VARIABLES LIKE 'collation_%';&nbsp;<br style="clear: both; " />+----------------------+-------------------+<br style="clear: both; " />| Variable_name | Value |<br style="clear: both; " />+----------------------+-------------------+<br style="clear: both; " />| collation_connection | latin1_swedish_ci |<br style="clear: both; " />| collation_database | latin1_swedish_ci |<br style="clear: both; " />| collation_server | latin1_swedish_ci |<br style="clear: both; " />+----------------------+-------------------+<br style="clear: both; " />3 rows in set (0.00 sec)<br style="clear: both; " /><br style="clear: both; " />上面列出的值就是系统的默认值。<br style="clear: both; " /><br style="clear: both; " />一般就算设置了表的默认字符集为utf8并且通过UTF-8编码发送查询，你会发现存入数据库的仍然是乱码。问题就出在这个connection连接层上。解决方法是在发送查询前执行一下下面这句：</p><p style="font-style: italic; ">SET NAMES 'utf8';</p><p><em>它相当于下面的三句指令：</em><br style="clear: both; " /><em>SET character_set_client = utf8;</em><br style="clear: both; " /><em>SET character_set_results = utf8;</em><br style="clear: both; " /><em>SET character_set_connection = utf8;</em><br style="clear: both; " /><br style="clear: both; " /><em>而MySQL数据库的4.1是一个分水岭，4.1直接支持Unicode，它以下版本支持的不好；&nbsp;</em><br style="clear: both; " /><br style="clear: both; " /><em>MySQL JDBC Driver的3.0.16也是一个分水岭，3.0.16版本会取数据库本身的编码，然后按照该编码转换，这种方式和Oracle的JDBC Driver是一样的。例如你的数据库是GBK编码的话，JDBC Driver就会把数据库里面的取出来的字符串按照GBK往unicode转换，送给JVM。因此正确的设置数据库本身的编码就尤为重要。&nbsp;</em><br style="clear: both; " /><br style="clear: both; " /><em>MySQL JDBC Driver3.0.16以下的版本则不然，它不会那么智能的根据数据库编码来确定如何转换，它总是默认使用ISO8859-1，因此你必须使用 characterEncoding=GBK来强制他把数据库中取出来的字符串按照GBK来往unicode转换。&nbsp;</em><br style="clear: both; " /><br style="clear: both; " /><em>因此，使用什么数据库版本，不管是3.x，还是4.0.x还是4.1.x，其实对我们来说不重要，重要的有二：&nbsp;</em><br style="clear: both; " /><br style="clear: both; " /><em>1) 正确的设定数据库编码，MySQL4.0以下版本的字符集总是默认ISO8859-1，MySQL4.1在安装的时候会让你选择。如果你准备使用UTF- 8，那么在创建数据库的时候就要指定好UTF-8(创建好以后也可以改，4.1以上版本还可以单独指定表的字符集)&nbsp;</em><br style="clear: both; " /><br style="clear: both; " /><em>2) 使用3.0.16以上版本的JDBC Driver，那么你就不需要再写什么characterEncoding=UTF-8</em><br /><br /><br /><strong>转自：</strong></p><a href="http://www.blogjava.net/bonix/articles/159291.html"><strong>http://www.blogjava.net/bonix/articles/159291.html</strong></a></blockquote><img src ="http://www.cppblog.com/flyinghare/aggbug/174001.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/flyinghare/" target="_blank">会飞的兔子</a> 2012-05-08 17:12 <a href="http://www.cppblog.com/flyinghare/archive/2012/05/08/174001.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>MySQL存储引擎</title><link>http://www.cppblog.com/flyinghare/archive/2012/04/01/169766.html</link><dc:creator>会飞的兔子</dc:creator><author>会飞的兔子</author><pubDate>Sun, 01 Apr 2012 03:10:00 GMT</pubDate><guid>http://www.cppblog.com/flyinghare/archive/2012/04/01/169766.html</guid><wfw:comment>http://www.cppblog.com/flyinghare/comments/169766.html</wfw:comment><comments>http://www.cppblog.com/flyinghare/archive/2012/04/01/169766.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/flyinghare/comments/commentRss/169766.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/flyinghare/services/trackbacks/169766.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: MySQL5.5以后默认使用InnoDB存储引擎，其中InnoDB和BDB提供事务安全表，其它存储引擎都是非事务安全表。若要修改默认引擎，可以修改配置文件中的default-storage-engine。可以通过：show variables like 'default_storage_engine';查看当前数据库到默认引擎。命令：show engines和show variables like...&nbsp;&nbsp;<a href='http://www.cppblog.com/flyinghare/archive/2012/04/01/169766.html'>阅读全文</a><img src ="http://www.cppblog.com/flyinghare/aggbug/169766.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/flyinghare/" target="_blank">会飞的兔子</a> 2012-04-01 11:10 <a href="http://www.cppblog.com/flyinghare/archive/2012/04/01/169766.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>通过 mysql 的 INFORMATION_SCHEMA信息数据库得到元数据</title><link>http://www.cppblog.com/flyinghare/archive/2012/03/26/169036.html</link><dc:creator>会飞的兔子</dc:creator><author>会飞的兔子</author><pubDate>Mon, 26 Mar 2012 10:08:00 GMT</pubDate><guid>http://www.cppblog.com/flyinghare/archive/2012/03/26/169036.html</guid><wfw:comment>http://www.cppblog.com/flyinghare/comments/169036.html</wfw:comment><comments>http://www.cppblog.com/flyinghare/archive/2012/03/26/169036.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/flyinghare/comments/commentRss/169036.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/flyinghare/services/trackbacks/169036.html</trackback:ping><description><![CDATA[&nbsp;&nbsp;&nbsp;&nbsp; 摘要: 23.1. INFORMATION_SCHEMA表23.1.1. INFORMATION_SCHEMA SCHEMATA表23.1.2. INFORMATION_SCHEMA TABLES表23.1.3. INFORMATION_SCHEMA COLUMNS表23.1.4. INFORMATION_SCHEMA STATISTICS表23.1.5. INFORMATION_SCHEMA USER_...&nbsp;&nbsp;<a href='http://www.cppblog.com/flyinghare/archive/2012/03/26/169036.html'>阅读全文</a><img src ="http://www.cppblog.com/flyinghare/aggbug/169036.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/flyinghare/" target="_blank">会飞的兔子</a> 2012-03-26 18:08 <a href="http://www.cppblog.com/flyinghare/archive/2012/03/26/169036.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>MySQL 的事件探查器 mysql-proxy</title><link>http://www.cppblog.com/flyinghare/archive/2012/03/14/167863.html</link><dc:creator>会飞的兔子</dc:creator><author>会飞的兔子</author><pubDate>Wed, 14 Mar 2012 03:38:00 GMT</pubDate><guid>http://www.cppblog.com/flyinghare/archive/2012/03/14/167863.html</guid><wfw:comment>http://www.cppblog.com/flyinghare/comments/167863.html</wfw:comment><comments>http://www.cppblog.com/flyinghare/archive/2012/03/14/167863.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/flyinghare/comments/commentRss/167863.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/flyinghare/services/trackbacks/167863.html</trackback:ping><description><![CDATA[<p style="line-height: normal; color: #333333; font-family: Arial; font-size: 13px; background-color: #ffffff; ">是不是一直为怎样调试 MySQL 上的应用程序而苦恼？现在有个工具可以让我们脱离苦海了--MySQL Proxy，从名称上就可以看出来是 MySQL 代理，可以作为 MySQL 服务器和客户端的中介，因为使用 MySQL 的网络协议，所以所有兼容该协议的 MySQL 客户端都不需要做修改就可以直接连接。除了转发外，还可以监控、过滤和修改客户端与服务器之间的通信数据，MySQL Proxy 以 lua 作为脚本语言。<br />&nbsp;&nbsp;&nbsp; 支持 MySQL 5.0.x 以上版本，可以实现类似 MSSQL 的事件探器功能。<br /><br /><strong>安装：</strong><br />有 Linux 和 Windows 平台的二进制包下载，解开直接使用即可。<br /><br />主要命令行选项：<br />--help-all &#8212; 显示所有帮助选项。&nbsp;<br />--proxy-backend-addresses=host:port &#8212; 要连接的 MySQL 服务器地址和端口，可以接多个服务器，请求会以轮询的方式进行转发。<br />--proxy-lua-script=file 要载入的 lua 脚本文件。</p><p style="line-height: normal; color: #333333; font-family: Arial; font-size: 13px; background-color: #ffffff; "><br /><strong>安装：</strong><br />有 Linux 和 Windows 平台的二进制包下载，解开直接使用即可。<br /><br />主要命令行选项：<br />--help-all &#8212; 显示所有帮助选项。&nbsp;<br />--proxy-backend-addresses=host:port &#8212; 要连接的 MySQL 服务器地址和端口，可以接多个服务器，请求会以轮询的方式进行转发。<br />--proxy-lua-script=file 要载入的 lua 脚本文件。<br /><br /><strong>示例:</strong><br />F:\mysql-proxy-0.8.0-win32-x86\bin\mysql-proxy --proxy-backend-addresses=192.168.128.131:3306 --proxy-lua-script=F:/mysql-proxy-0.8.0-win32-x86/share/doc/mysql-proxy/tutorial-query-time.lua</p><p style="line-height: normal; color: #333333; font-family: Arial; font-size: 13px; background-color: #ffffff; "><img src="http://www.cppblog.com/images/cppblog_com/flyinghare/ff73dab48e6ba24b8bd4b2ad.jpg" width="664" height="425" alt="" /><br /></p><p style="line-height: normal; color: #333333; font-family: Arial; font-size: 13px; background-color: #ffffff; ">注：自带的这个示例脚本可以显示收到的 SQL 操作请求和执行时间，也可以自己编写脚本<br /><br />客户端连接<br />跟平常连服务器一样，只是默认端口是 4040，连接后就可以进行 SQL 操作了，相应命令会显示在 Proxy 上。</p><p style="line-height: normal; color: #333333; font-family: Arial; font-size: 13px; background-color: #ffffff; ">各种版本官网下载地址：<a href="http://dev.mysql.com/downloads/mysql-proxy/" style="color: #999999 !important; border-bottom-color: #f8f8f8 !important; border-bottom-width: 2px !important; border-bottom-style: solid !important; text-decoration: none; ">http://dev.mysql.com/downloads/mysql-proxy/<br /><br /><br />转自</a>：<a href="http://hi.baidu.com/bkitty/blog/item/e627b938cbd03aced56225f2.html">http://hi.baidu.com/bkitty/blog/item/e627b938cbd03aced56225f2.html</a></p><img src ="http://www.cppblog.com/flyinghare/aggbug/167863.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/flyinghare/" target="_blank">会飞的兔子</a> 2012-03-14 11:38 <a href="http://www.cppblog.com/flyinghare/archive/2012/03/14/167863.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item><item><title>VC的MySQL编程</title><link>http://www.cppblog.com/flyinghare/archive/2012/03/13/167793.html</link><dc:creator>会飞的兔子</dc:creator><author>会飞的兔子</author><pubDate>Tue, 13 Mar 2012 10:00:00 GMT</pubDate><guid>http://www.cppblog.com/flyinghare/archive/2012/03/13/167793.html</guid><wfw:comment>http://www.cppblog.com/flyinghare/comments/167793.html</wfw:comment><comments>http://www.cppblog.com/flyinghare/archive/2012/03/13/167793.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/flyinghare/comments/commentRss/167793.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/flyinghare/services/trackbacks/167793.html</trackback:ping><description><![CDATA[<br /><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">一、在你的程序中使用数据库是不错的注意。如果已经有可用的MySQL服务器，在VC中可以按照如下方法实现与数据库的连接。<br />1、找来MySQL(Win32)安装目录下的include文件夹，将其添加到VC头文件目录列表中；<br />（VC6 -&gt; Options -&gt;&nbsp;Directories -&gt; 加入此目录）<br />（VC2005 -&gt;&nbsp;工具 -&gt;&nbsp;选择 -&gt;项目和解决方案 -&gt; VC++目录 -&gt;&nbsp;显示以下內容的目录 -&gt;&nbsp;包含文件 -&gt; 加入此目录）2、找来MySQL(Win32)安装目录下的lib文件夹，将&nbsp;其添加到VC库文件目录列表中；<br />（VC6 -&gt; Options -&gt;&nbsp;Directories -&gt; 加入此目录）<br />（VC2005 -&gt;&nbsp;工具 -&gt;选择 -&gt;&nbsp;项目和解決方案 -&gt; VC++目录 -&gt;&nbsp;显示以下內容的目录 -&gt;&nbsp;库文件 -&gt; 加入此目录，注意是lib/debug或lib/opt）<br />3、新建一个工程，参考如下代码：<br />// mysql.cpp : Defines the entry point for the console application.<br /><br />#include "stdafx.h"<br />#include &lt;stdio.h&gt;<stdio.h></stdio.h><br />#include &lt;winsock.h&gt;<winsock.h></winsock.h><br />#include &lt;mysql.h&gt;<mysql.h></mysql.h><br />#include &lt;windows.h&gt;<br />#pragma comment(lib, "libmysql.lib")<br />int main(int argc, char* argv[])<br />{<br />&nbsp;&nbsp;&nbsp; unsigned short Port = 3306;<br />&nbsp;&nbsp;&nbsp; char *IPAddress = "192.168.31.56";<br />&nbsp;&nbsp;&nbsp; char *UserName = "root";<br />&nbsp;&nbsp;&nbsp; char *Password = "";<br />&nbsp;&nbsp;&nbsp; char *DBName = "SAS_1_2_0";<br />&nbsp;&nbsp;&nbsp; printf("Start... ");<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp; MYSQL *ssock;<br />&nbsp;&nbsp;&nbsp; //char execsql[500];<br />&nbsp;&nbsp;&nbsp; ssock = (MYSQL *)malloc(sizeof(MYSQL));&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp; //在某些版本中，不需要该初始化工作，可观看mysql.H以及readme<br />&nbsp;&nbsp;&nbsp; mysql_init(ssock);<br />&nbsp;&nbsp;&nbsp; if(ssock == NULL)<br />&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("EROR: MySQL ssock init error. ");<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return FALSE;<br />&nbsp;&nbsp;&nbsp; }<br /><br />&nbsp;&nbsp;&nbsp; //连接到指定的数据库<br />&nbsp;&nbsp;&nbsp; ssock = mysql_real_connect(ssock, IPAddress, UserName, Password, NULL, Port, NULL, 0);<br />&nbsp;&nbsp;&nbsp; if(!ssock)<br />&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("conn fail... ");<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //memcpy(eee, mysql_error(ssock), 20);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //fprintf(stderr, "Failed to connect to database: Error: %s ", mysql_error(ssock));<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //printf("%c ", eee);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; unsigned int mtint = mysql_errno(ssock);<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; //printf("%d ");<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return FALSE;<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; if(mysql_select_db(ssock, DBName) != 0)<br />&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("select db error. ");<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return FALSE;<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; printf("version=%d ", mysql_get_server_version(ssock));<br />&nbsp;&nbsp;&nbsp; //exec my execsql string<br />&nbsp;&nbsp;&nbsp; //sprintf(execsql,"create table girls (name char(10),age int)");<br />&nbsp;&nbsp;&nbsp; //mysql_real_query(ssock,execsql,strlen(execsql));<br />&nbsp;&nbsp;&nbsp; mysql_close(ssock);<br />&nbsp;&nbsp;&nbsp; printf("End... ");<br />&nbsp;&nbsp;&nbsp; return TRUE;<br />}&nbsp;</p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">二、怎样用c/c++编程连接mysql数据库<br />&nbsp;&nbsp;&nbsp;&nbsp; 执行一个查询有以下几个步骤要做。首先执行一个查询，然后保存结果，&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp; &nbsp; 得到的是一个子集。这里是一个小例子：&nbsp;&nbsp;&nbsp;<br />&nbsp; #include&nbsp;&nbsp;&nbsp;&lt;stdio.h&gt;&nbsp;&nbsp;<br />&nbsp; #include&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp; #include&nbsp;&nbsp; &lt;mysql.h&gt;<br />&nbsp; MYSQL&nbsp;&nbsp; mysql;&nbsp;&nbsp;&nbsp;<br />&nbsp; MYSQL_RES&nbsp;&nbsp; *res;&nbsp;&nbsp;&nbsp;<br />&nbsp; MYSQL_ROW&nbsp;&nbsp; row;&nbsp;&nbsp;&nbsp;<br />&nbsp; void&nbsp;&nbsp; exiterr(int&nbsp;&nbsp; exitcode)&nbsp;&nbsp;&nbsp;<br />&nbsp; {&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; fprintf(&nbsp;&nbsp; stderr,&nbsp;&nbsp; "%s/n",&nbsp;&nbsp; mysql_error(&amp;mysql)&nbsp;&nbsp; );&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;exit(&nbsp;&nbsp; exitcode&nbsp;&nbsp; );&nbsp;&nbsp;&nbsp;<br />&nbsp; }&nbsp;&nbsp;&nbsp;<br />&nbsp; int&nbsp;&nbsp; main()&nbsp;&nbsp;&nbsp;<br />&nbsp; {&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; uint&nbsp;&nbsp; i&nbsp;&nbsp; =&nbsp;&nbsp; 0;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if&nbsp;&nbsp; (!(mysql_connect(&amp;mysql,"host","username","password")))&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; exiterr(1);&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if&nbsp;&nbsp; (mysql_select_db(&amp;mysql,"payroll"))&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;exiterr(2);&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; if&nbsp;&nbsp; (mysql_query(&amp;mysql,"SELECT&nbsp;&nbsp; name,rate&nbsp;&nbsp; FROM&nbsp;&nbsp; emp_master"))&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;exiterr(3);&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;if&nbsp;&nbsp; (!(res&nbsp;&nbsp; =&nbsp;&nbsp; mysql_store_result(&amp;mysql)))&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;exiterr(4);&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;while((row&nbsp;&nbsp; =&nbsp;&nbsp; mysql_fetch_row(res)))&nbsp;&nbsp; {&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; for&nbsp;&nbsp; (i=0&nbsp;&nbsp; ;&nbsp;&nbsp; i&nbsp;&nbsp; &lt;&nbsp;&nbsp; mysql_num_fields(res);&nbsp;&nbsp; i++)&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; printf("%s/n",row[i]);&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; mysql_free_result(res);&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;mysql_close(&amp;mysql);&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;mysql_query&nbsp;&nbsp; 函数将把查询送给服务器，如果查询成功，调用mysql_store_result 函数将分配一个MYSQL_RES&nbsp;&nbsp; 结构并且重新从服务器获得一个结果集。<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 你可以用mysql_fetch_row&nbsp;&nbsp; 函数来查看数据。这样做你将获得一个&nbsp;&nbsp;&nbsp;MYSQL_ROW&nbsp;&nbsp; 指针指向数据中的一行。&nbsp;&nbsp; MYSQL_ROW&nbsp;&nbsp; 指针是一简单的字符串数组。所有的数据类型被转换成字符串送到客户端。&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;mysql_num_fields函数将告诉你返回的列数。你可以继续调用mysql_fetch_row直到它返回一个空指针以得到查询中的每一行。&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 注意在这个例子里，我们没有检查有空指针的列。如果你不使用非空列的表，那么你必须检查一个特殊行的列是否为空。一旦你使用完毕一个结果集，你必须释放它。这通过&nbsp;&nbsp; mysql_free_result&nbsp;&nbsp; 来完成。&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 最后调用mysql_close来关闭你和数据库之间的连接。&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 查看结果集你可以不用调用mysql_fetch_row就查出返回的结果集共有多少行。这由<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; int&nbsp;&nbsp; mysql_num_rows(MYSQL_RES&nbsp;&nbsp; *result)来完成。&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 改变到被下一个&nbsp;&nbsp; mysql_fetch_row&nbsp;&nbsp; 调用返回的行，你可以用void&nbsp;&nbsp; mysql_data_seek(MYSQL_RES&nbsp;&nbsp; *res,&nbsp;&nbsp; uint&nbsp;&nbsp; offset)&nbsp;&nbsp; 改变到任意一行。&nbsp; 获得更多的信息 你可以使用这几个额外的函数来找出关于一个查询的更多的信息，并从服务器获得这些信息。&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 如果你执行一个UPDATE，&nbsp;&nbsp; INSERT&nbsp;&nbsp; 或者&nbsp;&nbsp; DELETE&nbsp;&nbsp; 查询，你可以用int&nbsp;&nbsp; mysql_affected_rows&nbsp;&nbsp; 来查出共有多少行数据被你影响到。&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;如果在你的数据库里有二进制数据，那么得知数据的长度将是有用的。unsigned&nbsp;&nbsp;int&nbsp;&nbsp; *mysql_fetch_lengths(MYSQL_RES&nbsp;&nbsp; *mysql)&nbsp;&nbsp; 将返回一指出了结果集中每一列 的长度的整型数组。&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp; &nbsp; 当你插入一个带有&nbsp;&nbsp; AUTO_INCREMENT&nbsp;&nbsp; 列的表的时候，你可以用int&nbsp;&nbsp; mysql_insert_id(MYSQL&nbsp;&nbsp; *mysql)&nbsp;&nbsp; 来查出生成的那一行的ID。&nbsp;&nbsp;&nbsp;<br />======================<br /></p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">int main()<br />{<br />&nbsp;&nbsp; &nbsp;MYSQL mysql;<br />&nbsp;&nbsp;&nbsp; MYSQL_RES * res ;&nbsp;<br />&nbsp;&nbsp;&nbsp; MYSQL_FIELD * fd ;&nbsp;<br />&nbsp;&nbsp;&nbsp; MYSQL_ROW row ;&nbsp;<br />&nbsp;&nbsp; &nbsp;int id[10000];<br />&nbsp;&nbsp;&nbsp; double result[10000][8];<br />&nbsp;&nbsp; &nbsp;vector&lt;string&gt; v;</p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">&nbsp;&nbsp;&nbsp; if(mysql_init(&amp;mysql) == NULL)<br />&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp; &nbsp;&nbsp;std::cout&lt;&lt;"init mysql data status fail"&lt;&lt;std::endl;<br />&nbsp;&nbsp;&nbsp;&nbsp; &nbsp;&nbsp;return false;<br />&nbsp; &nbsp;}&nbsp;<br />&nbsp;else<br />&nbsp;{<br />&nbsp;&nbsp;std::cout&lt;&lt;"init mysql data status success"&lt;&lt;std::endl;<br />&nbsp;}<br />&nbsp;<br />&nbsp;if(NULL == mysql_real_connect(&amp;mysql,"localhost","root","","wsnss",MYSQL_PORT,NULL,0))<br />&nbsp;{<br />&nbsp;&nbsp;std::cout&lt;&lt;"connect database fail"&lt;&lt;std::endl&lt;&lt;mysql_error(&amp;mysql)&lt;&lt;std::endl;;<br />&nbsp;&nbsp;return false;<br />&nbsp;}<br />&nbsp;else{<br />&nbsp;&nbsp;std::cout&lt;&lt;"connect database success"&lt;&lt;std::endl;<br />&nbsp;}</p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">&nbsp;char&nbsp;&nbsp; szSqlText[500]="";&nbsp;<br />&nbsp;int j = 0;</p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">&nbsp;sprintf(szSqlText,"%s","select * from data_receive ");&nbsp;<br />&nbsp;if (mysql_query( &amp;mysql, szSqlText))&nbsp;<br />&nbsp;//进行数据检索&nbsp;<br />&nbsp;{&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp; //执行SQL语句出错&nbsp;<br />&nbsp;&nbsp;cout&lt;&lt;"query error"&lt;&lt;endl;<br />&nbsp;&nbsp;mysql_close( &amp;mysql ) ;&nbsp;<br />&nbsp;&nbsp;return FALSE ;&nbsp;<br />&nbsp;}&nbsp;<br />&nbsp;&nbsp;&nbsp; else&nbsp;<br />&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;res = mysql_store_result( &amp;mysql ) ;&nbsp;<br />&nbsp;&nbsp;int i; &nbsp;&nbsp;<br />&nbsp;&nbsp;while((row&nbsp;&nbsp; =&nbsp;&nbsp; mysql_fetch_row(res)))&nbsp;&nbsp; {&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;id[j] = atoi(row[0]);<br />&nbsp;&nbsp;&nbsp; for&nbsp;&nbsp; (i = 1; i &lt; mysql_num_fields(res); i++)&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp; {<br />&nbsp;&nbsp;&nbsp;&nbsp; result[j][i-1] =&nbsp; atof(row[i]);<br />&nbsp;&nbsp;&nbsp; }<br />&nbsp;&nbsp;&nbsp; j++;<br />&nbsp;&nbsp;}<br />&nbsp;&nbsp;&nbsp; }&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;&nbsp;<br />&nbsp;&nbsp;<br />&nbsp;for(int i = 0 ; i &lt; 10000; i++)<br />&nbsp;{<br />&nbsp;&nbsp;if(i&gt;=j)<br />&nbsp;&nbsp;&nbsp;break;<br />&nbsp;&nbsp;char str[10000];<br />&nbsp;&nbsp;stringstream ss;</p><p style="color: #333333; font-family: Arial; line-height: 26px; text-align: left; background-color: #ffffff; ">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; ss&lt;&lt;"insert into data_receive(ID,data1,data2,data3,&nbsp;data4,data5,data6,data7,data8)values('"&lt;&lt;id[i]&lt;&lt;"','"&lt;&lt;<br />&nbsp;&nbsp;&nbsp;result[i][0]&lt;&lt;"','"&lt;&lt;result[i][1]&lt;&lt;"','"&lt;&lt;result[i][2]&lt;&lt;"','"&lt;&lt;<br />&nbsp;&nbsp;&nbsp;result[i][3]&lt;&lt;"','"&lt;&lt;result[i][4]&lt;&lt;"','"&lt;&lt;result[i][5]&lt;&lt;"','"&lt;&lt;<br />&nbsp;&nbsp;&nbsp;result[i][6]&lt;&lt;"','"&lt;&lt;result[i][7]&lt;&lt;"');";<br />&nbsp;&nbsp;string s = ss.str();<br />&nbsp;&nbsp;v.push_back(s);&nbsp;&nbsp;<br />&nbsp;}<br />&nbsp;for(vector&lt;string&gt;::iterator iter = v.begin();&nbsp; iter != v.end(); ++iter)<br />&nbsp;{<br />&nbsp;&nbsp;<br />&nbsp;&nbsp;if(mysql_query(&amp;mysql,(*iter).c_str())!=0)<br />&nbsp;&nbsp;{<br />&nbsp;&nbsp;&nbsp;std::cout&lt;&lt;"execute insert syntax fail"&lt;&lt;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;std::endl&lt;&lt;mysql_error(&amp;mysql)&lt;&lt;endl;<br />&nbsp;&nbsp;&nbsp;mysql_close(&amp;mysql);<br />&nbsp;&nbsp;&nbsp;return 1;<br />&nbsp;&nbsp;}<br />&nbsp;}<br />&nbsp;&nbsp;&nbsp; mysql_free_result(res);<br />&nbsp;&nbsp;&nbsp; mysql_close(&amp;mysql);<br />&nbsp;&nbsp;&nbsp; return 0;<br />}&nbsp;</p>转自：<a href="http://blog.csdn.net/ztj111/article/details/2512147">http://blog.csdn.net/ztj111/article/details/2512147</a><img src ="http://www.cppblog.com/flyinghare/aggbug/167793.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/flyinghare/" target="_blank">会飞的兔子</a> 2012-03-13 18:00 <a href="http://www.cppblog.com/flyinghare/archive/2012/03/13/167793.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>