当前位置 博文首页 > 后端码匠:HBase Shell 基本操作

    后端码匠:HBase Shell 基本操作

    作者:[db:作者] 时间:2021-07-16 09:47

    HBase Shell 操作

    基本操作

    • 进入 HBase 客户端命令行
    bin/hbase shell
    
    • 查看帮助命令
    help
    
    • 查看当前数据库中有哪些表
    list
    

    表的操作

    • 创建表
    create 'student','info'
    
    • 插入数据到表
    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'
    
    • 扫描查看表数据
    scan 'student'
    
    scan 'student',{STARTROW => '1001', STOPROW => '1001'}
    
    scan 'student',{STARTROW => '1001'}
    
    • 查看表结构
    describe 'student'
    
    • 更新指定字段的数据
    put 'student','1001','info:name','Nick'
    
    put 'student','1001','info:age','100'
    
    • 查看“指定行”或“指定列族:列”的数据
    get 'student','1001'
    
    get 'student','1001','info:name'
    
    • 统计表数据行数
    count 'student'
    
    • 删除数据

    删除某 rowkey 的全部数据

    deleteall 'student','1001'
    
    

    删除某 rowkey 的某一列数据

    delete 'student','1002','info:sex'
    
    
    • 清空表数据
    truncate 'student'
    

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

    • 删除表

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

    disable 'student'
    

    然后才能 drop 这个表

    drop 'student'
    

    提示:如果直接 drop 表,会报错:ERROR: Table student is enabled. Disable it first.

    • 变更表信息

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

    alter 'student',{NAME=>'info',VERSIONS=>3}
    
    get 'student','1001',{COLUMN=>'info:name',VERSIONS=>3}
    
    cs
    下一篇:没有了