当前位置:   article > 正文

HBase学习01(HBase入门及HBase Shell简单操作)_hbase(main)怎么弄出来

hbase(main)怎么弄出来

hbase入门

启动关闭

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

./bin/start-hbase.sh 
  • 1

关闭时先关闭hbase

./bin/stop-hbase.sh 
  • 1

再关闭zookeeper和hadoop

查看hbase页面

hadoop102:16010
  • 1

在这里插入图片描述

hbase shell操作

./bin/hbase shell
  • 1

在这里插入图片描述
帮助为help
退出为exit回车

namespace的操作

查看当前hbase中有哪些namespace

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

创建namespace

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

就不复制前面的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
  • 1
  • 2
  • 3
  • 4
  • 5

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

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

删除属性

alter_namespace "test01",{METHOD=>'unset',NAME=>'author'}
  • 1
describe_namespace "test01"
DESCRIPTION                                                                  
{NAME => 'test01', create_time => '2022-06-24 14:07:05'}                     
Took 0.0222 seconds                                                          
=> 1
  • 1
  • 2
  • 3
  • 4
  • 5

删除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   
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

表的操作

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

list
  • 1

创建表

create 'student','info'
  • 1

插入数据到表

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'
  • 1
  • 2
  • 3
  • 4
  • 5

扫描查看表数据

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  
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
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 
  • 1
  • 2
  • 3
  • 4
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 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

查看表结构

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'} 
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11

更新指定字段的数据

put 'student','1001','info:name','Nick'
put 'student','1001','info:age','28'
  • 1
  • 2
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  
  • 1
  • 2
  • 3
  • 4
  • 5

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

get 'student','1001'
COLUMN               CELL                                                    
 info:age            timestamp=1656054338962, value=28                       
 info:name           timestamp=1656054322120, value=Nick                     
 info:sex            timestamp=1656053678992, value=male  
  • 1
  • 2
  • 3
  • 4
  • 5
get 'student','1001','info:name'
COLUMN               CELL                                                    
 info:name           timestamp=1656054322120, value=Nick 
  • 1
  • 2
  • 3

统计表数据行数

count 'student'
2 row(s)
  • 1
  • 2

删除数据

删除某rowkey的全部数据

deleteall 'student','1001'
  • 1

数据已被删除

 get 'student','1001'
COLUMN               CELL  
  • 1
  • 2

删除某rowkey的某一列数据

deleteall 'student','1002','info:sex'
get 'student','1002'
COLUMN               CELL                                                    
 info:age            timestamp=1656053734378, value=20                       
 info:name           timestamp=1656053710343, value=Janna   
  • 1
  • 2
  • 3
  • 4
  • 5

清空表数据

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

truncate 'student'
  • 1

删除表

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

disable 'student'
drop 'student'
  • 1
  • 2

变更表信息

将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)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9

在指定namespace下创建表

create 'test01:student','info'
  • 1

查看namespace下的表

list_namespace_tables 'test01'
TABLE                                                                           
student               
  • 1
  • 2
  • 3

插入一些数据

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'
  • 1
  • 2
  • 3
  • 4
  • 5

获取数据

get 'test01:student','1001'
COLUMN                CELL                                                      
 info:age             timestamp=1656068055139, value=18                         
 info:sex             timestamp=1656068054972, value=male  
  • 1
  • 2
  • 3
  • 4
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/凡人多烦事01/article/detail/725712
推荐阅读
相关标签
  

闽ICP备14008679号