存储引擎MyISAM和InnoDB

存储引擎:创建、查询、更新、删除

innoDB:64T、支持事物、不支持全文索引、支持缓存、支持外键、行级锁定

MyISAM:256T、不支持事物、支持全文索引、插入和查询速度快

memory:内存、不支持事物、不支持全文索引,临时表

archive:none、不支持事物、不支持全文索引,insert,select

myisam:

frm:表的结构信息

myd:数据部分

myi:索引 (创建索引越多,myi越大)

innoDB:

frm:数据表的元数据

ibd:数据

opt:mysql的配置信息

创建"users"表查看默认存储引擎:

修改配置文件中引擎名创建t1表,查看存储引擎名看是否是自己修改的引擎名:

创建t2表的同时指定存储引擎:

创建t3表,使用set命令临时修改存储引擎:

MyISam和InnoDB实例比较

1:创建两张表分别以MyIsam和InnoDB作为存储引擎

create database test;

use test;

create table tm(id int(20) primary key auto_increment,name char(30)) engine=myisam;

create table ti(id int(20) primary key auto_increment,name char(30)) engine=innodb;

查看两张表的存储引擎:

mysql> show create table tm\G

mysql> show create table ti\G

2:插入一千万数据,来比较两个存储引擎的存储效率

(1)设置sql语句结束符

mysql> delimiter $

(delimiter 语句是设置sql语句的结束符为"")

(2)创建两个存储过程

mysql> create procedure insertm()

begin

set @i=1;

while @i

do

insert into tm(name) values(concat("wy",@i));

set @i=@i+1;

end while;

end

$

mysql> create procedure inserti()

begin

set @i=1;

while @i

do

insert into ti(name) values(concat("wy",@i));

set @i=@i+1;

end while;

end

$

mysql> delimiter ;

(delimiter ;语句是设置sql语句的结束符为";")

(3)利用存储过程向两个表添加数据插入(一千万条)MyIsam存储引擎的表中的时间如下:

mysql> call insertm;

Query OK, 0 rows affected (1 min 49.74 sec)

插入(一千万条)InnoDB存储引擎的表中的时间如下:

mysql> call inserti;

Query OK, 0 rows affected (13 min 32.96 sec)

比较结果:

MyIsam存储引擎在写入方面有优势

3:查询数据总数目

下面是InnoDB的SQL语句的分析:

MariaDB test> desc select count(*) from ti\G;

*************************** 1. row ***************************

id: 1

select_type: SIMPLE

table: ti

type: index

possible_keys: NULL

key: PRIMARY

key_len: 4

ref: NULL

rows: 1000160

Extra: Using index

1 row in set (0.00 sec)

下面是MyIsam(他的数据存储在其他的表中所以这里是没有影响行数的)的SQL语句的分析:

riaDB test> desc select count(*) from tm\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)

MyIsam使用专门的MYD表存储数据,所以这里没有查询结果

MyISAM存储引擎会是数据表生成3个文件:

frm文件存储表的定义、MYD文件是数据文件、MYI文件是索引文件

4:查询某一范围的数据

(1)没有索引的列

MariaDB test> select * from tm where name>"wy100" and name

+---------+-----------+

| id | name |

+---------+-----------+

| 1000 | wy1000 |

| 10000 | wy10000 |

| 100000 | wy100000 |

| 1000000 | wy1000000 |

+---------+-----------+

4 rows in set (0.68 sec)

MariaDB test> select * from ti where name>"wy100" and name

+---------+-----------+

| id | name |

+---------+-----------+

| 1000 | wy1000 |

| 10000 | wy10000 |

| 100000 | wy100000 |

| 1000000 | wy1000000 |

+---------+-----------+

4 rows in set (2.71 sec)

MariaDB test> select * from tm where name="wy9999999";

+---------+-----------+

| id | name |

+---------+-----------+

| 9999999 | wy9999999 |

+---------+-----------+

1 row in set (0.42 sec)

MariaDB test> select * from ti where name="wy9999999";

+---------+-----------+

| id | name |

+---------+-----------+

| 9999999 | wy9999999 |

+---------+-----------+

1 row in set (2.38 sec)

无索引查询MyIsam有优势

(2)有索引的列

对于使用MyIsam存储引擎的表:

select * from tm where id>10 and id

执行时间:

9999988 rows in set (1.88 sec)

对于使用了InnoDB存储引擎的表:

select * from ti where id>10 and id

执行时间:

9999988 rows in set (0.65 sec)

有索引查询INNODB有优势

相关推荐
ii_best1 小时前
移动开发工具按键精灵安卓版 OcrEx 识别总是漏字错字?改这一个参数,精度直接翻倍
android·ai编程·按键精灵
chjif2 小时前
Android 设备管控开发实战:自定义 Launcher 如何只显示指定 App?
android·kotlin
Dovis(誓平步青云)2 小时前
模拟器横评:电脑上看小说、追短剧用什么模拟器?MuMu、雷电、腾讯手游助手实测
android·java·服务器·前端·javascript·电脑
非凡ghost3 小时前
用 Kotlin 和 Jetpack Compose 重写的安卓视频播放器,原生体验有多流畅?
android·java·kotlin·音视频·软件需求
峥嵘life3 小时前
Android16 系统 APEX 模块调试总结
android·大数据·开发语言
亘元有量-流量变现3 小时前
2026安卓ASO增量攻略:摆脱iOS思维依赖,吃透多商店自然免费流量
android·aso优化·亘元有量·方糖试玩
一航jason3 小时前
安卓车机端 AIOS 技术生态全景
android·人工智能·ai·ai编程·ai-native
深念Y4 小时前
ZTE B860AV1.1-T2 机顶盒改造记录:从 Android 到 Linux 服务器
android·linux·运维·服务器·boot·cma·机顶盒
淡淡的香烟5 小时前
Android中tcp的通信
android·物联网·tcp/ip