HBase | 基本使用

HBase Shell操作

  • 基本操作
    • 进入HBase客户端 bin/hbase shell
    • 查看帮助 help
    • 查看当前数据库中有哪些表 list
  • 表的操作
    • 创建表 create 'student','info' 格式 create '表名','列族'
    • 插入数据到表
    #格式 请求方式 '表名','行名','列族:列','值'
    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}
    
posted @ 2021-08-12 10:13  —清风碎心—  阅读(33)  评论(0编辑  收藏  举报