• hbase学习01(hbase入门及hbase shell简单操作)


    hbase入门

    启动关闭

    首先zookeeper和hadoop正常启动
    再启动hbase

    ./bin/start-hbase.sh 
    
    • 1

    关闭时先关闭hbase

    ./bin/stop-hbase.sh 
    
    • 1

    再关闭zookeeper和hadoop

    查看hbase页面

    hadoop102:16010
    
    • 1

    在这里插入图片描述

    hbase shell操作

    ./bin/hbase shell
    
    • 1

    在这里插入图片描述
    帮助为help
    退出为exit回车

    namespace的操作

    查看当前hbase中有哪些namespace

    hbase(main):001:0> list_namespace
    NAMESPACE                                                                    
    default                                                                      
    hbase
    
    • 1
    • 2
    • 3
    • 4
    default(创建表时未指定命名空间的话默认在default)                                                                                                
    hbase(系统使用的,用来存放系统相关的元数据信息等,勿随便操作) 
    
    • 1
    • 2

    创建namespace

    hbase(main):002:0> create_namespace "test"
    create_namespace "test01",{"author"=>"xwk","create_time"=>"2022-06-24 14:07:05"}
    
    • 1
    • 2

    就不复制前面的hbase(main):002:0>了,太麻烦

    查看namespace

    describe_namespace "test01"
    DESCRIPTION                                                                  
    {NAME => 'test01', author => 'xwk', create_time => '2022-06-24 14:07:05'}    
    Took 0.0783 seconds                                                          
    => 1
    
    • 1
    • 2
    • 3
    • 4
    • 5

    修改namespace的信息(添加或者修改属性)

    alter_namespace "test01",{METHOD=>'set','author'=>'xingweikun'}
    
    • 1
    describe_namespace "test01"
    DESCRIPTION                                                                  
    {NAME => 'test01', author => 'xingweikun', create_time => '2022-06-24 14:07:0
    5'}                                                                          
    Took 0.0190 seconds                                                          
    => 1
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    删除属性

    alter_namespace "test01",{METHOD=>'unset',NAME=>'author'}
    
    • 1
    describe_namespace "test01"
    DESCRIPTION                                                                  
    {NAME => 'test01', create_time => '2022-06-24 14:07:05'}                     
    Took 0.0222 seconds                                                          
    => 1
    
    • 1
    • 2
    • 3
    • 4
    • 5

    删除namespace

    要删除的namespace必须是空的,其下没有表。

    hbase(main):020:0> list_namespace
    NAMESPACE                                                                    
    default                                                                      
    hbase                                                                        
    test                                                                         
    test01                                                                       
    4 row(s)
    Took 0.1862 seconds                                                          
    hbase(main):021:0> drop_namespace "test"
    Took 0.7911 seconds                                                          
    hbase(main):022:0> list_namespace
    NAMESPACE                                                                    
    default                                                                      
    hbase                                                                        
    test01                                                                       
    3 row(s)
    Took 0.0456 seconds   
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17

    表的操作

    查看当前数据库中有哪些表

    list
    
    • 1

    创建表

    create 'student','info'
    
    • 1

    插入数据到表

    put 'student','1001','info:sex','male'
    put 'student','1001','info:age','18'
    put 'student','1002','info:name','Janna'
    put 'student','1002','info:sex','female'
    put 'student','1002','info:age','20'
    
    • 1
    • 2
    • 3
    • 4
    • 5

    扫描查看表数据

    scan 'student'
    ROW                  COLUMN+CELL                                             
     1001                column=info:age, timestamp=1656053691789, value=18      
     1001                column=info:sex, timestamp=1656053678992, value=male    
     1002                column=info:age, timestamp=1656053734378, value=20      
     1002                column=info:name, timestamp=1656053710343, value=Janna  
     1002                column=info:sex, timestamp=1656053722697, value=female  
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    scan 'student',{STARTROW=>'1001',STOPROW=>'1001'}
    ROW                  COLUMN+CELL                                             
     1001                column=info:age, timestamp=1656053691789, value=18      
     1001                column=info:sex, timestamp=1656053678992, value=male 
    
    • 1
    • 2
    • 3
    • 4
    scan 'student',{STARTROW=>'1001'}
    ROW                  COLUMN+CELL                                             
     1001                column=info:age, timestamp=1656053691789, value=18      
     1001                column=info:sex, timestamp=1656053678992, value=male    
     1002                column=info:age, timestamp=1656053734378, value=20      
     1002                column=info:name, timestamp=1656053710343, value=Janna  
     1002                column=info:sex, timestamp=1656053722697, value=female 
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    查看表结构

    describe 'student'
    Table student is ENABLED                                                     
    student                                                                      
    COLUMN FAMILIES DESCRIPTION                                                  
    {NAME => 'info', VERSIONS => '1', EVICT_BLOCKS_ON_CLOSE => 'false', NEW_VERSI
    ON_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_BLOCK
    S_ON_OPEN => 'false', COMPRESSION => 'NONE', BLOCKCACHE => 'true', BLOCKSIZE 
    => '65536'} 
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11

    更新指定字段的数据

    put 'student','1001','info:name','Nick'
    put 'student','1001','info:age','28'
    
    • 1
    • 2
    scan 'student',{STARTROW=>'1001',STOPROW=>'1001'}
    ROW                  COLUMN+CELL                                             
     1001                column=info:age, timestamp=1656054338962, value=28      
     1001                column=info:name, timestamp=1656054322120, value=Nick   
     1001                column=info:sex, timestamp=1656053678992, value=male  
    
    • 1
    • 2
    • 3
    • 4
    • 5

    查看“指定行”或“指定列族:列”的数据

    get 'student','1001'
    COLUMN               CELL                                                    
     info:age            timestamp=1656054338962, value=28                       
     info:name           timestamp=1656054322120, value=Nick                     
     info:sex            timestamp=1656053678992, value=male  
    
    • 1
    • 2
    • 3
    • 4
    • 5
    get 'student','1001','info:name'
    COLUMN               CELL                                                    
     info:name           timestamp=1656054322120, value=Nick 
    
    • 1
    • 2
    • 3

    统计表数据行数

    count 'student'
    2 row(s)
    
    • 1
    • 2

    删除数据

    删除某rowkey的全部数据

    deleteall 'student','1001'
    
    • 1

    数据已被删除

     get 'student','1001'
    COLUMN               CELL  
    
    • 1
    • 2

    删除某rowkey的某一列数据

    deleteall 'student','1002','info:sex'
    get 'student','1002'
    COLUMN               CELL                                                    
     info:age            timestamp=1656053734378, value=20                       
     info:name           timestamp=1656053710343, value=Janna   
    
    • 1
    • 2
    • 3
    • 4
    • 5

    清空表数据

    清空表的操作顺序为先disable,然后再truncate。

    truncate 'student'
    
    • 1

    删除表

    首先需要先让该表为disable状态:

    disable 'student'
    drop 'student'
    
    • 1
    • 2

    变更表信息

    将info列族中的数据存放3个版本

    alter 'student',{NAME=>'info',VERSIONS=>3}
    Updating all regions with the new schema...
    1/1 regions updated.
    Done.
    
    get 'student','1001',{COLUMN=>'info:name',VERSIONS=>3}
    COLUMN               CELL                                                    
     info:name           timestamp=1656055107222, value=Nick                     
    1 row(s)
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    在指定namespace下创建表

    create 'test01:student','info'
    
    • 1

    查看namespace下的表

    list_namespace_tables 'test01'
    TABLE                                                                           
    student               
    
    • 1
    • 2
    • 3

    插入一些数据

    put 'test01:student','1001','info:sex','male'
    put 'test01:student','1001','info:age','18'
    put 'test01:student','1002','info:name','Janna'
    put 'test01:student','1002','info:sex','female'
    put 'test01:student','1002','info:age','20'
    
    • 1
    • 2
    • 3
    • 4
    • 5

    获取数据

    get 'test01:student','1001'
    COLUMN                CELL                                                      
     info:age             timestamp=1656068055139, value=18                         
     info:sex             timestamp=1656068054972, value=male  
    
    • 1
    • 2
    • 3
    • 4
  • 相关阅读:
    数据库读写分离和分库分表
    python面向对象1--类、对象、属性、魔法方法
    Cmake升级与软链接
    (Java岗面试)耗时1月最新整理了20个技术栈的大厂面试题+解析+面经!
    onnx删除无用属性
    JAVA毕业设计酒店员工管理系统计算机源码+lw文档+系统+调试部署+数据库
    LIF-MDF6000-6KMG80I FPGA现场可编程门阵列 封装BGA
    C#实现线性查找算法
    文心一言 VS 讯飞星火 VS chatgpt (106)-- 算法导论10.1 4题
    软件工程与计算总结(六)需求分析方法
  • 原文地址:https://blog.csdn.net/weixin_46322367/article/details/125443782