HBase 常用命令

时间:2022-06-22
本文章向大家介绍HBase 常用命令,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

1. 启动 HBase Shell , 在 HBase 目录下执行

bin/hbase shell

注意: 在 HBase Shell 中如果按退格键无法删除 , 则需要按 Ctrl + backspace 键

2. 建表 , 表名 scores , 有两个列簇 grade , course

get 't1','r1'
get 't1','r1','c1'
get 't1','r1','c1','c2'
create 'scores','grade','course'

3. 查看 HBase 中的表

list

4. 查看表结构

describe 'scores'

5. 向表中写入数据

put 't1','r1','c1','value',ts1

t1 : 表名 | r1 : 行键 | c1 : 列名 | value : 值 | ts1 : 数据的时间戳(一般都省略不设置)

put 'scores','Tom','grade',5            //qualifier为空
put 'scores','Tom','course:math',89     //qualifier不为空

6. 随机查找数据 get

get 't1','r1'
get 't1','r1','c1'
get 't1','r1','c1:q1'
get 't1','r1','c1','c2'
get 't1','r1',{COLUMN=>'c1',TIMESTAMP=>ts1}
get 't1','r1',{COLUMN=>'c1',TIMERANGE=>[ts1,ts2],VERSIONS=>4}    //这里的VERSIONS暂时还不知道咋用

// 举个栗子
get 'scores','Tom','grade'
get 'scores','Tom','course:math'
get 'scores','Tom','grade','course'

7. 范围查找数据 scan

scan 't1'
scan 't1',{COLUMNS=>'c1'}
scan 't1',{COLUMNS=>'c1:q1'}
scan 't1',{COLUMNS=>['c1','c2'],LIMIT=>10,STARTROW=>'xxx'}
scan 't1',{REVERSED=>true}   //反向查找

8. 删除数据

delete 't1','r1','c1',ts1    // ts1我测试貌似没用
// 举例
delete 'scores','jim','course:math'
// 删除全表数据
truncate 'scores' 

9. 修改表结构

// 添加一个列簇
alter 'scores',NAME=>'profile'
// 删除一个列簇
alter 'scores',NAME=>'profile',METHOD=>'delete'

10. 删除表

// 分两步,先disable, 然后在 drop
disable 't1'
drop 't1'

如果有错误欢迎指正!