MySQL表种类中两大经常使用的类型
我们今天主要和大家一起分享的是MySQL表种类,即 ,MYISAM与innodb的详细内容的解析,这两种表的类型也是在实际应用中经常使用的,以下的文章主要就是对其相关的具体内容的描述。 1、如果你的数据执行大量的INSERT或UPDATE,出于性能方面的考虑,应该使用Inn
我们今天主要和大家一起分享的是MySQL表种类,即 ,MYISAM与innodb的详细内容的解析,这两种表的类型也是在实际应用中经常使用的,以下的文章主要就是对其相关的具体内容的描述。
1、如果你的数据执行大量的INSERT或UPDATE,出于性能方面的考虑,应该使用InnoDB表。
如果执行大量的SELECT,MyISAM是更好的选择。
2、我需要使用事务处理,但是原来的数据表使用的是myisam,就需要改为bdb或者innodb,这样基于myisam的程序,将类型改为innodb后,原来的程序是不需要改动。
3、myisam属于非事务安全型,innodb和bdb属于事务安全型。
说明:
测试表建立 (环境为MySQL5.0.22, Windows 2000操作系统)
<ol class="dp-xml"> <li class="alt"><span><span>create table AAA( </span></span></li> <li><span>a1 varchar(64) not null, </span></li> <li class="alt"><span>b2 varchar(255), </span></li> <li><span>c3 int, </span></li> <li class="alt"><span>primary key (a1) </span></li> <li> <span>)</span><span class="attribute">ENGINE</span><span>=</span><span class="attribute-value">InnoDB</span><span>; </span> </li> </ol>
测试存储过程–执行10000次Insert插入
<ol class="dp-xml"> <li class="alt"><span><span>create procedure sp_AAA () </span></span></li> <li><span>begin </span></li> <li class="alt"><span>declare i integer; </span></li> <li><span>declare a1 char(64); </span></li> <li class="alt"><span>declare b2 char(255); </span></li> <li> <span>set </span><span class="attribute">i</span><span>=</span><span class="attribute-value">1</span><span>; </span> </li> <li class="alt"> <span>while i </span><span class="tag"><span> </span><span class="tag-name">10000</span><span> do </span></span> </li> <li> <span>set </span><span class="attribute">a1</span><span>= </span><span class="attribute-value">concat</span><span>(‘aaa’ ,i); </span> </li> <li class="alt"> <span>set </span><span class="attribute">b2</span><span>= </span><span class="attribute-value">concat</span><span>(‘bbbbbbbbbbbbbbbbbbbbbbb’ ,i) ; </span> </li> <li><span>insert into aaa values(a1,b2,i) ; </span></li> <li class="alt"> <span>set </span><span class="attribute">i</span><span class="attribute-value">i</span><span>=i+1 ; </span> </li> <li><span>end while; </span></li> <li class="alt"><span>end; </span></li> </ol>
调用 call sp_AAA 发现执行完该存储过程总共花费295秒时间
我知道,在存储过程sp_AAA的while循环外层用start transaction; 和commit; 包起来, 使执行完10000次插入再整个做一次commit提交, mysql会表现得比较快, 但是在实际应用中一般都要求插入一条或几条,完成一个动作后就commit一次, 这样MySQL的innodb性能似乎很差, 不知道是我测试理解有误,或是还有其他原因,请大家指点一下.
(另外我在sybase11.9和oracle9i下进行相同的测试, 同样安装在本人笔记本电脑环境下, 也是insert一次commit一次, 总共10000次插入, Sybase费时6秒, Oracle费时2秒)
MySQL的事务类型表InnoDB居然性能差距这么大么???
附Sybase和Oracle的测试过程:
Sybase测试存储过程
<ol class="dp-xml"> <li class="alt"><span><span>create procedure sp_AAA </span></span></li> <li><span>as </span></li> <li class="alt"><span>begin </span></li> <li><span>declare @i integer </span></li> <li class="alt"><span>declare @a1 char(64) </span></li> <li><span>declare @b2 char(255) </span></li> <li class="alt"> <span>select @</span><span class="attribute">i</span><span>=</span><span class="attribute-value">1</span><span> </span> </li> <li> <span>while @i </span><span class="tag"><span> </span><span class="tag-name">10000</span><span> </span></span> </li> <li class="alt"><span>begin </span></li> <li> <span>select @</span><span class="attribute">a1</span><span>= ‘aaa’ + convert(varchar(64),@i) </span> </li> <li class="alt"> <span>select @</span><span class="attribute">b2</span><span>= ‘bbbbbbbbbbbbbbbbbbbbbbb’ + convert(varchar(64),@i) </span> </li> <li><span>insert into AAA values(@a1,@b2,@i) </span></li> <li class="alt"> <span>select @</span><span class="attribute">i</span><span>=@i+1 </span> </li> <li><span>end </span></li> <li class="alt"><span>end </span></li> <li><span> </span></li> </ol>
Oracle测试存储过程
<ol class="dp-xml"> <li class="alt"><span><span>CREATE OR REPLACE PROCEDURE sp_AAA(a int) </span></span></li> <li><span>AS </span></li> <li class="alt"><span>i int; </span></li> <li><span>a1 varchar2(64); </span></li> <li class="alt"><span>b2 varchar2(255); </span></li> <li><span>BEGIN </span></li> <li class="alt"> <span>i </span><span class="attribute">:</span><span>=</span><span class="attribute-value">1</span><span>; </span> </li> <li> <span>while i </span><span class="tag"><span> </span><span class="tag-name">10000</span><span> loop </span></span> </li> <li class="alt"> <span>a1 </span><span class="attribute">:</span><span>= ‘aaa’ || to_char(i); </span> </li> <li> <span>b2 </span><span class="attribute">:</span><span>= ‘bbbbbbbbbbbbbbbbbbbbbbb’ || to_char(i); </span> </li> <li class="alt"><span>insert into aaa values(a1,b2,i) ; </span></li> <li><span>commit ; </span></li> <li class="alt"> <span>i </span><span class="attribute">:</span><span>=</span><span class="attribute-value">i</span><span>+1 ; </span> </li> <li><span>end loop; </span></li> <li class="alt"><span>END; </span></li> </ol>
InnoDB和MyISAM是在使用MySQL表类型中最常用的两个,各有优缺点,视具体应用而定。基本的差别为:MyISAM类型不支持事务处理等高级处理,而InnoDB类型支持。MyISAM类型的表强调的是性能,其执行数度比InnoDB类型更快,但是不提供事务支持,而InnoDB提供事务支持已经外部键等高级数据库功能。
MyIASM是IASM表的新版本,有如下扩展:
二进制层次的可移植性。
NULL列索引。
对变长行比ISAM表有更少的碎片。
支持大文件。
更好的索引压缩。
更好的键吗统计分布。
更好和更快的auto_increment处理。
1.MySQL最大的优势在于MyISAM引擎下的简单SELECT,INSERT和UPDATE快速操作
2.MyISAM类型的数据文件可以在不同操作系统中COPY,这点很重要,布署的时候方便点。
以下是一些细节和具体实现的差别:
1.InnoDB不支持FULLTEXT类型的索引。
2.InnoDB 中不保存表的具体行数,也就是说,执行select count(*) from table时,InnoDB要扫描一遍整个表来计算有多少行,但是MyISAM只要简单的读出保存好的行数即可。注意的是,当count(*)语句包含 where条件时,两种表的操作是一样的。
3.对于AUTO_INCREMENT类型的字段,InnoDB中必须包含只有该字段的索引,但是在MyISAM表中,可以和其他字段一起建立联合索引。
4.DELETE FROM table时,InnoDB不会重新建立表,而是一行一行的删除。
5.LOAD TABLE FROM MASTER操作对InnoDB是不起作用的,解决方法是首先把InnoDB表改成MyISAM表,导入数据后再改成InnoDB表,但是对于使用的额外的InnoDB特性(例如外键)的表不适用。
另外,InnoDB表的行锁也不是绝对的,如果在执行一个SQL语句时MySQL不能确定要扫描的范围,InnoDB表同样会锁全表,例如update table set num=1 where name like “%aaa%”
以暂对存储引擎的认识,觉得 InnoDB 支持外键,在数据量可以用“庞大”来形容时,在有良好的 INDEX 的基础上,InnoDB 的查询速度应该比 MyISAM 要快。
在 Falcon 有稳定版本前,我想 MyISAM 是一个可用的选择方案。
任何一种表都不是万能的,只用恰当的针对业务类型来选择合适的表类型,才能最大的发挥MySQL的性能优势。
以上的相关内容就是对MySQL表种类 MyISAM,innodb详解的介绍,望你能有所收获。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

