博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
MySQL索引
阅读量:6112 次
发布时间:2019-06-21

本文共 5036 字,大约阅读时间需要 16 分钟。

MySQL基础

单进程多线程:    用户连接:连接线程       MySQL数据文件类型:        数据文件、索引文件        重做日志、撤消日志、二进制日志、错误日志、查询日志、慢查询日志、(中继日志)DDL & DML:    索引管理:            按特定数据结构存储的数据;        索引类型:            聚集索引、非聚集索引:数据是否与索引存储在一起;            主键索引、辅助索引            稠密索引、稀疏索引:是否索引了每一个数据项;            B+ TREE、HASH、R TREE            简单索引、组合索引            左前缀索引            覆盖索引        管理索引的途径:            创建索引:创建表时指定;CREATE INDEX            创建或删除索引:修改表的命令            删除索引:DROP INDEX            查看表上的索引:                SHOW {INDEX | INDEXES | KEYS}                    {FROM | IN} tbl_name                    [{FROM | IN} db_name]                    [WHERE expr]        索引的创建可以使用ALTER、CREATE命令创建:        mysql> CREATE INDEX name ON student (name);        Query OK, 0 rows affected (0.12 sec)        Records: 0  Duplicates: 0  Warnings: 0        mysql> SHOW INDEXES FROM student;        +---------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+        | Table   | Non_unique | Key_name | Seq_in_index | Column_name | Collation | Cardinality | Sub_part | Packed | Null | Index_type | Comment | Index_comment |        +---------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+        | student |          0 | PRIMARY  |            1 | id          | A         |          10 |     NULL | NULL   |      | BTREE      |         |               |        | student |          1 | name     |            1 | name        | A         |          10 |     NULL | NULL   |      | BTREE      |         |               |        +---------+------------+----------+--------------+-------------+-----------+-------------+----------+--------+------+------------+---------+---------------+        2 rows in set (0.00 sec)        mysql>            EXPLAIN   #确认是否有使用到索引进行查询。            mysql> EXPLAIN SELECT * FROM students WHERE id=3;            mysql> select * from student;            +----+----------+---------------+------+            | id | name     | register_date | sex  |            +----+----------+---------------+------+            |  1 | ZhanYang | 2018-06-20    | NULL |            |  4 | LiuJia   | 2018-05-30    | NULL |            |  8 | JiaLiu   | 2018-06-20    | NULL |            |  9 | JiaLiu   | 2018-04-20    | NULL |            | 10 | gaoyf    | 2018-04-20    | NULL |            | 11 | zhujh    | 2018-04-20    | NULL |            | 12 | zhouha   | 2018-04-20    | NULL |            | 13 | hanzb    | 2018-04-21    | M    |            | 16 | ZhanXing | 2018-05-21    | M    |            | 17 | XingYan  | 2018-05-21    | M    |            +----+----------+---------------+------+            10 rows in set (0.01 sec)            mysql> EXPLAIN SELECT * FROM student  WHERE id=4;            +----+-------------+---------+-------+---------------+---------+---------+-------+------+-------+            | id | select_type | table   | type  | possible_keys | key     | key_len | ref   | rows | Extra |            +----+-------------+---------+-------+---------------+---------+---------+-------+------+-------+            |  1 | SIMPLE      | student | const | PRIMARY       | PRIMARY | 4       | const |    1 | NULL  |            +----+-------------+---------+-------+---------------+---------+---------+-------+------+-------+            1 row in set (0.01 sec)            mysql> EXPLAIN SELECT * FROM student  WHERE id=4\G            *************************** 1. row ***************************                       id: 1              select_type: SIMPLE                    table: student                     type: const            possible_keys: PRIMARY                      key: PRIMARY                  key_len: 4                      ref: const                     rows: 1                    Extra: NULL            1 row in set (0.00 sec)        mysql> EXPLAIN SELECT * FROM student WHERE name LIKE '%X%';        +----+-------------+---------+------+---------------+------+---------+------+------+-------------+        | id | select_type | table   | type | possible_keys | key  | key_len | ref  | rows | Extra       |        +----+-------------+---------+------+---------------+------+---------+------+------+-------------+        |  1 | SIMPLE      | student | ALL  | NULL          | NULL | NULL    | NULL |   10 | Using where |        +----+-------------+---------+------+---------------+------+---------+------+------+-------------+        1 row in set (0.00 sec)        mysql> EXPLAIN SELECT * FROM student WHERE name LIKE '%X%'\G        *************************** 1. row ***************************                   id: 1          select_type: SIMPLE                table: student                 type: ALL        possible_keys: NULL                  key: NULL              key_len: NULL                  ref: NULL                 rows: 10                Extra: Using where        1 row in set (0.01 sec)    DESC命令用于获取数据表结构

转载于:https://blog.51cto.com/zhanx/2348157

你可能感兴趣的文章
Oracle 冷备份
查看>>
jq漂亮实用的select,select选中后,显示对应内容
查看>>
C 函数sscanf()的用法
查看>>
python模块之hashlib: md5和sha算法
查看>>
linux系统安装的引导镜像制作流程分享
查看>>
解决ros建***能登录不能访问内网远程桌面的问题
查看>>
pfsense锁住自己
查看>>
vsftpd 相关总结
查看>>
bash complete -C command
查看>>
解决zabbix 3.0中1151端口不能运行问题
查看>>
售前工程师的成长---一个老员工的经验之谈
查看>>
Get到的优秀博客网址
查看>>
dubbo
查看>>
【Git入门之四】操作项目
查看>>
老男孩教育每日一题-第107天-简述你对***的理解,常见的有哪几种?
查看>>
Python学习--time
查看>>
在OSCHINA上的第一篇博文,以后好好学习吧
查看>>
高利率时代的结局,任重道远,前途叵测
查看>>
Debian 6.05安装后乱码
查看>>
欢迎大家观看本人录制的51CTO精彩视频课程!
查看>>