MySQL 记录&优化


Innodb 数据完整性更好,支持事务,行级锁
MyISAM 查询及插入效率更高;比如 日志

类型分为三大类:
常用类型有 数值类型 又分为整型 浮点型等,字符串类型 char,varchar,text,enum枚举等,时间类型很少用

索引:
好比目录,利用关键字建立与记录位置对应的关系
种类:主键索引,唯一索引,普通索引,全文索引
查找指定表所有索引
show index from users;
可以通过 EXPLAIN 查看索引状态
explain select * from statuses where user_id =1G;
*************************** 1. row ***************************
id: 1
select_type: SIMPLE
table: statuses
partitions: NULL
type: ref // 查询类型 ALL、index、range、ref、eq_ref、const、system、NULL(从左到右,性能从差到好)
possible_keys: statuses_user_id_index // 可能使用的索引
key: statuses_user_id_index // 真早使用的索引
key_len: 4
ref: const
rows: 37 // 预计需要扫描多少行
filtered: 100.00 // 按表条件过滤的行百分比
Extra: NULL

select SQL_NO_CACHE * from statuses where user_id =1 limit 1G; 不使用缓存

TODO:未完待续

原文地址:https://www.cnblogs.com/blue-t/p/14528728.html