MySQL is an open source relational database management system, mainly used to store and retrieve data quickly and reliably. Its working principle includes client requests, query resolution, execution of queries and return results. Examples of usage include creating tables, inserting and querying data, and advanced features such as JOIN operations. Common errors involve SQL syntax, data types, and permissions, and optimization suggestions include the use of indexes, optimized queries, and partitioning of tables.

You can open phpMyAdmin through the following steps: 1. Log in to the website control panel; 2. Find and click the phpMyAdmin icon; 3. Enter MySQL credentials; 4. Click "Login".

MySQL is chosen for its performance, reliability, ease of use, and community support. 1.MySQL provides efficient data storage and retrieval functions, supporting multiple data types and advanced query operations. 2. Adopt client-server architecture and multiple storage engines to support transaction and query optimization. 3. Easy to use, supports a variety of operating systems and programming languages. 4. Have strong community support and provide rich resources and solutions.

MySQL's position in databases and programming is very important. It is an open source relational database management system that is widely used in various application scenarios. 1) MySQL provides efficient data storage, organization and retrieval functions, supporting Web, mobile and enterprise-level systems. 2) It uses a client-server architecture, supports multiple storage engines and index optimization. 3) Basic usages include creating tables and inserting data, and advanced usages involve multi-table JOINs and complex queries. 4) Frequently asked questions such as SQL syntax errors and performance issues can be debugged through the EXPLAIN command and slow query log. 5) Performance optimization methods include rational use of indexes, optimized query and use of caches. Best practices include using transactions and PreparedStatemen

Apache connects to a database requires the following steps: Install the database driver. Configure the web.xml file to create a connection pool. Create a JDBC data source and specify the connection settings. Use the JDBC API to access the database from Java code, including getting connections, creating statements, binding parameters, executing queries or updates, and processing results.

The process of starting MySQL in Docker consists of the following steps: Pull the MySQL image to create and start the container, set the root user password, and map the port verification connection Create the database and the user grants all permissions to the database

The main role of MySQL in web applications is to store and manage data. 1.MySQL efficiently processes user information, product catalogs, transaction records and other data. 2. Through SQL query, developers can extract information from the database to generate dynamic content. 3.MySQL works based on the client-server model to ensure acceptable query speed.

The key to installing MySQL elegantly is to add the official MySQL repository. The specific steps are as follows: Download the MySQL official GPG key to prevent phishing attacks. Add MySQL repository file: rpm -Uvh https://dev.mysql.com/get/mysql80-community-release-el7-3.noarch.rpm Update yum repository cache: yum update installation MySQL: yum install mysql-server startup MySQL service: systemctl start mysqld set up booting
