[转]MySQL数据库引擎
经常用MySQL数据库,但是,你在用的时候注意过没有,数据库的存储引擎,可能有注意但是并不清楚什么意思,可能根本没注意过这个问题,使用了默认的数据库引擎,当然我之前属于后者,后来成了前者,然后就有了这篇博文啦,希望可以帮助部分人了解MySQL引擎的一些特性。
存储引擎概念
有哪些存储引擎
存储引擎主要有: 1. MyIsam , 2. Mrg_Myisam, 3. Memory, 4. Blackhole, 5. CSV, 6. Performance_Schema, 7. Archive, 8. Federated , 9 InnoDB
- mysql> show engines\G
- *************************** 1. row ***************************
- Engine: MyISAM
- Support: YES
- Comment: MyISAM storage engine
- Transactions: NO
- XA: NO
- Savepoints: NO
- *************************** 2. row ***************************
- Engine: MRG_MYISAM
- Support: YES
- Comment: Collection of identical MyISAM tables
- Transactions: NO
- XA: NO
- Savepoints: NO
- *************************** 3. row ***************************
- Engine: MEMORY
- Support: YES
- Comment: Hash based, stored in memory, useful for temporary tables
- Transactions: NO
- XA: NO
- Savepoints: NO
- *************************** 4. row ***************************
- Engine: BLACKHOLE
- Support: YES
- Comment: /dev/null storage engine (anything you write to it disappears)
- Transactions: NO
- XA: NO
- Savepoints: NO
- *************************** 5. row ***************************
- Engine: CSV
- Support: YES
- Comment: CSV storage engine
- Transactions: NO
- XA: NO
- Savepoints: NO
- *************************** 6. row ***************************
- Engine: PERFORMANCE_SCHEMA
- Support: YES
- Comment: Performance Schema
- Transactions: NO
- XA: NO
- Savepoints: NO
- *************************** 7. row ***************************
- Engine: ARCHIVE
- Support: YES
- Comment: Archive storage engine
- Transactions: NO
- XA: NO
- Savepoints: NO
- *************************** 8. row ***************************
- Engine: FEDERATED
- Support: NO
- Comment: Federated MySQL storage engine
- Transactions: NULL
- XA: NULL
- Savepoints: NULL
- *************************** 9. row ***************************
- Engine: InnoDB
- Support: DEFAULT
- Comment: Supports transactions, row-level locking, and foreign keys
- Transactions: YES
- XA: YES
- Savepoints: YES
- 9 rows in set (0.00 sec)
存储引擎的主要特性
1. MyIsam
2. Mrg_Myisam
3. Memory
4. Blackhole
5. CSV
6. Performance_Schema
7. Archive
8. Federated
9. InnoDB
MyISam和InnoDB实例比较
- create table testMyIsam(
- -> id int unsigned primary key auto_increment,
- -> name varchar(20) not null
- -> )engine=myisam;
- create table testInnoDB( id int unsigned primary key auto_increment, name varchar(20) not null )engine=innodb;
两张表内容是一致的但是存储引擎不一样,下面我们从插入数据开始进行测试比较。
2.插入一百万数据
- mysql> create procedure insertMyIsam()
- -> begin
- -> set @i = 1;
- -> while @i <= 1000000
- -> do
- -> insert into testMyIsam(name) values(concat("wy", @i));
- -> set @i = @i + 1;
- -> end while;
- -> end//
- mysql> create procedure insertInnoDB()
- -> begin
- -> set @i = 1;
- -> while @i <= 1000000
- -> do
- -> insert into testInnoDB(name) values(concat("wy", @i));
- -> set @i = @i + 1;
- -> end while;
- -> end//
插入(一百万条)MyIsam存储引擎的表中的时间如下:
- mysql> call insertMyIsam;
- -> //
- Query OK, 0 rows affected (49.69 sec)
- mysql> create procedure insertInnoDB()
- -> begin
- -> set @i = 1;
- -> while @i <= 1000000
- -> do
- -> insert into testInnoDB(name) values(concat("wy", @i));
- -> set @i = @i + 1;
- -> end while;
- -> end//
- Query OK, 0 rows affected (0.00 sec)
- mysql> call insertInnoDB;
- -> //
- Query OK, 0 rows affected (1 hour 38 min 14.12 sec)
我的心情是复杂的,这里当时默认的是开启了自动提交事务了,所以执行速度很慢,可以先将自动提交关闭,然后再调用存储过程插入一百万的数据,执行完成之后再开启自动提交,这样会快很多。
- mysql> set autocommit = 0;
- Query OK, 0 rows affected (0.00 sec)
- mysql> call insertInnoDB;
- Query OK, 0 rows affected (36.52 sec)
- mysql> set autocommit = 1;
- Query OK, 0 rows affected (5.72 sec)
3. 查询数据总数目
- mysql> desc select count(*) from testInnoDB\G;
- *************************** 1. row ***************************
- id: 1
- select_type: SIMPLE
- table: testInnoDB
- type: index
- possible_keys: NULL
- key: PRIMARY
- key_len: 4
- ref: NULL
- rows: 997134
- Extra: Using index
- 1 row in set (0.03 sec)
下面是MyIsam(他的数据总数存储在其他的表中所以这里是没有影响行数的)的SQL语句的分析:
- mysql> desc select count(*) from testMyIsam\G;
- *************************** 1. row ***************************
- id: 1
- select_type: SIMPLE
- table: NULL
- type: NULL
- possible_keys: NULL
- key: NULL
- key_len: NULL
- ref: NULL
- rows: NULL
- Extra: Select tables optimized away
- 1 row in set (0.00 sec)
4. 查询某一范围的数据
4.1 没有索引的列
- mysql> select * from testMyIsam where name > "wy100" and name < "wy100000";+-------+---------+
- | id | name |
- +-------+---------+
- | 1000 | wy1000 |
- | 10000 | wy10000 |
- +-------+---------+
- 2 rows in set (0.43 sec)
- mysql> select * from testInnoDB where name > "wy100" and name < "wy100000";+-------+---------+
- | id | name |
- +-------+---------+
- | 1000 | wy1000 |
- | 10000 | wy10000 |
- +-------+---------+
4.2 有索引的列
- <pre name="code" class="sql">select * from testMyIsam where id > 10 and id < 999999;
执行时间:
- <pre name="code" class="sql">999988 rows in set (0.91 sec)
对于使用了InnoDB存储引擎的表:
- select * from testInnoDB where id > 10 and id < 999999;
- 999988 rows in set (0.69 sec)
但是好像我没看出来多大的差距,可能是数据太少的原因吧。
- mysql> select * from testInnoDB where name = "wy999999";
- +--------+----------+
- | id | name |
- +--------+----------+
- | 999999 | wy999999 |
- +--------+----------+
- 1 row in set (0.20 sec)
- mysql> select * from testMyIsam where name = "wy999999";
- +--------+----------+
- | id | name |
- +--------+----------+
- | 999999 | wy999999 |
- +--------+----------+
- 1 row in set (0.16 sec)
[转]MySQL数据库引擎的更多相关文章
- mysql 数据库引擎
一.数据库引擎 数据库引擎是用于存储.处理和保护数据的核心服务.利用数据库引擎可控制访问权限并快速处理事务,从而满足企业内大多数需要处理大量数据的应用程序的要求. 使用数据库引擎创建用于联机事务处理或 ...
- MySQL数据库引擎介绍、区别、创建和性能测试的深入分析
本篇文章是对MySQL数据库引擎介绍.区别.创建和性能测试进行了详细的分析介绍,需要的朋友参考下 数据库引擎介绍 MySQL数据库引擎取决于MySQL在安装的时候是如何被编译的.要添加一个新的引擎 ...
- 常用mysql数据库引擎——MyISAM和InnoDB区别
背景: 昨天做项目时,发现使用事务后回滚不了,后来把数据库引擎从MyISAM换成InnoDB后果断好了,如下图: 正文: MyISAM和InnoDB是mysql常用的数据库引擎,他们的区别如下: 数据 ...
- [转]MySQL数据库引擎介绍、区别、创建和性能测试的深入分析
本篇文章是对MySQL数据库引擎介绍.区别.创建和性能测试进行了详细的分析介绍,需要的朋友参考下 数据库引擎介绍 MySQL数据库引擎取决于MySQL在安装的时候是如何被编译的.要添加一个新的引擎 ...
- (转)MySQL数据库引擎ISAM MyISAM HEAP InnoDB的区别
转自:http://blog.csdn.net/nightelve/article/details/16895917 MySQL数据库引擎取决于MySQL在安装的时候是如何被编译的.要添加一个新的引擎 ...
- MySQL数据库引擎介绍、区别
数据库引擎介绍 MySQL数据库引擎取决于MySQL在安装的时候是如何被编译的.要添加一个新的引擎,就必须重新编译MYSQL.在缺省情况下,MYSQL支持三个引擎:ISAM.MYISAM和HEAP.另 ...
- MYSQL数据库引擎区别详解
数据库引擎介绍 MySQL数据库引擎取决于MySQL在安装的时候是如何被编译的.要添加一个新的引擎,就必须重新编译MYSQL.在缺省情况下,MYSQL支持三个引擎:ISAM.MYISAM和HEAP.另 ...
- Mysql数据库引擎介绍--转载
引用博文链接:https:/www.cnblogs.com/zhangjinghe/p/7599988.html MYSQL数据库引擎区别详解 数据库引擎介绍 MySQL数据库引擎取决于MySQL在安 ...
- MySQL数据库引擎类别和更换方式
MySQL数据库引擎类别 能用的数据库引擎取决于mysql在安装的时候是如何被编译的.要添加一个新的引擎,就必须重新编译MYSQL.在缺省情况下,MYSQL支持三个引擎:ISAM.MYISAM和HEA ...
- 语言小知识-MySQL数据库引擎
MySQL作为全世界广受欢迎的数据库,被用于很多中小型的项目中,但是你对 MySQL 数据库的存储引擎了解多少呢? 我们将逻辑表中的数据存储到数据库中,数据库又将我们表中的数据存储到物理设备中(如磁盘 ...
随机推荐
- 样条曲线的Fortran程序
subroutine basis_function_b_val ( tdata, tval, yval ) ! !******************************************* ...
- 【转】Unity3D中脚本的执行顺序和编译顺序(vs工程引用关系)
http://www.cnblogs.com/champ/p/execorder.html 在Unity中可以同时创建很多脚本,并且可以分别绑定到不同的游戏对象上,它们各自都在自己的生命周期中运行.与 ...
- java JDK8 学习笔记——第18章 自定义泛型、枚举与注释
第十八章 自定义泛型.枚举与注释 18.1 自定义泛型 泛型定义: (1)仅定义在方法上的泛型语法 (2)用来限制泛型可用类型的extends与super关键字(3)?类型通配字符的使用 18.1.1 ...
- cordova插件iOS平台实战开发注意点
cordova插件是其设计理念的精髓部分,创建并使用自定义插件也是一件比较容易的事.但在这个过程中也容易进入一些误区或者有一些错误的理解,下面从笔者实际开发中遇到的问题出发,对其中的一些注意点和重要概 ...
- textview自适应高度的计算方法
http://blog.csdn.net/smking/article/details/22221441
- ASP.NET Web API与Rest web api(一)
HTTP is not just for serving up web pages. It is also a powerful platform for building APIs that exp ...
- 网页中的超链接<a>标签
格式: <a href="目标网址" title="鼠标滑过显示的文本">链接显示的文本</a> 注意:为文本加入<a>标签 ...
- 创建podSpec,使用pod管理第三方库
提要: podfile文件会先读取.podspec文件,根据.podspec文件的指向来下载第三方库到项目中. 本文先通过一.二.三项,这三个步骤讲解了如何建立一个.podspec文件在本地.coco ...
- oracle 把一个用户的表结构导入到另一个用户下
create table AM_CONTENTS as select * from bizdata008.AM_CONTENTS where 1=2
- JS实现动画原理一(闭包方式)
前提: 你必须了解js的闭包(否则你看不懂滴) 我们就来做一个js实现jq animate的动画效果来简单探索一下,js动画实现的简单原理: html代码 <div id=&q ...