展开
拓展 关闭
订阅号推广码
GitHub
视频
公告栏 关闭

hbase基本使用

  • docker安装hbase
# 下载镜像
docker pull harisekhon/hbase
# 启动
docker run -d --name myhbase -p 2181:2181 -p 8080:8080 -p 8085:8085 -p 9090:9090 -p 9095:9095 -p 16000:16000 -p 16010:16010 -p 16201:16201 -p 16301:16301 harisekhon/hbase:latest
  • 浏览器访问192.168.128.100:16010

  • 使用

# 进入容器
docker exec -it myhbase bash
# 执行如下
cd hbase-2.1.3/bin/
./hbase shell

# 帮助
help

# 查看表
hbase(main):002:0> list
TABLE                                                                           
0 row(s)
Took 0.4214 seconds                                                             
=> []

# 创建表
hbase(main):003:0> create 'student','info'
Created table student
Took 0.8227 seconds                                                             
=> Hbase::Table - student
hbase(main):004:0> list
TABLE                                                                           
student                                                                         
1 row(s)
Took 0.0173 seconds                                                             
=> ["student"]

# 插入数据 
hbase(main):005:0> put 'student','1001','info:sex','male'
Took 0.1585 seconds                                                             
hbase(main):006:0> put 'student','1001','info:age','18'
Took 0.0067 seconds                                                             
hbase(main):007:0> put 'student','1002','info:name','Janna'
Took 0.0084 seconds                                                             
hbase(main):008:0> put 'student','1002','info:sex','female'
Took 0.0055 seconds                                                             
hbase(main):009:0> put 'student','1002','info:age','20'
Took 0.0057 seconds  

# 查看表数据
hbase(main):013:0> scan 'student'
ROW                   COLUMN+CELL                                               
 1001                 column=info:age, timestamp=1705565313647, value=18        
 1001                 column=info:sex, timestamp=1705565307782, value=male      
 1002                 column=info:age, timestamp=1705565328729, value=20        
 1002                 column=info:name, timestamp=1705565321612, value=Janna    
 1002                 column=info:sex, timestamp=1705565325481, value=female    
2 row(s)
Took 0.0271 seconds   
hbase(main):014:0> scan 'student',{STARTROW => '1001', STOPROW  => '1001'}
ROW                   COLUMN+CELL                                               
 1001                 column=info:age, timestamp=1705565313647, value=18        
 1001                 column=info:sex, timestamp=1705565307782, value=male      
1 row(s)
Took 0.0103 seconds                                                             
hbase(main):015:0> scan 'student',{STARTROW => '1001'}
ROW                   COLUMN+CELL                                               
 1001                 column=info:age, timestamp=1705565313647, value=18        
 1001                 column=info:sex, timestamp=1705565307782, value=male      
 1002                 column=info:age, timestamp=1705565328729, value=20        
 1002                 column=info:name, timestamp=1705565321612, value=Janna    
 1002                 column=info:sex, timestamp=1705565325481, value=female    
2 row(s)
Took 0.0091 seconds 

# 查看表结构
hbase(main):016:0> describe 'student'
Table student is ENABLED                                                        
student                                                                         
COLUMN FAMILIES DESCRIPTION                                                     
{NAME => 'info', VERSIONS => '1', EVICT_BLOCKS_ON_CLOSE => 'false', NEW_VERSION_
BEHAVIOR => 'false', KEEP_DELETED_CELLS => 'FALSE', CACHE_DATA_ON_WRITE => 'fals
e', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', MIN_VERSIONS => '0', REPLIC
ATION_SCOPE => '0', BLOOMFILTER => 'ROW', CACHE_INDEX_ON_WRITE => 'false', IN_ME
MORY => 'false', CACHE_BLOOMS_ON_WRITE => 'false', PREFETCH_BLOCKS_ON_OPEN => 'f
alse', COMPRESSION => 'NONE', BLOCKCACHE => 'true', BLOCKSIZE => '65536'}       
1 row(s)
Took 0.0677 seconds  

# 更新数据
hbase(main):017:0> put 'student','1001','info:name','Nick'
Took 0.0061 seconds                                                             
hbase(main):018:0> put 'student','1001','info:age','100'
Took 0.0052 seconds  

# 查看指定行或列
hbase(main):019:0> get 'student','1001'
COLUMN                CELL                                                      
 info:age             timestamp=1705565620452, value=100                        
 info:name            timestamp=1705565615620, value=Nick                       
 info:sex             timestamp=1705565307782, value=male                       
1 row(s)
Took 0.0297 seconds                                                             
hbase(main):020:0> get 'student','1001','info:name'
COLUMN                CELL                                                      
 info:name            timestamp=1705565615620, value=Nick                       
1 row(s)
Took 0.0110 seconds    

# 统计行数                                                         
hbase(main):021:0> count 'student'
2 row(s)
Took 0.0326 seconds                                                             
=> 2

# 变更表信息
hbase(main):022:0> alter 'student',{NAME=>'info',VERSIONS=>3}
Updating all regions with the new schema...
1/1 regions updated.
Done.
Took 1.7603 seconds                                                             
hbase(main):023:0> get 'student','1001',{COLUMN=>'info:name',VERSIONS=>3}
COLUMN                CELL                                                      
 info:name            timestamp=1705565615620, value=Nick                       
1 row(s)
Took 0.0110 seconds  

# 删除1列
hbase(main):024:0> delete 'student','1002','info:sex'
Took 0.0181 seconds               
# 删除全部                                              
hbase(main):025:0> deleteall 'student','1001'
Took 0.0051 seconds           
# 清空表                                                  
hbase(main):026:0> truncate 'student'
Truncating 'student' table (it may take a while):
Disabling table...
Truncating table...
Took 1.2037 seconds   

# 删除表
hbase(main):027:0> disable 'student'
Took 0.4359 seconds                                                             
hbase(main):028:0> drop 'student'
Took 0.2485 seconds 

# 查看命名空间
hbase(main):029:0> list_namespace
NAMESPACE                                                                       
default                                                                         
hbase                                                                           
2 row(s)
Took 0.0258 seconds            

# 创建空间                                                 
hbase(main):030:0> create_namespace 'bigdata'
Took 0.2311 seconds  

# 创建表
hbase(main):031:0> create 'bigdata:student','info'
Created table bigdata:student
Took 0.7287 seconds                                                             
=> Hbase::Table - bigdata:student

# 删除表后,再删除命名空间
hbase(main):035:0> disable 'bigdata:student'
Took 0.4381 seconds                                                             
hbase(main):036:0> drop 'bigdata:student'
Took 0.2321 seconds                                                             
hbase(main):037:0> drop_namespace 'bigdata'
Took 0.2283 seconds  
posted @ 2024-01-18 15:46  DogLeftover  阅读(9)  评论(0编辑  收藏  举报