使用hbase shell CLI在Hbase中创建表、在表中插入行、对表执行放置和扫描操作、启用或禁用表以及启动和停止Hbase
主要描述了Hbase的CRUD等基本DDL和DML操作
$ ./bin/hbase shell
HBase Shell; enter 'help<RETURN>' for list of supported commands.
Type "exit" to leave the HBase Shell
Version: 0.90.0, r1001068, Fri Sep 24 13:55:42 PDT 2010
hbase(main):001:0> version
hbase(main):001:0> help 'create'
status
list
list_namespace
create_namespace 'ns1'
drop_namespace 'ns1'
hbase> alter_namespace 'ns', {METHOD => 'set', 'PROPERTY_NAME' => 'PROPERTY_VALUE'}
hbase(main):003:0> create 'test', 'cf'
0 row(s) in 1.2200 seconds
hbase(main):003:0> list 'table'
test
1 row(s) in 0.0550 seconds
hbase(main):004:0> put 'test', 'row1', 'cf:a', 'value1'
0 row(s) in 0.0560 seconds
hbase(main):005:0> put 'test', 'row2', 'cf:b', 'value2'
0 row(s) in 0.0370 seconds
hbase(main):006:0> put 'test', 'row3', 'cf:c', 'value3'
0 row(s) in 0.0450 seconds
//列出指定空间下的所有表
list_namespace_tables 'ns1'
//列出所有表
list
hbase(main):003:0> describe 'test'
Table test is ENABLED
test
COLUMN FAMILIES DESCRIPTION
{NAME => 'cf', VERSIONS => '1', EVICT_BLOCKS_ON_CLOSE => 'false', NEW_VERSION_BEHAVIOR => 'false', KEEP_DELETED_CELLS => 'FALSE', CACHE_DATA_ON_WRITE =>
'false', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', MIN_VERSIONS => '0', REPLICATION_SCOPE => '0', BLOOMFILTER => 'ROW', CACHE_INDEX_ON_WRITE => 'f
alse', IN_MEMORY => 'false', CACHE_BLOOMS_ON_WRITE => 'false', PREFETCH_BLOCKS_ON_OPEN => 'false', COMPRESSION => 'NONE', BLOCKCACHE => 'true', BLOCKSIZE
=> '65536'}
1 row(s)
Took 0.9998 seconds
exists 'test'
hbase(main):003:0> put 'test', 'row1', 'cf:a', 'value1'
0 row(s) in 0.0850 seconds
hbase(main):004:0> put 'test', 'row2', 'cf:b', 'value2'
0 row(s) in 0.0110 seconds
hbase(main):005:0> put 'test', 'row3', 'cf:c', 'value3'
0 row(s) in 0.0100 seconds
hbase(main):005:0> put 'test', 'row3', 'cf:c', 'value4'
0 row(s) in 0.0100 seconds
查询前几条数据
scan 'test',{LIMIT=>5}
#查询从指定行到结束行
hbase(main):009:0> scan 'test',{STARTROW => '1001', STOPROW => '1001'}
#查询从指定行开始五条
hbase(main):010:0> scan 'test',{STARTROW => '1001',LIMIT=>5}
drop 'test'
//删除某rowkey的全部数据
deleteall 'test','1001'
//删除某rowkey的某一列数据
delete 'test','row1','cf:a'
alter 'test','cf1'
hbase(main):016:0> alter 'test',{NAME => 'cf',METHOD => 'delete'}
hbase(main):022:0> alter 'test',{NAME=>'cf',VERSIONS=>3}
hbase(main):022:0> get 'test','1001',{COLUMN=>'cf:a',VERSIONS=>3}