首先,在命令行中启动MySQL服务;
service mysql start
MySQL服务启动后,在命令行中输入mysql的用户名和密码登录到MySQL;
mysql -u root -p
登录到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)
对索引进行排序后,重新查看表结构,即可看到索引排序的效果;
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)