<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0">
<channel>
<title><![CDATA[BIWEB开源PHP WMS系统创始人ArthurXF肖飞的blog]]></title> 
<link>http://www.bizeway.net/index.php</link> 
<description><![CDATA[网务通 - 网务公司发展之路]]></description> 
<language>zh-cn</language> 
<copyright><![CDATA[BIWEB开源PHP WMS系统创始人ArthurXF肖飞的blog]]></copyright>
<item>
<link>http://www.bizeway.net/read.php?</link>
<title><![CDATA[MySQL数据库存储引擎详解]]></title> 
<author>ArthurXF &lt;arthurxf@gmail.com&gt;</author>
<category><![CDATA[MySQL]]></category>
<pubDate>Sun, 12 Aug 2007 14:59:24 +0000</pubDate> 
<guid>http://www.bizeway.net/read.php?</guid> 
<description>
<![CDATA[ 
	<strong>存储引擎是什么？</strong><br/><br/>MySQL中的数据用各种不同的技术存储在文件(或者内存)中。这些技术中的每一种技术都使用不同的存储机制、索引技巧、锁定水平并且最终提供广泛的不同的功能和能力。 &nbsp; <br/> &nbsp;<br/>通过选择不同的技术，你能够获得额外的速度或者功能，从而改善你的应用的整体功能。<br/><br/>例如，如果你在研究大量的临时数据，你也许需要使用内存存储引擎。内存存储引擎能够在内存中存储所有的表格数据。又或者，你也许需要一个支持事务处理的数据库(以确保事务处理不成功时数据的回退能力)。<br/><br/>这些不同的技术以及配套的相关功能在MySQL中被称作存储引擎(也称作表类型)。MySQL默认配置了许多不同的存储引擎，可以预先设置或者在MySQL服务器中启用。你可以选择适用于服务器、数据库和表格的存储引擎，以便在选择如何存储你的信息、如何检索这些信息以及你需要你的数据结合什么性能和功能的时候为你提供最大的灵活性。<br/><br/>选择如何存储和检索你的数据的这种灵活性是MySQL为什么如此受欢迎的主要原因。其它数据库系统(包括大多数商业选择)仅支持一种类型的数据存储。遗憾的是，其它类型的数据库解决方案采取的“一个尺码满足一切需求”的方式意味着你要么就牺牲一些性能，要么你就用几个小时甚至几天的时间详细调整你的数据库。使用MySQL，我们仅需要修改我们使用的存储引擎就可以了。<br/><br/>在这篇文章中，我们不准备集中讨论不同的存储引擎的技术方面的问题(尽管我们不可避免地要研究这些因素的某些方面)，相反，我们将集中介绍这些不同的引擎分别最适应哪种需求和如何启用不同的存储引擎。为了实现这个目的，在介绍每一个存储引擎的具体情况之前，我们必须要了解一些基本的问题。<br/><br/><strong>如何确定有哪些存储引擎可用</strong><br/><br/>你可以在MySQL(假设是MySQL服务器4.1.2以上版本)中使用显示引擎的命令得到一个可用引擎的列表。<br/><br/>mysql> show engines;<br/><br/>+------------+---------+------------------------------------------------------------+<br/>&#124; Engine &nbsp; &nbsp; &#124; Support &#124; 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;&#124;<br/>+------------+---------+------------------------------------------------------------+<br/>&#124; MyISAM &nbsp; &nbsp; &#124; DEFAULT &#124; Default engine as of MySQL 3.23 with great performance &nbsp; &nbsp; &#124;<br/>&#124; HEAP &nbsp; &nbsp; &nbsp; &#124; YES &nbsp; &nbsp; &#124; Alias for MEMORY &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#124;<br/>&#124; MEMORY &nbsp; &nbsp; &#124; YES &nbsp; &nbsp; &#124; Hash based, stored in memory, useful for temporary tables &nbsp;&#124;<br/>&#124; MERGE &nbsp; &nbsp; &nbsp;&#124; YES &nbsp; &nbsp; &#124; Collection of identical MyISAM tables &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#124;<br/>&#124; MRG_MYISAM &#124; YES &nbsp; &nbsp; &#124; Alias for MERGE &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#124;<br/>&#124; ISAM &nbsp; &nbsp; &nbsp; &#124; NO &nbsp; &nbsp; &nbsp;&#124; Obsolete storage engine, now replaced by MyISAM &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#124;<br/>&#124; MRG_ISAM &nbsp; &#124; NO &nbsp; &nbsp; &nbsp;&#124; Obsolete storage engine, now replaced by MERGE &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#124;<br/>&#124; InnoDB &nbsp; &nbsp; &#124; YES &nbsp; &nbsp; &#124; Supports transactions, row-level locking, and foreign keys &#124;<br/>&#124; INNOBASE &nbsp; &#124; YES &nbsp; &nbsp; &#124; Alias for INNODB &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#124;<br/>&#124; BDB &nbsp; &nbsp; &nbsp; &nbsp;&#124; NO &nbsp; &nbsp; &nbsp;&#124; Supports transactions and page-level locking &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#124;<br/>&#124; BERKELEYDB &#124; NO &nbsp; &nbsp; &nbsp;&#124; Alias for BDB &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&#124;<br/>&#124; NDBCLUSTER &#124; NO &nbsp; &nbsp; &nbsp;&#124; Clustered, fault-tolerant, memory-based tables &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#124;<br/>&#124; NDB &nbsp; &nbsp; &nbsp; &nbsp;&#124; NO &nbsp; &nbsp; &nbsp;&#124; Alias for NDBCLUSTER &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#124;<br/>&#124; EXAMPLE &nbsp; &nbsp;&#124; NO &nbsp; &nbsp; &nbsp;&#124; Example storage engine &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#124;<br/>&#124; ARCHIVE &nbsp; &nbsp;&#124; NO &nbsp; &nbsp; &nbsp;&#124; Archive storage engine &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#124;<br/>&#124; CSV &nbsp; &nbsp; &nbsp; &nbsp;&#124; NO &nbsp; &nbsp; &nbsp;&#124; CSV storage engine &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#124;<br/>+------------+---------+------------------------------------------------------------+<br/>16 rows in set (0.01 sec)这个表格显示了可用的数据库引擎的全部名单以及在当前的数据库服务器中是否支持这些引擎。<br/><br/>对于MySQL 4.1.2以前版本，可以使用mysql> show variables like "have_%"(显示类似“have_%”的变量):<br/>mysql> show variables like "have_%"; <br/>+------------------+----------+ <br/>&#124; Variable_name &nbsp; &nbsp;&#124; Value &nbsp; &nbsp;&#124; <br/>+------------------+----------+ <br/>&#124; have_bdb &nbsp; &nbsp; &nbsp; &nbsp; &#124; YES &nbsp; &nbsp; &nbsp;&#124; <br/>&#124; have_crypt &nbsp; &nbsp; &nbsp; &#124; YES &nbsp; &nbsp; &nbsp;&#124; <br/>&#124; have_innodb &nbsp; &nbsp; &nbsp;&#124; DISABLED &#124; <br/>&#124; have_isam &nbsp; &nbsp; &nbsp; &nbsp;&#124; YES &nbsp; &nbsp; &nbsp;&#124; <br/>&#124; have_raid &nbsp; &nbsp; &nbsp; &nbsp;&#124; YES &nbsp; &nbsp; &nbsp;&#124; <br/>&#124; have_symlink &nbsp; &nbsp; &#124; YES &nbsp; &nbsp; &nbsp;&#124; <br/>&#124; have_openssl &nbsp; &nbsp; &#124; YES &nbsp; &nbsp; &nbsp;&#124; <br/>&#124; have_query_cache &#124; YES &nbsp; &nbsp; &nbsp;&#124; <br/>+------------------+----------+ <br/>8 rows in set (0.01 sec) <br/>你可以通过修改设置脚本中的选项来设置在MySQL安装软件中可用的引擎。如果你在使用一个预先包装好的MySQL二进制发布版软件，那么，这个软件就包含了常用的引擎。然而，需要指出的是，如果你要使用某些不常用的引擎，特别是CSV、RCHIVE(存档)和BLACKHOLE(黑洞)引擎，你就需要手工重新编译MySQL源码 。<br/><br/><strong>使用一个指定的存储引擎</strong><br/><br/>你可以使用很多方法指定一个要使用的存储引擎。最简单的方法是，如果你喜欢一种能满足你的大多数数据库需求的存储引擎，你可以在MySQL设置文件中设置一个默认的引擎类型（使用storage_engine 选项）或者在启动数据库服务器时在命令行后面加上--default-storage -engine或--default-table-type选项 。<br/><br/>更灵活的方式是在随MySQL服务器发布同时提供的MySQL客户端时指定使用的存储引擎。最直接的方式是在创建表时指定存储引擎的类型，向下面这样:<br/><br/>CREATE TABLE mytable (id int, title char(20)) ENGINE = INNODB<br/><br/>你还可以改变现有的表使用的存储引擎，用以下语句:<br/><br/>ALTER TABLE mytable ENGINE = MyISAM<br/><br/>然而，你在以这种方式修改表格类型的时候需要非常仔细，因为对不支持同样的索引、字段类型或者表大小的一个类型进行修改可能使你丢失数据。如果你指定一个在你的当前的数据库中不存在的一个存储引擎，那么就会创建一个MyISAM(默认的)类型的表。<br/><br/><strong>各存储引擎之间的区别</strong><br/><br/>　　为了做出选择哪一个存储引擎的决定，我们首先需要考虑每一个存储引擎提供了哪些不同的核心功能。这种功能使我们能够把不同的存储引擎区别开来。我们一般把这些核心功能分为四类:支持的字段和数据类型、锁定类型、索引和处理。一些引擎具有能过促使你做出决定的独特的功能，我们一会儿再仔细研究这些具体问题。<br/><br/>　　字段和数据类型<br/><br/>　　虽然所有这些引擎都支持通用的数据类型，例如整型、实型和字符型等，但是，并不是所有的引擎都支持其它的字段类型，特别是blog（二进制大对象）或者text文本类型。其它引擎也许仅支持有限的字符宽度和数据大小。<br/><br/>　　这些局限性可能直接影响到你可以存储的数据，同时也可能会对你实施的搜索的类型或者你对那些信息创建的索引产生间接的影响。这些区别能够影响你的应用程序的性能和功能，因为你必须要根据你要存储的数据类型选择对需要的存储引擎的功能做出决策。<br/><br/>　　锁定<br/><br/>　　数据库引擎中的锁定功能决定了如何管理信息的访问和更新。当数据库中的一个对象为信息更新锁定了，在更新完成之前，其它处理不能修改这个数据(在某些情况下还不允许读这种数据)。<br/><br/>　　锁定不仅影响许多不同的应用程序如何更新数据库中的信息，而且还影响对那个数据的查询。这是因为查询可能要访问正在被修改或者更新的数据。总的来说，这种延迟是很小的。大多数锁定机制主要是为了防止多个处理更新同一个数据。由于向数据中插入信息和更新信息这两种情况都需要锁定，你可以想象，多个应用程序使用同一个数据库可能会有很大的影响。<br/><br/>　　不同的存储引擎在不同的对象级别支持锁定，而且这些级别将影响可以同时访问的信息。得到支持的级别有三种:表锁定、块锁定和行锁定。支持最多的是表锁定，这种锁定是在myisam中提供的。在数据更新时，它锁定了整个表。这就防止了许多应用程序同时更新一个具体的表。这对应用很多的多用户数据库有很大的影响，因为它延迟了更新的过程。<br/><br/>　　页级锁定使用berkeleydb引擎，并且根据上载的信息页(8kb)锁定数据。当在数据库的很多地方进行更新的时候，这种锁定不会出现什么问题。但是，由于增加几行信息就要锁定数据结构的最后8kb，当需要增加大量的行，也别是大量的小型数据，就会带来问题。<br/><br/>　　行级锁定提供了最佳的并行访问功能，一个表中只有一行数据被锁定。这就意味着很多应用程序能够更新同一个表中的不同行的数据，而不会引起锁定的问题。只有innodb存储引擎支持行级锁定。<br/><br/>　　建立索引<br/><br/>　　建立索引在搜索和恢复数据库中的数据的时候能够显著提高性能。不同的存储引擎提供不同的制作索引的技术。有些技术也许会更适合你存储的数据类型。<br/><br/>　　有些存储引擎根本就不支持索引，其原因可能是它们使用基本表索引(如merge引擎)或者是因为数据存储的方式不允许索引(例如federated或者blackhole引擎)。<br/><br/>　　事务处理<br/><br/>　　事务处理功能通过提供在向表中更新和插入信息期间的可靠性。这种可靠性是通过如下方法实现的，它允许你更新表中的数据，但仅当应用的应用程序的所有相关操作完全完成后才接受你对表的更改。例如，在会计处理中每一笔会计分录处理将包括对借方科目和贷方科目数据的更改，你需要要使用事务处理功能保证对借方科目和贷方科目的数据更改都顺利完成，才接受所做的修改。如果任一项操作失败了，你都可以取消这个事务处理，这些修改就不存在了。如果这个事务处理过程完成了，我们可以通过允许这个修改来确认这个操作。<br/><br/>Tags - <a href="tag.php?tag=mysql" rel="tag">mysql</a> , <a href="tag.php?tag=%E5%AD%98%E5%82%A8%E5%BC%95%E6%93%8E" rel="tag">存储引擎</a>
]]>
</description>
</item><item>
<link>http://www.bizeway.net/read.php?&amp;guid=0#topreply</link>
<title><![CDATA[[评论] MySQL数据库存储引擎详解]]></title> 
<author> &lt;user@domain.com&gt;</author>
<category><![CDATA[评论]]></category>
<pubDate>Thu, 01 Jan 1970 00:00:00 +0000</pubDate> 
<guid>http://www.bizeway.net/read.php?&amp;guid=0#topreply</guid> 
<description>
<![CDATA[ 
	
]]>
</description>
</item>
</channel>
</rss>