[转]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 数据库的存储引擎了解多少呢? 我们将逻辑表中的数据存储到数据库中,数据库又将我们表中的数据存储到物理设备中(如磁盘 ...
随机推荐
- Tomcat7 安装StartSSL证书笔记
1.Tomcat-Native安装 使用StartSSL,Tomcat必须用apr方式启动(apr方式对于静态的内容,比默认的bio效率要高很多倍) Windows下tomcat-native安装 直 ...
- php + ajax + html 简单跨域问题
XMLHttpRequest cannot load http://localhost:8080/abc/index.php. No 'Access-Control-Allow-Origin' hea ...
- jdk1.7
http://download.oracle.com/otn-pub/java/jdk/7u79-b15/jdk-7u79-windows-i586.exe?AuthParam=1450748157_ ...
- 处理PHP字符串的10个简单方法;mysql出现乱码:character_set_server=utf8
PHP处理字符串的能力非常强大,方法也是多种多样,但有的时候你需要选择一种最简单且理想的解决方法.文章列举了10个PHP中常见的字符串处理案例,并提供了相对应的最理想的处理方法. 1.确定一个字符串的 ...
- BLE-NRF51822教程19-Battery Service
Battery Service是有关电池特性方面的服务,如果需要它,在初始化时将它加入到蓝牙协议栈. 如果通过ble_bas_battery_level_update(),电池电量将会通知,Batte ...
- 轮询、select、 epoll
网卡设备对应一个中断号, 当网卡收到网络端的消息的时候会向CPU发起中断请求, 然后CPU处理该请求. 通过驱动程序 进而操作系统得到通知, 系统然后通知epoll, epoll通知用户代码. 一. ...
- SQL语句里怎么获得当前年份(MySQL数据库)
使用函数Year及CurDate的组合: Year(CurDate()) select date_format(min(date),'%Y-%m-%d') as mindate, date_forma ...
- c#中的linq一
c#中的linq 测试数据: using System; using System.Collections.Generic; using System.Linq; using System.Text; ...
- DDS杂散频谱来源:谐波超Nyquist 折返
- LeetCode Maximal Square
原题链接在这里:https://leetcode.com/problems/maximal-square/ 这是一道DP题,存储历史信息是到当前点能有的最大square, 用二维数组dp存储. 更新方 ...