HBase系列2-HBase快速入门

2022-01-17  本文已影响0人  只是甲

一. Hbase安装

本地已经安装CDH 6.3.1版本,已安装Hbase,如下截图:


image.png

此处略过安装。

二. Hbase Shell 操作

2.1 基本操作

  1. 进入Hbase客户端
[root@hp1 ~]# hbase shell
HBase Shell
Use "help" to get list of supported commands.
Use "exit" to quit this interactive shell.
For Reference, please visit: http://hbase.apache.org/2.0/book.html#shell
Version 2.1.0-cdh6.3.1, rUnknown, Thu Sep 26 02:56:37 PDT 2019
Took 0.0010 seconds                                                                                                                                                                                    
Ignoring executable-hooks-1.6.0 because its extensions are not built.  Try: gem pristine executable-hooks --version 1.6.0
Ignoring gem-wrappers-1.4.0 because its extensions are not built.  Try: gem pristine gem-wrappers --version 1.4.0
2.5.1 :001 > 
  1. 查看帮助命令
2.5.1 :001 > help
HBase Shell, version 2.1.0-cdh6.3.1, rUnknown, Thu Sep 26 02:56:37 PDT 2019
Type 'help "COMMAND"', (e.g. 'help "get"' -- the quotes are necessary) for help on a specific command.
Commands are grouped. Type 'help "COMMAND_GROUP"', (e.g. 'help "general"') for help on a command group.

COMMAND GROUPS:
  Group name: general
  Commands: processlist, status, table_help, version, whoami
......
......

2.2 表的操作

  1. 创建表
2.5.1 :004 >   create 'student','info'
Created table student
Took 1.7550 seconds                                                                                                                                                                                    
 => Hbase::Table - student 
2.5.1 :005 > 
  1. 插入数据到表
2.5.1 :006 >   put 'student','1001','info:sex','male'
Took 0.2356 seconds                                                                                                                                                                                    
2.5.1 :007 > put 'student','1001','info:age','18'
Took 0.0093 seconds                                                                                                                                                                                    
2.5.1 :008 > put 'student','1002','info:name','Janna'
Took 0.0126 seconds                                                                                                                                                                                    
2.5.1 :009 > put 'student','1002','info:sex','female'
Took 0.0063 seconds                                                                                                                                                                                    
2.5.1 :010 > put 'student','1002','info:age','20'
Took 0.0074 seconds                                                                                                                                                                                    
2.5.1 :011 > 
  1. 扫描查看表的数据
2.5.1 :015 >   scan 'student'
ROW                                                COLUMN+CELL                                                                                                                                         
 1001                                              column=info:age, timestamp=1640657568508, value=18                                                                                                  
 1001                                              column=info:sex, timestamp=1640657563443, value=male                                                                                                
 1002                                              column=info:age, timestamp=1640657582172, value=20                                                                                                  
 1002                                              column=info:name, timestamp=1640657573111, value=Janna                                                                                              
 1002                                              column=info:sex, timestamp=1640657577458, value=female                                                                                              
2 row(s)
Took 0.0271 seconds                                                                                                                                                                                    
2.5.1 :016 > scan 'student',{STARTROW => '1001', STOPROW => '1001'}
ROW                                                COLUMN+CELL                                                                                                                                         
 1001                                              column=info:age, timestamp=1640657568508, value=18                                                                                                  
 1001                                              column=info:sex, timestamp=1640657563443, value=male                                                                                                
1 row(s)
Took 0.0177 seconds                                                                                                                                                                                    
2.5.1 :017 > scan 'student',{STARTROW => '1001'}
ROW                                                COLUMN+CELL                                                                                                                                         
 1001                                              column=info:age, timestamp=1640657568508, value=18                                                                                                  
 1001                                              column=info:sex, timestamp=1640657563443, value=male                                                                                                
 1002                                              column=info:age, timestamp=1640657582172, value=20                                                                                                  
 1002                                              column=info:name, timestamp=1640657573111, value=Janna                                                                                              
 1002                                              column=info:sex, timestamp=1640657577458, value=female                                                                                              
2 row(s)
Took 0.0104 seconds                                                                                                                                                                                    
2.5.1 :018 > 
  1. 查看表结构
2.5.1 :019 >   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 => 'false', DATA_BLOCK_ENCODING => 'NONE', TTL 
=> 'FOREVER', MIN_VERSIONS => '0', REPLICATION_SCOPE => '0', BLOOMFILTER => 'ROW', CACHE_INDEX_ON_WRITE => 'false', IN_MEMORY => 'false', CACHE_BLOOMS_ON_WRITE => 'false', PREFETCH_BLOCKS_ON_OPEN => 
'false', COMPRESSION => 'NONE', BLOCKCACHE => 'true', BLOCKSIZE => '65536'}                                                                                                                            
1 row(s)
Took 0.0583 seconds                                                                                                                                                                                    
2.5.1 :020 > 
  1. 更新指定字段的数据
2.5.1 :023 >   put 'student','1001','info:name','Nick'
Took 0.0124 seconds                                                                                                                                                                                    
2.5.1 :024 > put 'student','1001','info:age','100'
Took 0.0069 seconds                                                                                                                                                                                    
2.5.1 :025 > 
  1. 查看"指定行"或"指定列族:列"的数据
2.5.1 :025 > get 'student','1001'
COLUMN                                             CELL                                                                                                                                                
 info:age                                          timestamp=1640658019973, value=100                                                                                                                  
 info:name                                         timestamp=1640658015683, value=Nick                                                                                                                 
 info:sex                                          timestamp=1640657563443, value=male                                                                                                                 
1 row(s)
Took 0.0438 seconds                                                                                                                                                                                    
2.5.1 :026 > get 'student','1001','info:name'
COLUMN                                             CELL                                                                                                                                                
 info:name                                         timestamp=1640658015683, value=Nick                                                                                                                 
1 row(s)
Took 0.0214 seconds   
  1. 统计表的行数
2.5.1 :036 >   count 'student'
2 row(s)
Took 0.0273 seconds                                                                                                                                                                                    
 => 2 
2.5.1 :037 > 
  1. 删除
    删除某 rowkey的全部数据:
2.5.1 :037 > deleteall 'student','1001'
Took 0.0148 seconds                                                                                                                                                                                    
2.5.1 :038 > deleteall 'student','1002','info:sex'
Took 0.0077 seconds
  1. 清空表数据
2.5.1 :043 >   truncate 'student'
Truncating 'student' table (it may take a while):
Disabling table...
Truncating table...
Took 2.0864 seconds                                                                                                                                                                                    
2.5.1 :044 > 
  1. 删除表
    首先需要先让表为disable状态:
2.5.1 :049 >   disable 'student'
Took 0.4318 seconds                                                                                                                                                                                    
2.5.1 :050 > drop 'student'
Took 0.2503 seconds                                                                                                                                                                                    
2.5.1 :051 > 
  1. 变更表信息
    将info列族中的数据存放3个版本:
2.5.1 :059 >   create 'student','info'
Created table student
Took 0.7353 seconds                                                                                                                                                                                    
 => Hbase::Table - student 
2.5.1 :060 > alter 'student',{NAME=>'info',VERSIONS=>3}
Updating all regions with the new schema...
1/1 regions updated.
Done.
Took 1.9441 seconds                                                                                                                                                                                    
2.5.1 :061 > 
上一篇下一篇

猜你喜欢

热点阅读