hbase 创建一直到删除过程学习笔记

创建王者荣耀表的需求:

1.进入Shell

[root@hadoop01 ~]# hbase shell
HBase Shell; enter 'help<RETURN>' for list of supported commands.
Type "exit<RETURN>" to leave the HBase Shell
Version 1.3.1, r930b9a55528fe45d8edce7af42fef2d35e77677a, Thu Apr  6 19:36:54 PDT 2017

2.查看有哪些表

hbase(main):001:0> list
TABLE                                                                                                                                                                      
scores                                                                                                                                                                     
1 row(s) in 1.0400 seconds

=> ["scores"]

3.创建gamer表

hbase(main):002:0> create 'TencentGames','grade','attribute'
0 row(s) in 6.7000 seconds

=> Hbase::Table - TencentGames

4.插入表数据

hbase(main):003:0> put 'TencentGames','shangguan','grade','1'
0 row(s) in 0.3330 seconds

hbase(main):004:0> put 'TencentGames','shangguan','attribute:Master','master'
0 row(s) in 0.4780 seconds

hbase(main):003:0> put 'TencentGames','daji','grade','2'
0 row(s) in 0.2350 seconds

hbase(main):004:0> put 'TencentGames','daji','attribute:Master','master'
0 row(s) in 0.0250 seconds

5.查询数据
a)查询某行记录
或者:获取一个rowkey,一个列族中一个列的所有数据

hbase(main):009:0> get 'TencentGames','daji','attribute:Master'
COLUMN                                      CELL                                                                                                                           
 attribute:Master                           timestamp=1587376586228, value=master                                                                                          
1 row(s) in 0.0320 seconds

或者:获取一个rowkey,一个列族的所有数据

hbase(main):008:0> get 'TencentGames','daji','grade'
COLUMN                                      CELL                                                                                                                           
 grade:                                     timestamp=1587376552594, value=2                                                                                               
1 row(s) in 0.0330 seconds

或者:获取一个rowkey的所有数据

hbase(main):007:0> get 'TencentGames','daji'
COLUMN                                      CELL                                                                                                                           
 attribute:Master                           timestamp=1587376586228, value=master                                                                                          
 grade:                                     timestamp=1587376552594, value=2                                                                                               
1 row(s) in 0.0780 seconds

b)扫描表

hbase(main):005:0> scan 'TencentGames'
ROW                                         COLUMN+CELL                                                                                                                    
 daji                                       column=attribute:Master, timestamp=1587376586228, value=master                                                                 
 daji                                       column=grade:, timestamp=1587376552594, value=2                                                                                
 shangguan                                  column=attribute:Master, timestamp=1587376421031, value=master                                                                 
 shangguan                                  column=grade:, timestamp=1587376287043, value=1                                                                                
2 row(s) in 0.1230 seconds

c)查询表中的数据行数

hbase(main):006:0> count 'TencentGames'
2 row(s) in 0.0880 seconds

=> 2

6.修改数据
#修改一个rowkey下某个列的值

hbase(main):001:0> put 'TencentGames','daji','grade','3'
0 row(s) in 0.3720 seconds

hbase(main):002:0> scan 'TencentGames'
ROW                                         COLUMN+CELL                                                                                                                    
 daji                                       column=attribute:Master, timestamp=1587376586228, value=master                                                                 
 daji                                       column=grade:, timestamp=1587377498026, value=3                                                                                
 shangguan                                  column=attribute:Master, timestamp=1587376421031, value=master                                                                 
 shangguan                                  column=grade:, timestamp=1587376287043, value=1                                                                                
2 row(s) in 0.0330 seconds

#通过timestamp来获取两个版本的数据

hbase(main):004:0> get 'TencentGames','daji',{COLUMN=>'attribute:Master',TIMESTAMP=>1587376586228}
COLUMN                                      CELL                                                                                                                           
 attribute:Master                           timestamp=1587376586228, value=master                                                                                          
1 row(s) in 0.0170 seconds

7.删除数据
a)删除行中的某个列值

hbase(main):023:0> delete 'TencentGames','daji','attribute:Master'
0 row(s) in 0.1830 seconds

b )删除行

hbase(main):028:0> delete 'TencentGames','daji','grade'
0 row(s) in 0.0070 seconds

c)删除表中的所有数据

truncate 'TencentGames'

8.查看表结构

hbase(main):005:0> desc 'TencentGames'
Table TencentGames is ENABLED                                                                                                                                              
TencentGames                                                                                                                                                               
COLUMN FAMILIES DESCRIPTION                                                                                                                                                
{NAME => 'attribute', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESS
ION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}                                                                  
{NAME => 'grade', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION 
=> 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}                                                                      
2 row(s) in 0.8310 seconds

9.is_enabled和is_disabled来检查表是否被禁用。

hbase(main):006:0> is_enabled 'TencentGames'
true                                                                                                                                                                       
0 row(s) in 0.1080 seconds

hbase(main):008:0> is_disabled 'TencentGames'
false                                                                                                                                                                      
0 row(s) in 0.0180 seconds

hbase(main):009:0> 

10.删除’lol’表的’assetsInfo’列簇

hbase(main):028:0> delete 'TencentGames','daji','grade'
0 row(s) in 0.0070 seconds

11.删除表
#如果直接删除会报错误:
#所以要先将表进行Disable 操作

hbase(main):029:0> disable 'TencentGames'
0 row(s) in 4.3610 seconds

hbase(main):030:0> drop 'TencentGames'
0 row(s) in 2.4520 seconds

hbase(main):031:0> list
TABLE                                                                                                                                                                      
scores                                                                                                                                                                     
1 row(s) in 0.1350 seconds

=> ["scores"]
hbase(main):032:0> 

12.查看表是否存在

hbase(main):009:0> exists 'TencentGames'
Table TencentGames does exist                                                                                                                                              
0 row(s) in 0.0240 seconds

hbase(main):010:0> 
发布了62 篇原创文章 · 获赞 32 · 访问量 2655

猜你喜欢

转载自blog.csdn.net/weixin_45627031/article/details/105642121
今日推荐