Hadoop学习笔记(5)-HBase常用Shell命令

status 查看系统状态

1
2
3
hbase(main):001:0> status
1 active master, 0 backup masters, 1 servers, 0 dead, 2.0000 average load
Took 2.7304 seconds

version 查看版本号

1
2
3
hbase(main):002:0> version
2.2.0, rUnknown, Tue Jun 11 04:30:30 UTC 2019
Took 0.0171 seconds

table_help 查看提示信息

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
hbase(main):003:0> table_help
Help for table-reference commands.

You can either create a table via 'create' and then manipulate the table via commands like 'put', 'get', etc.
See the standard help information for how to use each of these commands.

However, as of 0.96, you can also get a reference to a table, on which you can invoke commands.
For instance, you can get create a table and keep around a reference to it via:

hbase> t = create 't', 'cf'

Or, if you have already created the table, you can get a reference to it:

hbase> t = get_table 't'

You can do things like call 'put' on the table:

hbase> t.put 'r', 'cf:q', 'v'

which puts a row 'r' with column family 'cf', qualifier 'q' and value 'v' into table t.

To read the data out, you can scan the table:

hbase> t.scan

which will read all the rows in table 't'.

Essentially, any command that takes a table name can also be done via table reference.
Other commands include things like: get, delete, deleteall,
get_all_columns, get_counter, count, incr. These functions, along with
the standard JRuby object methods are also available via tab completion.

For more information on how to use each of these commands, you can also just type:

hbase> t.help 'scan'

which will output more information on how to use that command.

You can also do general admin actions directly on a table; things like enable, disable,
flush and drop just by typing:

hbase> t.enable
hbase> t.flush
hbase> t.disable
hbase> t.drop

Note that after dropping a table, your reference to it becomes useless and further usage
is undefined (and not recommended).
Took 0.0479 seconds

表的管理

创建表
1
2
3
create '表名', '列族1', '列族2', ...
# 或者
create '表名', {NANE => '列族1', VERSION => '版本数'}, {NAME => '列族2'}, ...

ps: 创建一个表,该表名称为Student,包含4个列族S_ID,S_Name,S_Sex和S_Age

1
2
3
4
hbase(main):004:0> create 'Student','S_ID','S_Name','S_Sex','S_Age'
Created table Student
Took 1.9408 seconds
=> Hbase::Table - Student
list 查看表
1
2
3
4
5
hbase(main):005:0> list
TABLE Student
1 row(s)
Took 0.0890 seconds
=> ["Student"]
enable/disable:使表有效或无效
1
2
3
4
hbase(main):008:0> disable 'Student'
Took 0.0389 seconds
hbase(main):009:0> enable 'Student'
Took 1.3869 seconds s
describe 表的描述
1
2
3
hbase(main):010:0> describe 'Student'
Table Student is ENABLED
.......
drop 表的删除

删除表首先需要利用disable命令禁用表再删除。

1
2
3
4
hbase(main):013:0> disable 'Student'
Took 1.2900 seconds
hbase(main):014:0> drop 'Student'
Took 0.3040 seconds
exists 判断是否存在
1
2
3
4
hbase(main):012:0> exists 'Student'
Table Student does exist
Took 0.0433 seconds
=> true

数据操作

put 增加和修改数据

向表、行、列指定的单元格添加数据,一次只能为一个表的一行数据的一个列添加一个数据

ps: 向表Student中的第1行、第S_ID列,添加数据值为 “111”

1
2
hbase(main):003:0> put 'Student','1','S_ID','111'
Took 0.1942 seconds
get 查询数据

通过表名、行、列、时间戳、时间范围和版本号来获得相应单元格的值

1
2
3
4
5
hbase(main):005:0> get 'Student','1'
COLUMN CELL
S_ID: timestamp=1589004989645, value=111
1 row(s)
Took 0.0987 seconds
scan 浏览表的相关信息
1
2
3
4
5
hbase(main):004:0> scan 'Student'
ROW COLUMN+CELL
1 column=S_ID:, timestamp=1589004989645, value=111
1 row(s)
Took 0.0917 seconds
delete 删除数据
1
2
hbase(main):007:0> delete 'Student','1','S_ID'
Took 0.0804 seconds
count 统计
1
2
3
4
hbase(main):010:0> count 'Student'
1 row(s)
Took 0.1488 seconds
=> 1
truncate 清空表数据
1
2
3
4
5
hbase(main):011:0> truncate 'Student'
Truncating 'Student' table (it may take a while):
Disabling table...
Truncating table...
Took 3.8872 seconds

本文标题:Hadoop学习笔记(5)-HBase常用Shell命令

文章作者:北徯。

发布时间:2020年04月23日 - 00:00:00

最后更新:2020年10月19日 - 10:50:49

原始链接:https://www.xiangjunhong.com/posts/3e8e6c1f.html

许可协议: 署名-非商业性使用-禁止演绎 4.0 国际 转载请保留原文链接及作者。

-------------------本文结束 感谢您的阅读-------------------