当前位置:   article > 正文

学习总结十九:Hbase数据库shell操作_hbase数据库操作小结

hbase数据库操作小结

     要想在shell中操作Hbase,首先要进入Hbase的shell操作环境,前提条件要保证hadoop和hbase已经启动,进入hbase的shell环境,

执行命令: hbase shell

常用操作命令:

1.创建表 create '表名称', '列族名称1','列族名称2','列族名称N'

举例:创建一个表名students,有三个列族students_id,address和info的表

create 'students','students_id','address','info'

2.添加记录  put '表名称', '行名称', '列名称:', '值'

注意:行名称又叫行键

举例:往表students中插入数据

put 'students','xiaoming','info:age','24'
put 'students','xiaoming','info:birthday','1987-06-17'
put 'students','xiaoming','info:company','alibaba'
put 'students','xiaoming','address:contry','china'
put 'students','xiaoming','address:province','zhejiang'
put 'students','xiaoming','address:city','hangzhou'
put 'students','zhangsan','info:birthday','1987-4-17'
put 'students','zhangsan','info:favorite','movie'
put 'students','zhangsan','info:company','alibaba'
put 'students','zhangsan','address:contry','china'
put 'students','zhangsan','address:province','guangdong'
put 'students','zhangsan','address:city','jieyang'
put 'students','zhangsan','address:town','xianqiao'

3.查看记录 get '表名称', '行名称'

3.1 取得一个id的所有数据
get 'students','xiaoming'
3.2获取一个id,一个列族的所有数据
get 'students','xiaoming','info'
3.3获取一个id,一个列族中一个列的所有数据
get 'students','xiaoming','info:age'

4.查看表中的记录总数count  '表名称'

count  'students'

5.删除记录 delete  '表名' ,'行名称' , '列名称'

delete 'students','xiaoming','info:age'
验证:get 'students','xiaoming'

删除整行 deleteall 'students','xiaoming'

6.查看所有记录 scan "表名称"  

scan 'students'

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

scan 'students',{COLUMN=>'info:age'}

8.更新记录 就是重写一遍进行覆盖

put 'students','xiaoming','info:age' ,'29'
get 'students','xiaoming','info:age'
put 'students','xiaoming','info:age' ,'30'
get 'students','xiaoming','info:age'

9.获取单元格数据的版本数据
get 'students','xiaoming',{COLUMN=>'info:age',VERSIONS=>1}
get 'students','xiaoming',{COLUMN=>'info:age',VERSIONS=>2}
get 'students','xiaoming',{COLUMN=>'info:age',VERSIONS=>3}
10.获取单元格数据的某个版本数据
get 'students','xiaoming',{COLUMN=>'info:age',TIMESTAMP=>1364874937056}

11.列出全部表
list 

12.得到表的描述

describe 'students'

13.清空表
truncate 'students'

14.删除一张表 先要屏蔽该表,才能对该表进行删除,第一步 disable '表名称' 第二步  drop '表名称'

disable 'students'
drop 'students'

15.退出hbase shell环境

quit

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/IT小白/article/detail/502454
推荐阅读
相关标签
  

闽ICP备14008679号