失眠网,内容丰富有趣,生活中的好帮手!
失眠网 > 1005--HBase操作实战(HBase Shell命令行模式)

1005--HBase操作实战(HBase Shell命令行模式)

时间:2023-12-16 12:50:47

相关推荐

1005--HBase操作实战(HBase Shell命令行模式)

通过HBase 命令行,创建一张表,用户存储用户信息,其中包括基本信息和额外信息

HBase shell 下所有命令可以使用: help “cmd” 进行了解1、创建表

create 't_person', {NAME => 'basic_info'}, {NAME => 'extra_info'}

2、表中存储数据

put 't_person', 'g25001', 'basic_info:username', '丽丽'

put 't_person', 'g25001', 'basic_info:age', 28

put 't_person', 'g25001', 'basic_info:sex', 'nv'

put 't_person', 'g25001', 'extra_info:salary', 50000

put 't_person', 'g25001', 'extra_info:career', 'singer'

put 't_person', 'g25002', 'basic_info:username', '文文'

put 't_person', 'g25002', 'basic_info:age', 27

put 't_person', 'g25002', 'basic_info:sex', 'nan'

put 't_person', 'g25002', 'extra_info:salary', 5000

put 't_person', 'g25002', 'extra_info:career', 'UI设计师'

put 't_person', 'g25003', 'basic_info:username', '福福'

put 't_person', 'g25003', 'basic_info:age', 29

put 't_person', 'g25003', 'basic_info:sex', 'nv'

put 't_person', 'g25003', 'extra_info:salary', 5000

put 't_person', 'g25003', 'extra_info:career', '产品经理'

3、查看表是否创建成功

list: 可以查看所有表的列表

list 't_person' :查看当前表的信息

4、查看标结构

describe 't_person'

得到的结果只会到列族,不会显示出列族下面的列名

5、修改表结构

5.1 修改表的时候需要

禁用表: disable '表名'

启用表: enable '表名'

5.2 添加列族

alter '表名','列族'

5.3 删除表

drop '表名'

drop 't_person'

5.4 删除列族

alert '表名','delete','列族'

alter 't_person','basic_info'

5.5 修改列族的属性

alter '表名',NAME=>'basic_info',列族属性=>列族属性的数值

6、查询数据

6.1 scan查看数据

//查看所有数据

scan 't_person'

//查看所有数据指定列

scan 't_person', {COLUMN => ['basic_info:sex']}

//范围行查询数据: hbase中默认rowkey升序排序,LIMIT 表示最多显示2行,STARTROW表示从该位置开始查询

scan 't_person', {COLUMNS => ['basic_info:username','basic_info:age'], LIMIT => 2, STARTROW => 'g25002'}

6.2 查看某一行数据

get 't_person','g25001'

6.3 查看某一行某一列族数据

get 't_person','g25001,'basic_info'

6.4 查看某一行某一列的数据

get 't_person','g25001,'basic_info:username'

6.5 查看某一行某几列

get 't_person','g25001', {COLUMN => ['basic_info:username','basic_info:age','basic_info:sex']}

6.6 统计行数count('t_person')

6.7 清空表truncate 't_person'

9、修改数据

修改数据的话,是重新插入一条数据将将之前的数据覆盖

put 't_person','g25001','basic_info:username','okok'

10、删除

先禁用表,然后在删除表

禁用表:

disable 't_person'

删除表:

delete 't_person'

参考文章:

淘宝技术部: /?p=457

搜索技术博客://01/understanding-hbase.html

如果觉得《1005--HBase操作实战(HBase Shell命令行模式)》对你有帮助,请点赞、收藏,并留下你的观点哦!

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。