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<RETURN>" 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}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ZhiguoXue_IT

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值