33.mysql数据库学习

1.   utf8  utf8mb4

参考:https://blog.csdn.net/z947663039/article/details/84029573

https://blog.csdn.net/weixin_42785557/article/details/83512138

https://www.cnblogs.com/xingxia/p/database_mysql_character.html

c763e5e53486bdb1056254943c96741933e.jpg

700dd288b1b74d51546fa75f986fb4f9f33.jpg

 

应用:

8f7371db42e841c41db7748cea04f1a5b34.jpg

4f73c5a59d52358e8ab08d6104909cb953d.jpg

 

2. varchar   设置长度

8f38d9eb66bc082cab168a228749de764d6.jpg

5834f322c5553f850339f6ad8fcc6e70db4.jpg

 

 

3.mysql 引擎

这里战时只说: InnoDB和MyIsam

              https://blog.csdn.net/summerzbh123/article/details/81201839

      存储结构:

            相同点:都是B+Tree

         什么是B+Tree:   https://www.jianshu.com/p/486a514b0ded

         不同点: 

             因为: 存储的结构不同  innoDB:是将数据与索引放在一起(聚合索引), MyIsam:数据与索引分开(非聚合索引

                        https://www.cnblogs.com/s-b-b/p/8334593.html

            584540129629c63d20b33031eb53813275a.jpg

             上面原因导致:

            b26fcb48fe913b909b96a627a1dd05a2756.jpg

 

      d19509354a531433d7dcb541e929ad44d69.jpg

 

 

4.索引

https://www.cnblogs.com/zuochuang/p/8184349.html

mysql索引类型和索引方法

f66f7877bbc66da3db2406ccdff3423189c.jpg

 

4.1 索引类型

2f408f2fd0efefedfae975ea559714ba9a4.jpg

4.2 单索引 及联合索引

4.2.1 创建 sql语法


-- 单一索引
create index singoleindex on t_user (name) 


-- 联合索引
create index moreIndex on t_user (name,age,other) 

54032ec230b1e3fdb84b56a18bc6cdb7ba6.jpg

 

05a8e8dd81e35b0a66b3f4dbddb617aa3c5.jpg

 

 

4.2.2 联合索引应用:


-- 单一索引
create index singoleindex on t_user (name) 


-- 联合索引
create index moreIndex on t_user (name,age,other) 

-- 1. key_len 为null 表示没有走索引
explain select * from t_user

-- 2.走索引了  33=10*3+2+1  10表示varchar长度  3:utf-8格式  2:非char类型占用  1:数据可以为null
explain select * from t_user where name ='张三'

--  3. 索引失效  原因数据类型不对
explain select * from t_user where name =1

--  4. 索引位置不对   第一索引 没有被用索引其他索引失效
explain select * from t_user where age =15

-- 5.第一个索引不能少  跟顺序有关
explain select * from t_user where name ='张三' and age =15

-- 6. 跳过中间所以 也有效   Using index condition
explain select * from t_user where name ='张三' and other='学生'


-- 7。索引 设计的几个原则
-- 7.1 范围最后 原则

  explain select * from t_user where name ='张三' and age >=15
-- 7.2 最左边原则  2中的列子
-- 8.索引覆盖  
-- 8.1索引失效
explain select * from t_user
-- 索引覆盖 
  explain select t.name,t.age from t_user t
-- 9. like 查询索引情况
-- 9.1 索引失效 因为没有用头索引
explain select * from t_user where other like '%学生%'

-- 9.2  索引没有失效  但是like 字段并没有生效
explain  select * from t_user where name ='张三' and other like '%学生%' 

-- 9.3 测试单索引的like   后%生效   其他不生效   除非发生索引覆盖
-- 索引失效
explain select * from t_user where other like '%学生%'
-- 索引可与使用
explain select * from t_user where other like '学生%'

 

(1) key_len 为null 表示没有走索引

29c7e8f34829717f7ff8df00029fb99932b.jpg

(2)

6cfe4ba0242400d9612406503c8eaf40eba.jpg

(3) 

3eeba485237c23a49d63e92f43d3c9e6609.jpg

 

(4)

db7350736276afdb93cb0d1e9318a2f5e2e.jpg

(5) 

48b9b0720288f0cc734c29841692668e04c.jpg

 

 

(6)

99f9506c32d0553d7bb74e8e66a8f502b1e.jpg

 

(7)

ffbf21a9ed166a0b4d2dcd0767ac8e87c7e.jpg

(8)

bb6803b301b112cf4a06f99cb9a772e85f7.jpg

(9)

我们首先新建  单索引 如下:

3c5ccb851069d1dfe120e78869ed9c59f3d.jpg

 

70c507e5162bd07e192aec1f61d0078c14c.jpg

 

4.3 Extra 的代表含义

de9b7d3bb99a49edde2aa88bc59fbf3d73e.jpg

https://www.cnblogs.com/wy123/p/7366486.html

 

138cd63ebc434fb54a463144c915b5ce737.jpg

 

45b2efdda12140770d08100ec6cb0a4f273.jpg

 

4.4 key_len 计算

https://www.cnblogs.com/xuanzhi201111/p/4554769.html

 

 

转载于:https://my.oschina.net/u/4132381/blog/3074859

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值