mysql 二進位制 索引 MySQL索引

2021-10-18 01:52:03 字數 3017 閱讀 8731

mysql基礎

單程序多執行緒:

使用者連線:連線線程

mysql資料檔案型別:

資料檔案、索引檔案

重做日誌、撤消日誌、二進位制日誌、錯誤日誌、查詢日誌、慢查詢日誌、(中繼日誌)

ddl & dml:

索引管理:

按特定資料結構儲存的資料;

索引型別:

聚集索引、非聚集索引:資料是否與索引儲存在一起;

主鍵索引、輔助索引

稠密索引、稀疏索引:是否索引了每乙個資料項;

b+ tree、hash、r tree

簡單索引、組合索引

左字首索引

覆蓋索引

管理索引的途徑:

建立索引:建立表時指定;create index

建立或刪除索引:修改表的命令

刪除索引:drop index

檢視表上的索引:

show

tbl_name

[ 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 | *** |

| 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 | ****** | 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: ******

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 | ****** | 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: ******

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命令用於獲取資料表結構

mysql二進位制 MySql二進位制連線方式詳解

使用mysql二進位制方式連線 您可以使用mysql二進位制方式進入到mysql命令提示符下來連線mysql資料庫。例項以下是從命令列中連線mysql伺服器的簡單例項 root host mysql u root p enter password 在登入成功後會出現 mysql 命令提示視窗,你可以...

mysql二進位制恢復 mysql二進位制日誌恢復

二進位制日誌匯出 1.按時間節點匯出 no defaults 用來對mysql5.5之前mysqlbinlog命令報錯 mysqlbinlog no defaults start date 2017 08 08 15 04 04 stop date 2017 08 08 15 12 00 progr...

mysql二進位制方式 MySql二進位制連線方式詳解

使用mysql二進位制方式連線 您可以使用mysql二進位制方式進入到mysql命令提示符下來連線mysql資料庫。例項以下是從命令列中連線mysql伺服器的簡單例項 複製 如下 root host mysql u root p enter password 在登入成功後會出現 mysql 命令提示...