[转]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 数据库的存储引擎了解多少呢? 我们将逻辑表中的数据存储到数据库中,数据库又将我们表中的数据存储到物理设备中(如磁盘 ...
随机推荐
- final与static
一.final 根据程序上下文环境,Java关键字final有“这是无法改变的”或者“终态的”含义,它可以修饰非抽象类.非抽象类成员方法和变量.你可能出于两种理解而需要阻止改变:设计或效率. fina ...
- 【转】全面解析Unity3D自动生成的脚本工程文件
http://blog.csdn.net/jjiss318/article/details/7632041 我们在Unity3D开发的时候,经常会看到它会产生不少固定命名工程文件,诸如: Assemb ...
- docker debug diagnose
$ sudo systemctl stop docker $ sudo docker -d -D DEBU[0282] Error contacting registry https://regist ...
- java JDK8 学习笔记——第11章 线程和并行API
第11章 线程与并行API 11.1 线程 11.1.1 线程 在java中,如果想在main()以外独立设计流程,可以撰写类操作java.lang.Runnable接口,流程的进入点是操作在run( ...
- mysql参数,蛮全的
网上有很多的文章教怎么配置MySQL服务器,但考虑到服务器硬件配置的不同,具体应用的差别,那些文章的做法只能作为初步设置参考,我们需要根据自己的情况进行配置优化,好的做法是MySQL服务器稳定运行了一 ...
- Dom方式解析XML
public class TestXML { public static void main(String[] args) throws SAXException, IOException { //D ...
- [Stanford 2011] MVC introduction
以下是课程笔记,仅供以后复习之便. 1.什么是MVC? (1) Model:如飞机激战的游戏中,太空中的飞船,什么机型,每个飞船有多少机枪,多少护甲,这些硬件组成是model. (2)Controll ...
- centos 安装 openerp
遇到问题:近日公司提出openerp的搭建,觉得openerp里的有些模块比较适合公司,openerp的运作,估计会有利于公司系统化的管理.于是我就去了解openrp,然后来搭建这套强大的系统. 解决 ...
- [LeetCode]题解(python):045-Jump game II
题目来源 https://leetcode.com/problems/jump-game-ii/ Given an array of non-negative integers, you are in ...
- Java学习-040-级联删除目录中的文件、目录
之前在写应用模块,进行单元测试编码的时候,居然脑洞大开居然创建了一个 N 层的目录,到后来删除测试结果目录的时候,才发现删除不了了,提示目录过长无法删除.网上找了一些方法,也找了一些粉碎机,都没能达到 ...