1
2
3
4
5
6
7
8
9
10
11
12
13
14
# 打开一个表名为 tbl_name 的表的句柄
HANDLER tbl_name OPEN [ [AS] alias]

# 2、通过索引查看表
# FIRST: 获取第一行(索引最小的一行)
# NEXT: 获取下一行
# PREV: 获取上一行
# LAST: 获取最后一行(索引最大的一行)
HANDLER tbl_name READ index_name { FIRST | NEXT | PREV | LAST }
[ WHERE where_condition ] [LIMIT ... ]

# 关闭以打开的句柄
HANDLER tbl_name CLOSE

完整使用实例:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48

MariaDB [mysql]> handler www open;
Query OK, 0 rows affected (0.000 sec)

MariaDB [mysql]> handler www read first;
+------+--------+
| id | name |
+------+--------+
| 3 | 张三 |
+------+--------+
1 row in set (0.000 sec)

MariaDB [mysql]> handler www read next;
+------+--------+
| id | name |
+------+--------+
| 3 | 张三 |
+------+--------+
1 row in set (0.000 sec)

MariaDB [mysql]> selct * from www;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'selct * from www' at line 1
MariaDB [mysql]> select * from www;
+------+--------+
| id | name |
+------+--------+
| 3 | 张三 |
| 3 | 张三 |
| 4 | 李四 |
+------+--------+
3 rows in set (0.000 sec)

MariaDB [mysql]> handler www read next;
+------+--------+
| id | name |
+------+--------+
| 4 | 李四 |
+------+--------+
1 row in set (0.000 sec)

MariaDB [mysql]> handler www read next;
Empty set (0.000 sec)

MariaDB [mysql]> handler close;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 1
MariaDB [mysql]> handler www close;
Query OK, 0 rows affected (0.000 sec)