Hbase shell常见命令

shell 命令

启动Hbase shell:

bin/hbase shell

[hadoop@master hbase-1.2.6]$ ./bin/hbase shell 
hbase(main):001:0>

hbase shell 命令的帮助可以通过help查看

hbase>help  #查看帮助
hbase>help 'command' #查看具体命令的帮助

下面介绍一些常见的命令:

  • 命名空间:
    Hbase命名空间可以对比理解为关系型数据库中的database。
    创建namespace:

     hbase(main):032:0> create_namespace 'ns_test'
     0 row(s) in 0.1090 seconds
    

    查看namespace

     hbase(main):034:0> describe_namespace 'ns_test'
     DESCRIPTION                                                                                          
     {NAME => 'ns_test'}                                                                                  
     1 row(s) in 0.0160 seconds
    

    查看所有namespace

     hbase(main):042:0> list_namespace 'ns'
     NAMESPACE                                                                                            
     ns2                                                                                                  
     ns_test                                                                                              
     2 row(s) in 0.0150 seconds
    

    查看namespace下的表

     hbase(main):047:0> list_namespace_tables 'ns_test'
     TABLE                                                                                                
     0 row(s) in 0.0260 seconds
    
  • 表相关:
    创建表

     hbase(main):017:0* create 'ns_test:t1', {NAME=>'f1'}, {NAME=>'f2'}
     0 row(s) in 2.3050 seconds
     
     => Hbase::Table - ns_test:t1
    

    修改表

     # 表t1增加列族f3
     hbase(main):035:0> alter 'ns_test:t1' , 'f3'
     Updating all regions with the new schema...
     0/1 regions updated.
     1/1 regions updated.
     Done.
     0 row(s) in 3.0650 seconds
     注意:生产环境上要为一个表添加一个列簇,一定要先disable这个表,不要直接操作。新增一个列簇对性能影响较大。
    
     # 表t1删除列族f4
     hbase(main):065:0>  alter 'ns_test:t1', NAME => 'f4',METHOD => 'delete'
     Updating all regions with the new schema...
     1/1 regions updated.
     Done.
     0 row(s) in 2.2440 seconds
    

    disable表

     hbase(main):021:0* disable 'ns_test:t1'
     0 row(s) in 2.3210 seconds
    

    enable表

     hbase(main):025:0> enable 'ns_test:t1'
     0 row(s) in 1.3030 seconds
    

    判断表是否存在

     hbase(main):028:0> exists 'ns_test:t1'
     Table ns_test:t1 does exist                                                                          
     0 row(s) in 0.0100 seconds
    

    查看表相关信息

     hbase(main):071:0> describe 'ns_test:t1'
     Table ns_test:t1 is ENABLED                                                                          
     ns_test:t1                                                                                           
     COLUMN FAMILIES DESCRIPTION                                                                          
     {NAME => 'f1', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FA
     LSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BL
     OCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}                                  
     {NAME => 'f2', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FA
     LSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BL
     OCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}                                  
     {NAME => 'f3', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FA
     LSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BL
     OCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}                                  
     3 row(s) in 0.0340 seconds
    

    查看所有表

     hbase(main):087:0* list
     TABLE                                                                                                
     ns2:t1                                                                                               
     ns2:t2                                                                                               
     ns_test:t1                                                                                           
     3 row(s) in 0.0060 seconds
     
     => ["ns2:t1", "ns2:t2", "ns_test:t1"]
    

    删除表(只有disable后的表才能被删除)

     hbase(main):096:0> drop 'ns_test:t1'
     0 row(s) in 1.2760 seconds
    
  • 表数据操作:
    添加数据

     hbase(main):101:0> put 'ns_test:t1', '0001', 'f1:name', 'bob'
     0 row(s) in 0.1650 seconds
    

    全表扫描

     hbase(main):105:0> scan 'ns_test:t1'
     ROW                        COLUMN+CELL                                                               
      0001                      column=f1:age, timestamp=1532252491211, value=30                          
      0001                      column=f1:name, timestamp=1532252499881, value=bob                        
     1 row(s) in 0.0460 seconds
    

    获取某一行数据

     # 获取一行的所有数据
     hbase(main):001:0> get 'ns_test:t1', '0001'
     COLUMN                     CELL                                                                      
      f1:age                    timestamp=1532252491211, value=30                                         
      f1:name                   timestamp=1532252499881, value=bob                                        
     2 row(s) in 0.3190 seconds
    

    获取一行某个列限定符的数据

     hbase(main):014:0* get 'ns_test:t1', '0001', 'f1:age'
     COLUMN                     CELL                                                                      
      f1:age                    timestamp=1532252491211, value=30                                         
     1 row(s) in 0.0140 seconds
    

    删除一行数据

     hbase(main):003:0> deleteall  'ns_test:t1', '0001'
     0 row(s) in 0.3380 seconds
    

    删除一个cell的数据

     hbase(main):002:0> delete 'ns_test:t1', '0001', 'f1:age'
     0 row(s) in 0.2380 seconds
    

    获取表的行数

     hbase(main):006:0> count 'ns_test:t1'
     1 row(s) in 0.0590 seconds
     
     => 1
    

    清空表数据

     hbase(main):013:0* truncate 'ns_test:t1'
     Truncating 'ns_test:t1' table (it may take a while):
      - Disabling table...
      - Truncating table...
     0 row(s) in 3.8720 seconds
     
     hbase(main):026:0> scan 'ns_test:t1'
     ROW                        COLUMN+CELL                                                               
     0 row(s) in 0.1380 seconds
    

总结

该文总结了Hbase启停脚本与常见shell命令的使用。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值