hbase终端常用命令

1、服务器中输入“hbase shell ” ,连接hbase

2、查询所有表

hbase(main):001:0>list

3、查看某表所有数据 scan '命名空间:表名'

hbase(main):001:0>scan 'db1:t1' 

4、limit 指定条数

hbase(main):001:0>scan 'db1:t1' ,{LIMIT =>3}

5、通过主键查询 get '命名空间:表名' ,'rowkey'

hbase(main):001:0>get 'db1:t1' ,'rowkey001'

6、通过指定列查询 

get <table>,<rowkey>,[<family:column>,....] 或 get <table>,<rowkey>,[COLUMN=><family:column>,....] 

例如:查询表t1,rowkey001中的f1下的col1的值

hbase(main):001:0> get 't1','rowkey001', 'f1:col1'

 或者:

hbase(main)> get 't1','rowkey001', {COLUMN=>'f1:col1'}

hbase(main)> get 'emp', '2', {COLUMN=>'personal data:name'}

7、Filter是一个非常强大的修饰词,可以设定一系列条件来进行过滤。比如我们要限制某个列的值等于26
hbase(main):001:0>scan 'member', FILTER=>"ValueFilter(=,'binary:26’)"

7、删除指定行的所有元素值(deleteall <table>, <rowkey>)

hbase(main):001:0>deleteall 'db1:t1','rowkey001'

8、删除行中的某个列值(delete <table>, <rowkey>, <family:column>必须指定列名)

hbase(main):001:0>delete 'test1','rowkey001','f1:col1'

9、删除表(分两步:首先disable,然后drop)

hbase(main):001:0> disable 't1'
hbase(main):001:0> drop 't1'

10、HBase表的清空

hbase(main):001:0> truncate 't1'

 11、插入数据

put 'tablename','row','colfamily:colname','value'

举例:

spark on hbase 中创建表

create table hv2_u1test (key int ,cid string ,csalary float) using org.apache.spark.sql.hbase.HBaseSourceV2 options
(hbaseTableName "table1_v2", keyCols "key", colsMapping "cid=cf1.cq1,csalary=cf1.cq2");

hbase(main)>put 'table1_v2','8','cf1:cq1','asdf8'
hbase(main)>put 'table1_v2','8','cf1:cq2',4577.08

12、退出

hbase(main)>exit 

更多可参考

https://www.cnblogs.com/cxzdy/p/5583239.html

https://www.cnblogs.com/gongxr/p/7808286.html

原文地址:https://www.cnblogs.com/cailingsunny/p/11416559.html