温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

HBase Shell命令怎么用

发布时间:2022-01-21 11:39:42 来源:亿速云 阅读:135 作者:小新 栏目:开发技术

小编给大家分享一下HBase Shell命令怎么用,相信大部分人都还不怎么了解,因此分享这篇文章给大家参考一下,希望大家阅读完这篇文章后大有收获,下面让我们一起去了解一下吧!

HBase Shell

第一部分:Hbase基础查看


1. Hbase版本查看

hbase(main):008:0> version
2.2.3, r6a830d87542b766bd3dc4cfdee28655f62de3974, 2020年 01月 10日 星期五 18:27:51 CST
Took 0.0002 seconds

2. Hbase状态查看命令shell

hbase(main):009:0> status1 active master, 0 backup masters, 1 servers, 0 dead, 3.0000 average load
Took 0.0387 seconds
第二部分:DDL(Data Defination Language)操作,Hbase的表table的增删改查


1. 新建表test 设置两个列族为cf1,cf2

hbase(main):010:0> create 'test','cf1','cf2'Created table testTook 1.3418 seconds                                                             
=> Hbase::Table - test

2. 获取表的描述

hbase(main):011:0> describe 'test'Table test is ENABLED                                                           
test                                                                            COLUMN FAMILIES DESCRIPTION                                                     
{NAME => 'cf1', VERSIONS => '1', EVICT_BLOCKS_ON_CLOSE => 'false', NEW_VERSION_B
EHAVIOR => 'false', KEEP_DELETED_CELLS => 'FALSE', CACHE_DATA_ON_WRITE => 'false
', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', MIN_VERSIONS => '0', REPLICA
TION_SCOPE => '0', BLOOMFILTER => 'ROW', CACHE_INDEX_ON_WRITE => 'false', IN_MEM
ORY => 'false', CACHE_BLOOMS_ON_WRITE => 'false', PREFETCH_BLOCKS_ON_OPEN => 'fa
lse', COMPRESSION => 'NONE', BLOCKCACHE => 'true', BLOCKSIZE => '65536'}         {NAME => 'cf2', VERSIONS => '1', EVICT_BLOCKS_ON_CLOSE => 'false', NEW_VERSION_B
EHAVIOR => 'false', KEEP_DELETED_CELLS => 'FALSE', CACHE_DATA_ON_WRITE => 'false
', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', MIN_VERSIONS => '0', REPLICA
TION_SCOPE => '0', BLOOMFILTER => 'ROW', CACHE_INDEX_ON_WRITE => 'false', IN_MEM
ORY => 'false', CACHE_BLOOMS_ON_WRITE => 'false', PREFETCH_BLOCKS_ON_OPEN => 'fa
lse', COMPRESSION => 'NONE', BLOCKCACHE => 'true', BLOCKSIZE => '65536'}         2 row(s) 
QUOTAS                                                                          
0 row(s)Took 16.3063 seconds

3. 删除一个列族cf2

hbase(main):012:0> alter 'test', {NAME=>'cf2',METHOD=>'delete'}Updating all regions with the new schema...1/1 regions updated.
Done.
Took 2.0665 seconds

4. 列出所有Hbase里的表

hbase(main):013:0> list
TABLE                                                                           
table                                                                           
test                                                                            2 row(s)Took 0.0044 seconds                                                             
=> ["table", "test"]

5. 查询表是否存在

hbase(main):014:0> exists 'test'Table test does exist                                                           
Took 0.0224 seconds                                                             
=> true

6. 查询表是否可用

hbase(main):015:0> is_enabled 'test'true                                                                            Took 0.0053 seconds                                                             
=> true

7. 删除一个表

hbase(main):017:0> disable 'test'Took 0.4657 seconds                                                             
hbase(main):018:0> drop 'test'Took 0.2485 seconds
第三部分:HBase的DML(Data Manipulation Language,数据操作语言)操作表的数据进行添加、修改、获取、删除和查询。


1. 插入数据
给Hbase的test表的row1行 插入两个列。

hbase(main):034:0> put 'test','row1','cf1:name','tom'Took 0.0080 seconds                                                             
hbase(main):035:0> put 'test','row1','cf1:age','18'Took 0.0043 seconds

列族cf1 定义了两个列 name 和 age

2. 读取数据
读取test 表的row1行的所有数据

hbase(main):036:0> get 'test','row1'COLUMN                CELL                                                      
 cf1:age              timestamp=1581128757386, value=18                         
 cf1:name             timestamp=1581128743387, value=tom                        
1 row(s)Took 0.0264 seconds

读取test row1行,列族cf1所有数据

hbase(main):037:0> get 'test','row1','cf1'COLUMN                CELL                                                      
 cf1:age              timestamp=1581128757386, value=18                         
 cf1:name             timestamp=1581128743387, value=tom                        
1 row(s)Took 0.0083 seconds

3. 更新一条记录
Hbase的更新语法和插入新数据语法一样

hbase(main):038:0> put 'test','row1','cf1:age','19'Took 0.0059 seconds

查看更新结果

hbase(main):039:0> get 'test','row1','cf1:age'COLUMN                CELL                                                      
 cf1:age              timestamp=1581130589721, value=19                         1 row(s)Took 0.0133 seconds

4. 通过时间戳读取两个版本的数据

hbase(main):005:0> get 'test','row1',{COLUMN=>'cf1:age',TIMESTAMP=>1581130589721}COLUMN                CELL                                                      
 cf1:age              timestamp=1581130589721, value=19                         1 row(s)Took 0.0082 seconds 
 
hbase(main):008:0> get 'test','row1',{COLUMN=>'cf1:age',TIMESTAMP=>1581128757386}COLUMN                CELL                                                      
 cf1:age              timestamp=1581128757386, value=18                         1 row(s)Took 0.0135 seconds

5. 全表扫描

hbase(main):009:0> scan 'test'ROW                   COLUMN+CELL                                               
 row1                 column=cf1:age, timestamp=1581130589721, value=19         
 row1                 column=cf1:name, timestamp=1581128743387, value=tom       
1 row(s)Took 0.0107 seconds

6.统计表中行数

hbase(main):017:0> count 'test'1 row(s)Took 0.0635 seconds                                                             
=> 1

7. 删除一列

hbase(main):011:0> delete 'test','row1','cf1:age'Took 0.0269 seconds

检查删除的结果,年龄回到了18,把19那条删除了

hbase(main):012:0> get 'test','row1'COLUMN                CELL                                                      
 cf1:age              timestamp=1581128757386, value=18                         
 cf1:name             timestamp=1581128743387, value=tom                        
1 row(s)Took 0.0114 seconds

再次删除

hbase(main):015:0> delete 'test','row1','cf1:age'Took 0.0030 seconds 
 
hbase(main):014:0> get 'test','row1'COLUMN                CELL                                                      
 cf1:name             timestamp=1581128743387, value=tom                        
1 row(s)Took 0.0134 seconds

8. 删除所有的单元格

hbase(main):020:0> deleteall 'test','row1'Took 0.0041 seconds

9. 清空表所有数据

hbase(main):022:0> truncate 'test'Truncating 'test' table (it may take a while):
Disabling table...
Truncating table...
Took 1.5547 seconds

以上是“HBase Shell命令怎么用”这篇文章的所有内容,感谢各位的阅读!相信大家都有了一定的了解,希望分享的内容对大家有所帮助,如果还想学习更多知识,欢迎关注亿速云行业资讯频道!

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI