扫二维码与项目经理沟通
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流
小编给大家分享一下HBase shell如何操作,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!
成都一家集口碑和实力的网站建设服务商,拥有专业的企业建站团队和靠谱的建站技术,十年企业及个人网站建设经验 ,为成都上千多家客户提供网页设计制作,网站开发,企业网站制作建设等服务,包括成都营销型网站建设,高端网站设计,同时也为不同行业的客户提供网站设计、做网站的服务,包括成都电商型网站制作建设,装修行业网站制作建设,传统机械行业网站建设,传统农业行业网站制作建设。在成都做网站,选网站制作建设服务商就选创新互联公司。
进入hbase Shell
[root@test31 ~]# hbase shell
HBase Shell; enter 'help' for list of supported commands.
Type "exit" to leave the HBase Shell
Version 0.92.1, r1298924, Fri Mar 9 16:58:34 UTC 2012
1.查看服务器状态
hbase(main):001:0> status
1 servers, 0 dead, 3.0000 average load
2.查看HBase版本
hbase(main):002:0> version
0.92.1, r1298924, Fri Mar 9 16:58:34 UTC 2012
3.DDL操作
1).create命令
创建一个具有三个列族"member_id"和"address"即"info"的表"member",其中表名、行和列都要用单引号括起来,并以逗号隔开。
hbase(main):003:0> create 'member','member_id','address','info'
0 row(s) in 1.1770 seconds
2).list命令
查看当前HBase中具有哪些表
hbase(main):004:0> list
TABLE
member
test
2 row(s) in 0.0170 seconds
3).describe 命令
查看表的描述信息
hbase(main):006:0> describe 'member'
DESCRIPTION ENABLED
{NAME => 'member', FAMILIES => [{NAME => 'address', BLOOMFILTER => 'NONE', REPLICATION_SCO true
PE => '0', VERSIONS => '3', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => '2147483647
', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'}, {NAME => 'info', BLO
OMFILTER => 'NONE', REPLICATION_SCOPE => '0', VERSIONS => '3', COMPRESSION => 'NONE', MIN_
VERSIONS => '0', TTL => '2147483647', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCAC
HE => 'true'}, {NAME => 'member_id', BLOOMFILTER => 'NONE', REPLICATION_SCOPE => '0', VERS
IONS => '3', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => '2147483647', BLOCKSIZE =>
'65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'}]}
1 row(s) in 0.0320 seconds
4).删除一个列族:disable,alter,enable
修改表结构必须先disable
hbase(main):004:0> disable member
NameError: undefined local variable or method `member' for #
hbase(main):005:0> disable 'member'
0 row(s) in 2.1560 seconds
删除member表的info列
hbase(main):006:0> alter 'member', 'delete' => 'info'
Updating all regions with the new schema...
1/1 regions updated.
Done.
0 row(s) in 1.3370 seconds
记得enable表:
hbase(main):009:0> enable 'member'
0 row(s) in 2.2330 seconds
5).删除一个表test(disable,drop)
hbase(main):025:0> disable 'test'
0 row(s) in 2.2100 seconds
hbase(main):026:0> drop 'test'
0 row(s) in 1.2350 seconds
6).查询表是否存在
hbase(main):033:0> exists 'test'
Table test does not exist
0 row(s) in 0.1820 seconds
7).查看表是否enable
hbase(main):032:0> is_enabled 'member'
true
0 row(s) in 0.0070 seconds
4.DML操作
1).插入数据
hbase(main):005:0> put 'member','scutshuxue','info:age','24'
0 row(s) in 0.0790 seconds
hbase(main):005:0> put 'member','duansf','info:age','37'
0 row(s) in 0.0790 seconds
hbase(main):001:0> put 'member','scutshuxue','info:company','alibaba'
0 row(s) in 0.6520 seconds
hbase(main):002:0> put 'member','xiaofeng','address:contry','china'
0 row(s) in 0.0090 seconds
hbase(main):007:0> put 'member','xiaofeng','info:birthday','1987-4-17'
0 row(s) in 0.0120 seconds
注:插入语句后面一定不要有空格。
2).获取一条数据
hbase(main):012:0* get 'member','xiaofeng'
COLUMN CELL
address:contry timestamp=1488307463293, value=china
info:birthday timestamp=1488307533852, value=1987-4-17
2 row(s) in 0.0130 seconds
3).获取一条记录中某个列族的信息
hbase(main):013:0> get 'member','xiaofeng','info'
COLUMN CELL
info:birthday timestamp=1488307533852, value=1987-4-17
1 row(s) in 0.0100 seconds
4).获取一条记录的某个列族中的某个列的信息
hbase(main):020:0> get 'member','xiaofeng','info:birthday'
COLUMN CELL
info:birthday timestamp=1488307533852, value=1987-4-17
1 row(s) in 0.0090 seconds
5).更新一条记录
把duansf的年龄改为38岁
hbase(main):022:0* get 'member','duansf','info:age'
COLUMN CELL
info:age timestamp=1488308172957, value=37
1 row(s) in 0.0090 seconds
put 'member','duansf','info:age','38'
6).删除member表中某个列
hbase(main):032:0* delete 'member','scutshuxue','info:age'
0 row(s) in 0.0080 seconds
7).member表全表扫描(类似于关系型数据库select *)
hbase(main):002:0> scan 'member'
ROW COLUMN+CELL
scutshuxue column=info:age, timestamp=1488306890710, value=24
scutshuxue column=info:company, timestamp=1488307003752, value=alibaba
xiaofeng column=address:contry, timestamp=1488307463293, value=china
xiaofeng column=info:birthday, timestamp=1488307533852, value=1987-4-17
2 row(s) in 0.9780 seconds
8).删除整行
hbase(main):036:0> deleteall 'member','scutshuxue'
0 row(s) in 0.0090 seconds
9).查询member表中有多少行
hbase(main):041:0> count 'member'
2 row(s) in 0.0240 seconds
10).清空整张表
hbase(main):045:0* truncate 'member'
Truncating 'member' table (it may take a while):
- Disabling table...
- Dropping table...
- Creating table...
0 row(s) in 4.8640 seconds
附图:
HBase Shell命令解释
以上是“HBase shell如何操作”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注创新互联行业资讯频道!
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流