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
更多可參考