進入console
$ hbase shell
表的管理
1. 查看表
hbase> list
2. 創(chuàng)建表
# syntax: create <table>, {NAME => <family>, VERSIONS => <version>}
hbase> create 't1', {NAME => 'f1'}, NAME => 'f2', VERSION => 2}
3. 刪除表
需要先disable
hbase> disable 't1'
hbase> drop 't1'
4. 查看表結構
hbase> describe 't1'
5. 修改表結構
需要先disable
# syntax: alter <table>, {NAME => <family>, <property> => <value>}
hbase> disable 't1'
hbase> alter 't1', {NAME => 'f1', TTL => '3600'}
hbase> enable 't1'
權限管理
1. 分配權限
# syntax: grant <user>, <permission>, <table>, <column family>, <column qualifier>
# permission: "RWXCA"
# READ('R'), WRITE('W'), EXEC('X'), CREATE('C'), ADMIN('A')
hbase> grant 'u1', 'RW', 't1'
2. 查看權限
hbase> user_permission 't1'
3. 收回權限
hbase> revoke 'u1', 't1'
數(shù)據(jù)操作
1. 添加數(shù)據(jù)
# syntax: put <table>, <rowkey>, <family:column>, <value>, <timestamp>
hbase> put 't1', 'rk1', 'f1:col1', 'value1'
2. 查詢數(shù)據(jù)
查詢某條數(shù)據(jù)
# syntax: get <table>, <rowkey>, [<family:column>, ...]
hbase> get 't1', 'rk1', 'f1:col1'
hbase> get 't1', 'rk1', {COLUMN => 'f1:col1'}
hbase> get 't1', 'rk1'
掃描表
# syntax: scan <table>, {COLUMN => [<family:column>, ...], LIMIT => <num>}
# 還可添加STARTROW, TIMERANGE 和FILTER 等條件
hbase> scan 't1', {LIMIT => 5}
查詢數(shù)據(jù)行數(shù)
# syntax: count <table>, {INTERVAL => <interval>, CACHE => <cacheNum>}
# INTERVAL 設置多少行顯示一次,默認為1000蒜撮;CACHE 設置每次取的緩存區(qū)大小仆救,默認為10
hbase> count 't1', {INTERVAL => 100, CACHE => 500}
3. 刪除數(shù)據(jù)
刪除某行的某個列值
# syntax: delete <table>, <rowkey>, <family:column>, <timestamp>
hbase> delete 't1', 'rk1', 'f1:col1'
刪除行
# syntax: deleteall <table>, <rowkey>, <family:column>, <timestamp>
hbase> deleteall 't1', 'rk1'
刪除表中的所有數(shù)據(jù)
hbase> truncate 't1'
Region 管理
1. 移動region
# syntax: move 'encodedRegionName', 'regionServerName'
hbase> move 'fd936a7b2233f81f59dd22d9fa924af2', 'ip-10-1-1-1.abc.co,60020,1488623785036'
2. 開啟/關閉balance
# syntax: balance_switch true | false
hbase> balance_switch false
3. 手動split
# syntax: split 'regionName', 'splitKey'
4. 手動major compaction
# compact all regions in a table
hbase> major_compact 't1'
# Compact an entire region
hbase> major_compact 'r1'
#Compact a single column family within a region
hbase> major_compact 'r1', 'f1'