Hbase的常用shell操作

  • 1.进入hbase的shell界面:
[root@lijie bin]# ./hbase shell
  • 2.创建表
hbase(main):002:0> create 'tablename','cf1','cf2'
0 row(s) in 0.5830 seconds

=> Hbase::Table - tablename
  • 3.列出所有表
hbase(main):003:0> list
TABLE                                                                                                                                                              
stu                                                                                                                                                                
t1                                                                                                                                                                 
tablename                                                                                                                                                          
3 row(s) in 0.0100 seconds

=> ["stu", "t1", "tablename"]
  • 4.插入数据
hbase(main):005:0> put 'tablename','rowkey01','cf1:name','lijie'
0 row(s) in 0.0570 seconds

hbase(main):006:0> put 'tablename','rowkey01','cf1:addr','chongqing'
0 row(s) in 0.0070 seconds
  • 5.查看表的所有数据
hbase(main):012:0> scan 'tablename'
ROW                                       COLUMN+CELL                                                                                                              
 rowkey01                                 column=cf1:addr, timestamp=1486547683853, value=chongqing                                                                
 rowkey01                                 column=cf1:name, timestamp=1486547607486, value=lijie                                                                    
 rowkey02                                 column=cf1:addr, timestamp=1486547771954, value=shenzhen                                                                 
 rowkey02                                 column=cf1:name, timestamp=1486547737573, value=zhangsan                                                                 
2 row(s) in 0.0280 seconds
  • 6.根据rowkey查看数据
hbase(main):015:0> get 'tablename','rowkey01'
COLUMN                                    CELL                                                                                                                     
 cf1:addr                                 timestamp=1486547683853, value=chongqing                                                                                 
 cf1:name                                 timestamp=1486547607486, value=lijie                                                                                     
2 row(s) in 0.0250 seconds
  • 7.查询数据的条数
hbase(main):016:0> count 'tablename'
2 row(s) in 0.0410 seconds

=> 2
  • 8.获取一行指定列族的数据
hbase(main):017:0> get 'tablename','rowkey01','cf1'
COLUMN                                    CELL                                                                                                                     
 cf1:addr                                 timestamp=1486547683853, value=chongqing                                                                                 
 cf1:name                                 timestamp=1486547607486, value=lijie                                                                                     
2 row(s) in 0.0120 seconds
  • 9.获取一行指定列族某列数据
hbase(main):021:0> get 'tablename','rowkey01','cf1:name'
COLUMN                                    CELL                                                                                                                     
 cf1:name                                 timestamp=1486547607486, value=lijie                                                                                     
1 row(s) in 0.0080 seconds
  • 10.删除列族
hbase(main):027:0> delete 'tablename','rowkey01','cf1:addr'
0 row(s) in 0.0030 seconds
  • 11.删除一整行数据
hbase(main):029:0> deleteall 'tablename','rowkey01' 
0 row(s) in 0.0090 seconds
  • 12.更新一条数据
hbase(main):032:0> put 'tablename','rowkey02','cf1:addr','shanghai'
0 row(s) in 0.0040 seconds
  • 13.是否enable或者disable
hbase(main):034:0> is_enabled 'tablename'
true                                                                                                                                                               
0 row(s) in 0.0070 seconds

hbase(main):035:0> is_disabled 'tablename'
false                                                                                                                                                              
0 row(s) in 0.0050 seconds
  • 14.查看表是否存在
hbase(main):036:0> exists 'tablename'
Table tablename does exist                                                                                                                                         
0 row(s) in 0.0050 seconds
  • 15.服务器状态
hbase(main):037:0> status
1 servers, 0 dead, 5.0000 average load
  • 16.hbase版本
hbase(main):039:0> version
1.0.3, rf1e1312f9790a7c40f6a4b5a1bab2ea1dd559890, Tue Jan 19 19:26:53 PST 2016
  • 17.删除一个列族
hbase(main):040:0> disable 'tablename'
0 row(s) in 1.2310 seconds

hbase(main):041:0> alter 'tablename',{NAME => 'cf1',METHOD => 'delete'} 
Updating all regions with the new schema...
1/1 regions updated.
Done.
0 row(s) in 1.1460 seconds

hbase(main):042:0> enable 'tablename'
0 row(s) in 0.1550 seconds
  • 18.获得表的描述
hbase(main):044:0> describe 'tablename'
Table tablename is ENABLED                                                                                                                                         
tablename                                                                                                                                                          
COLUMN FAMILIES DESCRIPTION                                                                                                                                        
{NAME => 'cf2', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', VERSIONS => '1', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => 
'FOREVER', KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'}                                                        
1 row(s) in 0.0150 seconds

hbase(main):045:0> desc 'tablename'
Table tablename is ENABLED                                                                                                                                         
tablename                                                                                                                                                          
COLUMN FAMILIES DESCRIPTION                                                                                                                                        
{NAME => 'cf2', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', VERSIONS => '1', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => 
'FOREVER', KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'}                                                        
1 row(s) in 0.0240 seconds
  • 19.清空整个表
hbase(main):046:0> truncate 'tablename'
Truncating 'tablename' table (it may take a while):
 - Disabling table...
 - Truncating table...
0 row(s) in 1.3600 seconds
  • 20.删除整个表
hbase(main):048:0> disable 'tablename'
0 row(s) in 1.1720 seconds

hbase(main):049:0> drop 'tablename'
0 row(s) in 0.1720 seconds

hbase(main):050:0> list
TABLE                                                                                                                                                              
stu                                                                                                                                                                
t1                                                                                                                                                                 
2 row(s) in 0.0100 seconds

=> ["stu", "t1"]

下次更新filter操作,未完待续。。。。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值