forked from MoRan1607/BigDataGuide
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path3、HBase Shell操作.md
91 lines (78 loc) · 2.3 KB
/
3、HBase Shell操作.md
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
三、HBase Shell操作
---
### 1、基本操作
1)进入HBase客户端命令行
```txt
[drift@hadoop102 hbase]$ bin/hbase shell
```
2)查看帮助命令
```txt
hbase(main):001:0> help
```
3)查看当前数据库中有哪些表
```txt
hbase(main):002:0> list
```
### 2、表的操作
1)创建表
```txt
hbase(main):002:0> create 'student','info'
```
2)插入数据到表
```txt
hbase(main):003:0> put 'student','1001','info:sex','male'
hbase(main):004:0> put 'student','1001','info:age','18'
hbase(main):005:0> put 'student','1002','info:name','Janna'
hbase(main):006:0> put 'student','1002','info:sex','female'
hbase(main):007:0> put 'student','1002','info:age','20'
```
3)扫描查看表数据
```txt
hbase(main):008:0> scan 'student'
hbase(main):009:0> scan 'student',{STARTROW => '1001', STOPROW => '1001'}
hbase(main):010:0> scan 'student',{STARTROW => '1001'}
```
4)查看表结构
```txt
hbase(main):011:0> describe 'student'
```
5)更新指定字段的数据
```txt
hbase(main):012:0> put 'student','1001','info:name','Nick'
hbase(main):013:0> put 'student','1001','info:age','100'
```
6)查看“指定行”或“指定列族:列”的数据
```txt
hbase(main):014:0> get 'student','1001'
hbase(main):015:0> get 'student','1001','info:name'
```
7)统计表数据行数
```txt
hbase(main):021:0> count 'student'
```
8)删除数据
```txt
删除某rowkey的全部数据:
hbase(main):016:0> deleteall 'student','1001'
删除某rowkey的某一列数据:
hbase(main):017:0> delete 'student','1002','info:sex'
```
9)清空表数据
```txt
hbase(main):018:0> truncate 'student'
提示:清空表的操作顺序为先disable,然后再truncate。
```
10)删除表
```txt
首先需要先让该表为disable状态:
hbase(main):019:0> disable 'student'
然后才能drop这个表:
hbase(main):020:0> drop 'student'
提示:如果直接drop表,会报错:ERROR: Table student is enabled. Disable it first.
```
11)变更表信息
```txt
将info列族中的数据存放3个版本:
hbase(main):022:0> alter 'student',{NAME=>'info',VERSIONS=>3}
hbase(main):022:0> get 'student','1001',{COLUMN=>'info:name',VERSIONS=>3}
```