HBase学习01(HBase入门及HBase Shell简单操作)

Posted 数据攻城小狮子

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了HBase学习01(HBase入门及HBase Shell简单操作)相关的知识,希望对你有一定的参考价值。

文章目录

hbase入门

启动关闭

首先zookeeper和hadoop正常启动
再启动hbase

./bin/start-hbase.sh 

关闭时先关闭hbase

./bin/stop-hbase.sh 

再关闭zookeeper和hadoop

查看hbase页面

hadoop102:16010

hbase shell操作

./bin/hbase shell


帮助为help
退出为exit回车

namespace的操作

查看当前hbase中有哪些namespace

hbase(main):001:0> list_namespace
NAMESPACE                                                                    
default                                                                      
hbase
default(创建表时未指定命名空间的话默认在default)                                                                                                
hbase(系统使用的,用来存放系统相关的元数据信息等,勿随便操作) 

创建namespace

hbase(main):002:0> create_namespace "test"
create_namespace "test01","author"=>"xwk","create_time"=>"2022-06-24 14:07:05"

就不复制前面的hbase(main):002:0>了,太麻烦

查看namespace

describe_namespace "test01"
DESCRIPTION                                                                  
NAME => 'test01', author => 'xwk', create_time => '2022-06-24 14:07:05'    
Took 0.0783 seconds                                                          
=> 1

修改namespace的信息(添加或者修改属性)

alter_namespace "test01",METHOD=>'set','author'=>'xingweikun'
describe_namespace "test01"
DESCRIPTION                                                                  
NAME => 'test01', author => 'xingweikun', create_time => '2022-06-24 14:07:0
5'                                                                          
Took 0.0190 seconds                                                          
=> 1

删除属性

alter_namespace "test01",METHOD=>'unset',NAME=>'author'
describe_namespace "test01"
DESCRIPTION                                                                  
NAME => 'test01', create_time => '2022-06-24 14:07:05'                     
Took 0.0222 seconds                                                          
=> 1

删除namespace

要删除的namespace必须是空的,其下没有表。

hbase(main):020:0> list_namespace
NAMESPACE                                                                    
default                                                                      
hbase                                                                        
test                                                                         
test01                                                                       
4 row(s)
Took 0.1862 seconds                                                          
hbase(main):021:0> drop_namespace "test"
Took 0.7911 seconds                                                          
hbase(main):022:0> list_namespace
NAMESPACE                                                                    
default                                                                      
hbase                                                                        
test01                                                                       
3 row(s)
Took 0.0456 seconds   

表的操作

查看当前数据库中有哪些表

list

创建表

create 'student','info'

插入数据到表

put 'student','1001','info:sex','male'
put 'student','1001','info:age','18'
put 'student','1002','info:name','Janna'
put 'student','1002','info:sex','female'
put 'student','1002','info:age','20'

扫描查看表数据

scan 'student'
ROW                  COLUMN+CELL                                             
 1001                column=info:age, timestamp=1656053691789, value=18      
 1001                column=info:sex, timestamp=1656053678992, value=male    
 1002                column=info:age, timestamp=1656053734378, value=20      
 1002                column=info:name, timestamp=1656053710343, value=Janna  
 1002                column=info:sex, timestamp=1656053722697, value=female  
scan 'student',STARTROW=>'1001',STOPROW=>'1001'
ROW                  COLUMN+CELL                                             
 1001                column=info:age, timestamp=1656053691789, value=18      
 1001                column=info:sex, timestamp=1656053678992, value=male 
scan 'student',STARTROW=>'1001'
ROW                  COLUMN+CELL                                             
 1001                column=info:age, timestamp=1656053691789, value=18      
 1001                column=info:sex, timestamp=1656053678992, value=male    
 1002                column=info:age, timestamp=1656053734378, value=20      
 1002                column=info:name, timestamp=1656053710343, value=Janna  
 1002                column=info:sex, timestamp=1656053722697, value=female 

查看表结构

describe 'student'
Table student is ENABLED                                                     
student                                                                      
COLUMN FAMILIES DESCRIPTION                                                  
NAME => 'info', VERSIONS => '1', EVICT_BLOCKS_ON_CLOSE => 'false', NEW_VERSI
ON_BEHAVIOR => 'false', KEEP_DELETED_CELLS => 'FALSE', CACHE_DATA_ON_WRITE =>
 'false', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', MIN_VERSIONS => '0
', REPLICATION_SCOPE => '0', BLOOMFILTER => 'ROW', CACHE_INDEX_ON_WRITE => 'f
alse', IN_MEMORY => 'false', CACHE_BLOOMS_ON_WRITE => 'false', PREFETCH_BLOCK
S_ON_OPEN => 'false', COMPRESSION => 'NONE', BLOCKCACHE => 'true', BLOCKSIZE 
=> '65536' 

更新指定字段的数据

put 'student','1001','info:name','Nick'
put 'student','1001','info:age','28'
scan 'student',STARTROW=>'1001',STOPROW=>'1001'
ROW                  COLUMN+CELL                                             
 1001                column=info:age, timestamp=1656054338962, value=28      
 1001                column=info:name, timestamp=1656054322120, value=Nick   
 1001                column=info:sex, timestamp=1656053678992, value=male  

查看“指定行”或“指定列族:列”的数据

get 'student','1001'
COLUMN               CELL                                                    
 info:age            timestamp=1656054338962, value=28                       
 info:name           timestamp=1656054322120, value=Nick                     
 info:sex            timestamp=1656053678992, value=male  
get 'student','1001','info:name'
COLUMN               CELL                                                    
 info:name           timestamp=1656054322120, value=Nick 

统计表数据行数

count 'student'
2 row(s)

删除数据

删除某rowkey的全部数据

deleteall 'student','1001'

数据已被删除

 get 'student','1001'
COLUMN               CELL  

删除某rowkey的某一列数据

deleteall 'student','1002','info:sex'
get 'student','1002'
COLUMN               CELL                                                    
 info:age            timestamp=1656053734378, value=20                       
 info:name           timestamp=1656053710343, value=Janna   

清空表数据

清空表的操作顺序为先disable,然后再truncate。

truncate 'student'

删除表

首先需要先让该表为disable状态:

disable 'student'
drop 'student'

变更表信息

将info列族中的数据存放3个版本

alter 'student',NAME=>'info',VERSIONS=>3
Updating all regions with the new schema...
1/1 regions updated.
Done.

get 'student','1001',COLUMN=>'info:name',VERSIONS=>3
COLUMN               CELL                                                    
 info:name           timestamp=1656055107222, value=Nick                     
1 row(s)

在指定namespace下创建表

create 'test01:student','info'

查看namespace下的表

list_namespace_tables 'test01'
TABLE                                                                           
student               

插入一些数据

put 'test01:student','1001','info:sex','male'
put 'test01:student','1001','info:age','18'
put 'test01:student','1002','info:name','Janna'
put 'test01:student','1002','info:sex','female'
put 'test01:student','1002','info:age','20'

获取数据

get 'test01:student','1001'
COLUMN                CELL                                                      
 info:age             timestamp=1656068055139, value=18                         
 info:sex             timestamp=1656068054972, value=male  

以上是关于HBase学习01(HBase入门及HBase Shell简单操作)的主要内容,如果未能解决你的问题,请参考以下文章

HBase学习01(HBase入门及HBase Shell简单操作)

技术分享专题Hbase入门心得篇

Hbase学习01

Hbase从入门到精通_如何学好Hbase

大数据-04-Hbase入门

HBase 原理