在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)
本文来源:https://www.yuntue.com/post/58312.html | 云服务器网,转载请注明出处!