在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)