Hbase常用命令

技术主题

使用hbase shell CLI在Hbase中创建表、在表中插入行、对表执行放置和扫描操作、启用或禁用表以及启动和停止Hbase
主要描述了Hbase的CRUD等基本DDL和DML操作

一:连接HBase并查看版本

$ ./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}

你可能感兴趣的:(hbase,hbase,java,大数据)