hadoop学习笔记(11)——hbase shell简单操作示例

1) 表设计

这里写图片描述

2) 建表scores,具有两个列族:grad和course

[root@master bin]# hbase shell
hbase(main):002:0> create 'scores','grade','course'
0 row(s) in 7.6340 seconds
=> Hbase::Table - scores

3) 查看Hasee中有哪些表

hbase(main):003:0> list
TABLE                                                                                                                                 
scores                                                                                                                                
1 row(s) in 0.2190 seconds
=> ["scores"]

4) 查看表结构

hbase(main):004:0> describe 'scores'
Table scores is ENABLED                                                                                                               
scores                                                                                                                                
COLUMN FAMILIES DESCRIPTION                                                                                                           
{NAME => 'course', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', VERSIONS => '1', COMPRESSION => 'NON
E', MIN_VERSIONS => '0', TTL => 'FOREVER', KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 't
rue'}                                                                                                                                 
{NAME => 'grade', 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 => 'tr
ue'}                                                                                                                                  
2 row(s) in 0.5300 seconds

5) 添加数据

a) 行名称为 Tom 列名为grad, 值为1

hbase(main):005:0> put 'scores','Tom','grade:','1'

b) 给Tom这一行的数据的列族添加一列

hbase(main):005:0> put 'scores','Tom','course:math','93'

c) 给Tom这一行的数据的列族添加一列

hbase(main):005:0> put 'scores','Tom','course:art','82'

d) 行名称为 Sam 列名为grad, 值为2

hbase(main):005:0> put 'scores','Sam','grade:','2'

e) 给Sam这一行的数据的列族添加一列

hbase(main):005:0> put 'scores','Sam','course:math','97'

f) 给Sam这一行的数据的列族添加一列

hbase(main):005:0> put 'scores','Sam','course:art','76'

6) 查看scores表中Tom的相关数据

hbase(main):014:0> get 'scores','Tom'
COLUMN                             CELL                                                                                               
 course:art                        timestamp=1453694601377, value=76                                                                  
 course:math                       timestamp=1453694113182, value=93                                                                  
 grade:                            timestamp=1453694015658, value=1                                                                   
3 row(s) in 0.0190 seconds

7) 查看scores表中所有数据

hbase(main):015:0> scan 'scores'
ROW                   COLUMN+CELL                                                                                        
 Sam        column=course:art, timestamp=1453694637826, value=82                                               
 Sam        column=course:math, timestamp=1453694531258, value=97                                              
 Sam        column=grade:, timestamp=1453694479156, value=2                                                    
 Tom        column=course:art, timestamp=1453694601377, value=76                                               
 Tom        column=course:math, timestamp=1453694113182, value=93                                              
 Tom        column=grade:, timestamp=1453694015658, value=1                                                    
2 row(s) in 0.1770 seconds

8) 查看scores表中所有数据courses列族的所有数据

hbase(main):015:0> scan "scores",{COLUMNS => ['course:math']}
hbase(main):015:0> scan "scores",{COLUMNS => ['course']}
ROW       COLUMN+CELL                                                                                        
 Sam      column=course:art, timestamp=1453694637826, value=82                                               
 Sam      column=course:math, timestamp=1453694531258, value=97                                              
 Tom      column=course:art, timestamp=1453694601377, value=76                                               
 Tom      column=course:math, timestamp=1453694113182, value=93                                              
2 row(s) in 0.0250 seconds

9) delete表记录

hbase(main):015:0> delete 'scores','Tom','course:ctrl'

10) count表记录

hbase(main):025:0> count 'scores'
2 row(s) in 0.1310 seconds
=> 2

11) exists表

hbase(main):027:0> exists 'scores'
Table scores does exist                                                                                                               
0 row(s) in 0.0120 seconds
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值