Hbase常见操作

进入hbase

hbase shell

可以查看命令如何使用

help 'put'

1、建表

hbase(main):002:0> create 't1',{NAME=>'cf1'}
Created table t1
Took 1.0852 seconds  

hbase(main):022:0> create 'tb_t3','cf1','cf2','cf3'
Created table tb_t3
Took 1.2607 seconds  

hbase(main):024:0> create 'tb_t4',{NAME=>'cf1',VERSIONS=>'5'},'cf2','cf3'
Created table tb_t4
Took 2.2881 seconds 


2、list 列出系统中所有的表,scan 查看表中的数据

hbase(main):009:0> list
TABLE                                                                                                                                                                                                                                                             
t1                                                                                                                                                                                                                                                                
1 row(s)


hbase(main):016:0> scan 't1'
ROW                                                                   COLUMN+CELL                                                                                                                                                                                                 
0 row(s)

3、插入数据

hbase(main):028:0> put 't1','rk001','cf1:uid','uid001'
Took 0.0535 seconds                                                                                                                                                                                                                                                               
hbase(main):029:0> scan 't1'
ROW                                                                   COLUMN+CELL                                                                                                                                                                                                 
 rk001                                                                column=cf1:uid, timestamp=1616312018455, value=uid001                                                                                                                                                       
1 row(s)
Took 0.0206 seconds      

4、添加修改删除列族

如果有就更新,没有就添加
hbase(main):042:0> alter 't1' ,NAME=>'cf3',VERSIONS=>5
Updating all regions with the new schema...
1/1 regions updated.
Done.
Took 2.6825 seconds   

--删除

hbase(main):045:0> alter 't1' , 'delete'=>'cf3'
Updating all regions with the new schema...
1/1 regions updated.
Done.
Took 2.6309 seconds 


hbase(main):047:0> alter 't1' ,NAME=>'cf3',VERSIONS=>5,METHOD=>'delete'
Unknown argument ignored: VERSIONS
Updating all regions with the new schema...
1/1 regions updated.

5、禁用表

disable 't1’

禁用的表不能对数据进行操作,不能put delete scan

可以alter 修改表结构

drop 表前要先禁用表

hbase(main):006:0> disable 'tb_t4'
Took 0.8404 seconds                                                                                                                                                                                                                                                               
hbase(main):007:0> drop 'tb_t4'
Took 0.2509 seconds  

6、将表赋值给t ,然后通过t调用命令

hbase(main):009:0> t=get_table 't1'
Took 0.0003 seconds                                                                                                                                                                                                                                                               
=> Hbase::Table - t1
hbase(main):010:0> t.scan
ROW                                                                   COLUMN+CELL                                                                                                                                                                                                 
 rk001                                                                column=cf1:age, timestamp=1616312073156, value=21                                                                                                                                                           
 rk001                                                                column=cf1:name, timestamp=1616312045616, value=Alice                                                                                                                                                       
 rk001                                                                column=cf1:uid, timestamp=1616312018455, value=uid001                                                                                                                                                       
 rk002                                                                column=cf1:age, timestamp=1616312089155, value=23                                                                                                                                                           
2 row(s)
Took 0.0124 seconds    

7、查看数据文件

hbase hfile -p -f /hbase/data/default/t1/b2d5e5c725b9ff6e828c551f427e3df7/cf1/e1ada1f4d3a541b9872b40ac4673c422

region 名称:  b2d5e5c725b9ff6e828c551f427e3df7

8、按照指定的rk将一个region切割成两个region

hbase(main):021:0> split 't1' ,'rk002'
Took 0.2423 seconds                                                                                                                                                                                                                                                               

hbase(main):023:0> list_regions 't1'
                SERVER_NAME |                                              REGION_NAME |  START_KEY |    END_KEY |  SIZE |   REQ |   LOCALITY |
 -------------------------- | -------------------------------------------------------- | ---------- | ---------- | ----- | ----- | ---------- |
 master,16020,1616308766374 |      t1,,1616323524898.a0607dd00fd072b508ab32afdfbea9cb. |            |      rk002 |     0 |     0 |        1.0 |
 master,16020,1616308766374 | t1,rk002,1616323524898.047a3be11a8ecb734fd52e95ad87f9a2. |      rk002 |            |     0 |     0 |        1.0 |
 2 rows
Took 0.0406 seconds  

9、建表时指定RK的规则预分region

hbase(main):032:0> create 'tb_split','cf',SPLITS=>['e','l','o']
Created table tb_split
Took 2.3189 seconds  


hbase(main):033:0> list_regions 'tb_split'
                SERVER_NAME |                                                REGION_NAME |  START_KEY |    END_KEY |  SIZE |   REQ |   LOCALITY |
 -------------------------- | ---------------------------------------------------------- | ---------- | ---------- | ----- | ----- | ---------- |
 master,16020,1616308766374 |  tb_split,,1616325215163.6107b005c0ae1fb7c32789cdab645581. |            |          e |     0 |     0 |        0.0 |
 master,16020,1616308766374 | tb_split,e,1616325215163.7c21f3deba399512f27b103300eec988. |          e |          l |     0 |     0 |        0.0 |
 master,16020,1616308766374 | tb_split,l,1616325215163.904de08df703786319acf279d9f93318. |          l |          o |     0 |     0 |        0.0 |
 master,16020,1616308766374 | tb_split,o,1616325215163.331c39b8f032b3141db87310008219ee. |          o |            |     0 |     0 |        0.0 |
 4 rows

10、将内存中的数据写道HDFS中以hfile文件的格式存储

flush 'tb_split'

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值