Skip to content

Latest commit

 

History

History
132 lines (100 loc) · 2.99 KB

hbase-cli.md

File metadata and controls

132 lines (100 loc) · 2.99 KB
title date
HBase 命令
2019-03-06

HBase 命令

1. 连接 HBase

$ ./bin/hbase shell
hbase(main):001:0>

2. 查询帮助

help

3. 创建表

create 'table1','columnFamliy1','columnFamliy2'

说明:

创建一张名为 table1 的 HBase 表,columnFamliy1、columnFamliy2 是 table1 表的列族。

4. 查看表信息

list 'table1'

5. 查看表详细信息

describe 'table1'

6. 向表中写数据

put 'table1', 'row1', 'columnFamliy1:a', 'valueA'
put 'table1', 'row1', 'columnFamliy1:b', 'valueB'
put 'table1', 'row1', 'columnFamliy1:c', 'valueC'

put 'table1', 'row2', 'columnFamliy1:a', 'valueA'
put 'table1', 'row2', 'columnFamliy1:b', 'valueB'
put 'table1', 'row2', 'columnFamliy1:c', 'valueC'

put 'table1', 'row1', 'columnFamliy2:a', 'valueA'
put 'table1', 'row1', 'columnFamliy2:b', 'valueB'
put 'table1', 'row1', 'columnFamliy2:c', 'valueC'

7. 扫描表

hbase> scan 'hbase:meta'
hbase> scan 'hbase:meta', {COLUMNS => 'info:regioninfo'}
hbase> scan 'ns1:
hbase> scan 't1', {COLUMNS => ['c1', 'c2'], LIMIT => 10, STARTROW => 'xyz'}
hbase> scan 't1', {COLUMNS => 'c1', TIMERANGE => [1303668804, 1303668904]}
hbase> scan 't1', {REVERSED => true}
hbase> scan 't1', {ALL_METRICS => true}
hbase> scan 't1', {METRICS => ['RPC_RETRIES', 'ROWS_FILTERED']}
hbase> scan 't1', {ROWPREFIXFILTER => 'row2', FILTER => "
  (QualifierFilter (>=, 'binary:xyz')) AND (TimestampsFilter ( 123, 456))"}
hbase> scan 't1', {FILTER =>
  org.apache.hadoop.hbase.filter.ColumnPaginationFilter.new(1, 0)}
hbase> scan 't1', {CONSISTENCY => 'TIMELINE'}
For setting the Operation Attributes 
hbase> scan 't1', { COLUMNS => ['c1', 'c2'], ATTRIBUTES => {'mykey' => 'myvalue'}}
hbase> scan 't1', { COLUMNS => ['c1', 'c2'], AUTHORIZATIONS => ['PRIVATE','SECRET']}
For experts, there is an additional option -- CACHE_BLOCKS -- which
switches block caching for the scanner on (true) or off (false).  By
default it is enabled.  Examples:

hbase> scan 't1', {COLUMNS => ['c1', 'c2'], CACHE_BLOCKS => false}

8. 查询 row

get 'table1', 'row1'
get 'table1', 'row1', 'columnFamliy1'
get 'table1', 'row1', 'columnFamliy1:a'

9. 禁用、启用表

hbase(main):008:0> disable 'test'
0 row(s) in 1.1820 seconds

hbase(main):009:0> enable 'test'
0 row(s) in 0.1770 seconds

10. 删除表

hbase(main):011:0> drop 'test'
0 row(s) in 0.1370 seconds

11. 停止 HBase

$ ./bin/stop-hbase.sh
stopping hbase....................
$