美文网首页Hadoop系我爱编程
HBASE操作(1)-HBASE Shell

HBASE操作(1)-HBASE Shell

作者: 逸飞u | 来源:发表于2016-06-02 14:47 被阅读96次
    • 启动命令
      ./hbase shell

    • 退出命令
      exit

    • 创建表
      create '表名称', '列族名称1','列族名称2','列族名称N'
      create 'users','user_id','address','info'

    • 列出全部表
      list

    • 得到表的描述
      describe 'users'

    • 删除表
      disable 'users' drop 'users'

    • 添加记录
      put ‘表名称’, ‘行键', '列名称:', '值'

    put 'users','xiaoming','info:age','24'
    put 'users','xiaoming','info:birthday','1987-06-17'
    put 'users','xiaoming','info:company','alibaba'
    put 'users','xiaoming','address:contry','china'
    put 'users','xiaoming','address:province','zhejiang'
    put 'users','xiaoming','address:city','hangzhou'
    put 'users','zhangyifei','info:birthday','1987-4-17'
    put 'users','zhangyifei','info:favorite','movie'
    put 'users','zhangyifei','info:company','alibaba'
    put 'users','zhangyifei','address:contry','china'
    put 'users','zhangyifei','address:province','guangdong'
    put 'users','zhangyifei','address:city','jieyang'
    put 'users','zhangyifei','address:town','xianqiao'
    
    • 获取一条记录
      get '表名称', '行键'

    • 取得一个id的所有数据
      get 'users','xiaoming'

    • 获取一个id,一个列族的所有数据
      get 'users','xiaoming','info'

    • 获取一个id,一个列族中一个列的所有数据
      get 'users','xiaoming','info:age'

    • 更新记录(重新写一遍覆盖)

    put 'users','xiaoming','info:age' ,'29'
    get 'users','xiaoming','info:age'
    put 'users','xiaoming','info:age' ,'30'
    get 'users','xiaoming','info:age'
    
    • 获取单元格数据的版本数据
    get 'users','xiaoming',{COLUMN=>'info:age',VERSIONS=>1}
    get 'users','xiaoming',{COLUMN=>'info:age',VERSIONS=>2}
    get 'users','xiaoming',{COLUMN=>'info:age',VERSIONS=>3}
    
    • 获取单元格数据的某个版本数据

    get 'users','xiaoming',{COLUMN=>'info:age',TIMESTAMP=>1364874937056}

    • 全表扫描
      scan 'users'

    • 查看某个表某个列中所有数据
      scan "表名称" , {COLUMNS=>'列族名称:列名称'}

    • 删除xiaoming值的'info:age'字段
      delete '表名' ,'行键' , '列名称'
      delete 'users','xiaoming','info:age' get 'users','xiaoming'

    • 删除整行
      deleteall 'users','xiaoming'

    • 统计表的行数
      count '表名称'
      count 'users'

    • 清空表
      truncate 'users'

    相关文章

      网友评论

      • sys:这么好的总结怎么能没有赞。

      本文标题:HBASE操作(1)-HBASE Shell

      本文链接:https://www.haomeiwen.com/subject/wulkdttx.html