进入console
$ hbase shell
表的管理
1. 查看表
hbase> list
2. 创建表
# 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'
数据操作
1. 添加数据
# syntax: put <table>, <rowkey>, <family:column>, <value>, <timestamp>
hbase> put 't1', 'rk1', 'f1:col1', 'value1'
2. 查询数据
查询某条数据
# 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}
查询数据行数
# syntax: count <table>, {INTERVAL => <interval>, CACHE => <cacheNum>}
# INTERVAL 设置多少行显示一次,默认为1000;CACHE 设置每次取的缓存区大小,默认为10
hbase> count 't1', {INTERVAL => 100, CACHE => 500}
3. 删除数据
删除某行的某个列值
# syntax: delete <table>, <rowkey>, <family:column>, <timestamp>
hbase> delete 't1', 'rk1', 'f1:col1'
删除行
# syntax: deleteall <table>, <rowkey>, <family:column>, <timestamp>
hbase> deleteall 't1', 'rk1'
删除表中的所有数据
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'