Mysql如何使用索引排序 数据库索引排序怎么实现的

博主:xiaoweixiaowei 2022-12-19 条评论

mysql中使用索引排序的方法

1.首先,在命令行中启动MySQL服务;

service mysql start  

2.MySQL服务启动后,在命令行中输入mysql的用户名和密码登录到MySQL;

mysql -u root -p

3.登录到MySQL后,选择使用一个数据库,并在数据库中执行以下命令对索引进行排序;

use mysql;

mExplain select name, founded from artist where name like 'AUSTRALIA%' order by name G

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

id: 1

select_type: SIMPLE

table: artist

type: range

possible_keys: name

key: name

key_len: 257

ref: NULL

rows: 22

Extra: Using index condition

1 row in set (0.00 sec)

4.对索引进行排序后,重新查看表结构,即可看到索引排序的效果;

mysql> show session status like '%sort%';

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

| Variable_name | Value |

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

| Sort_merge_passes | 0 |

| Sort_range | 0 |

| Sort_rows | 0 |

| Sort_scan | 0 |

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

4 rows in set (0.00 sec)

mysql> select name, founded from artist where name like 'AUSTRALIA%' order by name G

......

22 rows in set (0.00 sec)

mysql> show session status like '%sort%';

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

| Variable_name | Value |

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

| Sort_merge_passes | 0 |

| Sort_range | 0 |

| Sort_rows | 0 |

| Sort_scan | 0 |

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

4 rows in set (0.00 sec)

The End

发布于:2022-12-19,除非注明,否则均为 主机评测原创文章,转载请注明出处。