hbase-day02

1 shell-客户端

1.1 建表 

create 是建表的关键字
help "create" 查看建表的基本语法
**   create "tb_name" , "cf1"  , "cf2"  在建表的时候至少指定一个列族
**   create "tb_b" , {NAME => "cf1" , TTL=>60 , VERSIONS=>3} ,{NAME=>"cf2"}

属性的配置  描述整个列族
   NAME 列族名称
   VERSIONS 整个列族的所有的数据存储3个数据版本
   TTL整个列族的所有的数据存储时间 单位秒
   K=>V   里面设置的KEY是固定不变
   {} , {} 多个列族 

1.2 列出系统中所有的表

  hbase> list
  hbase> list 'abc.*'
  hbase> list 'ns:abc.*'
  hbase> list 'ns:.*'

1.2 修改表结构

添加修改删除列族 , 修改配置选项

1.2.1添加修改列族

alter 'tb_b', NAME => 'cf3', VERSIONS => 5  如果列族不存在  添加列族 

alter 'tb_b', NAME => 'cf3', VERSIONS => 2  如果列族存在 修改列族的属性值

1.2.2 删除列族

 hbase> alter 'ns1:t1', NAME => 'f1', METHOD => 'delete'
  hbase> alter 'ns1:t1', 'delete' => 'f1'

alter "tb_b" , 'delete'=>"cf2"

1.2.3  修改列族的名字

删除要修改的列族

添加新的列族  保证配置属性一致

Commands: alter, alter_async, alter_status, clone_table_schema, create, describe, disable, disable_all, drop, drop_all, enable, enable_all, exists, get_table, is_disabled, is_enabled, list, list_regions, locate_region, show_filters

  • alter   
  • create 
  • describe  desc 
  • disable 禁用表
  • disable_all 禁用多张表
  • drop   删除表 
  • drop_all   删除多张表
  • enable
  • enable_all  启用多张表
  • exists 是否存在
  • is_disabled
  • is_enabled
  • list
  • list_regions  列出表所有的region信息
  • locate_region  查看某行数据在哪个region中
  • show_filters 列出所有的过滤器   过滤器实现数据的筛选过滤

1 disable 禁用表

hbase(main):009:0> disable "tb_user"
Took 0.9212 seconds                                                                                          
hbase(main):010:0> is_disabled  "tb_user"
true                                                                                                         
Took 0.0388 seconds                                                                                          
=> 1

禁用的表是不能查询数据和更新数据 , 删除表, 修改表结构  , 读写数据和修改表内结构分离  DDL和DML分离

hbase(main):011:0> scan "tb_user"
ROW                          COLUMN+CELL                                                                     
org.apache.hadoop.hbase.TableNotEnabledException: tb_user is disabled.
hbase(main):012:0> put "tb_user" , "rk10004" ,"cf1:name" ,"abc"

ERROR: Table tb_user is disabled!

For usage try 'help "put"'

2 disable_all 禁用多张表

hbase(main):027:0> disable_all  "tb.*"
tb_a                                                                                                         
tb_b                                                                                                         
tb_user                                                                                                      

Disable the above 3 tables (y/n)?
y
3 tables successfully disabled
Took 10.8733 seconds 

3 drop   删除表 

Drop the named table. Table must first be disabled:
 
hbase> drop 't1'
  hbase> drop 'ns1:t1'

disable "tb_a"  drop "tb_a"

4 drop_all   删除多张表

disable_all  "tb.*"   先禁用

drop_all "tb.*"     再删除

5 enable

  1. enable_all  启用多张表

hbase(main):028:0> enable_all  "tb.*"
tb_a                                                                                                         
tb_b                                                                                                         
tb_user                                                                                                      

Enable the above 3 tables (y/n)?
y
3 tables successfully enabled
Took 5.8575 seconds  

6 exists 是否存在

hbase(main):043:0> exists  "tb_a"
Table tb_a does not exist                                                                                    
Took 0.0210 seconds                                                                                          
=> false

hbase(main):045:0> exists  "tb_b"
Table tb_b does exist                                                                                        
Took 0.0054 seconds                                                                                          
=> true

7is_disabled

8 is_enabled

hbase(main):022:0> is_enabled  "tb_user"
true                                                                                                         
Took 0.0172 seconds                                                                                          
=> true
hbase(main):023:0> is_disabled  "tb_user"
false                                                                                                        
Took 0.0185 seconds                                                                                          
=> 1

9 list 

hbase(main):062:0> list  "doit18:.*"
TABLE                                                                                                        
doit18:tb_x                       

10 list_regions  列出表所有的region信息

hbase(main):070:0> list_regions  "tb_a"
                 SERVER_NAME |                                           REGION_NAME |  START_KEY |    END_KEY |  SIZE |   REQ |   LOCALITY |
 --------------------------- | ----------------------------------------------------- | ---------- | ---------- | ----- | ----- | ---------- |
 linux03,16020,1601428264252 | tb_a,,1601434162446.0244bbb9434054d22637194b5e93d8ef. |            |            |     0 |     2 |        0.0 |

split "tb_a"  

split "tb_a"  ,"rk0003"  指定切割点

hbase(main):086:0> list_regions "tb_a"
                 SERVER_NAME |                                                 REGION_NAME |  START_KEY |    END_KEY |  SIZE |   REQ |   LOCALITY |
 --------------------------- | ----------------------------------------------------------- | ---------- | ---------- | ----- | ----- | ---------- |
 linux03,16020,1601428264252 |       tb_a,,1601435670399.622d39361afc04e550892b48bcda3ca6. |            |     rk0003 |     0 |     0 |        1.0 |
 linux03,16020,1601428264252 | tb_a,rk0003,1601435670399.7df34040edf7d4ded53122fb4c6f034a. |     rk0003 |            |     0 |     0 |        1.0 |
 2 rows

11 locate_region  查看某行数据在哪个region中  rk0003

hbase(main):089:0> list_regions "tb_a"
                 SERVER_NAME |                                                 REGION_NAME |  START_KEY |    END_KEY |  SIZE |   REQ |   LOCALITY |
 --------------------------- | ----------------------------------------------------------- | ---------- | ---------- | ----- | ----- | ---------- |
 linux03,16020,1601428264252 |       tb_a,,1601435670399.622d39361afc04e550892b48bcda3ca6. |            |     rk0003 |     0 |     0 |        1.0 |
 linux01,16020,1601428264314 | tb_a,rk0003,1601435670399.7df34040edf7d4ded53122fb4c6f034a. |     rk0003 |            |     0 |     0 |        1.0 |
 2 rows
Took 0.0614 seconds                                                                                                                
hbase(main):090:0> locate_region "tb_a" , "rk0003"
HOST                              REGION                                                                                           
 linux01:16020                    { ENCODED => 7df34040edf7d4ded53122fb4c6f034a, NAME => 'tb_a,rk0003,1601435670399.7df34040edf7d4de
                                  d53122fb4c6f034a.', STARTKEY => 'rk0003', ENDKEY => ''}                                          
1 row(s)
Took 0.0056 seconds                                                        

12 预分region表

create "tb_s" , "cf" , SPLITS => ['4','7']

注意: 数据在Hbase中存储的时候是以rowkey进行排序,切割点划分数据存储范围[region存储数据的范围]

13 show_filters 列出所有的过滤器   过滤器实现数据的筛选过滤

显示系统中所有实现的过滤器 

DML

  Group name: dml
  Commands: append, count, delete, deleteall, get, get_counter, get_splits, incr, put, scan, truncate, truncate_preserve

1 append

向已经存在的值后面追加内容

append "tb_a" , "rk0002", "cf:name" ," AAA"

2 count

统计数据的行数据  

3  delete 删除数据

只能删除某行的某个列族的属性  只能删除单元格

delete "tb_a" , "rk0007" , "cf:name"  

4  deleteall

delete tb_name  , RK  删除整行

delete tb_name  , RK, "cf:属性" 删除一个属性

5  get 获取数据

获取整行数据   get tb_name , rowkey

获取行的某个列族  get tb_name , rowkey , cf

获取行的多个列族get tb_name , rowkey , cf1 , cf2

获取行的某个单元格   get tb_name , rowkey , cf:属性

获取行的多个列族中的多个单元格   get tb_name , rowkey , cf:1:属性1 , cf1:属性2 , cf2:属性3

注意 在get总一定有表名和行键两个参数

6  get_counter 和 incr

incr "tb_a" , "rk0001" , "cf:c" , 1

incr "tb_a" , "rk0001" , "cf:c" , 1

incr "tb_a" , "rk0001" , "cf:c" , 4

7  get_splits 获取表的切割点

 

8 put  插入或者是更新数据

表 行 列族 属性  值 

put  tb_name  , rowkey  , 列族:属性  ,  值

put "tb_a" ,"rk0007" , "cf:name" , "heihei"

9  scan 

scan   tb_name  查看表中所有的数据

scan tb_name , {STARTROW=>'rk0003' , LIMIT=>3 , COLUMN=>'列族'} 指定列族  起始位置

10  truncate

添加数据 修改数据  删除数据 查询数据   

delete  "tb_a" , "rk0001" , "cf:name" 
 

猜你喜欢

转载自blog.csdn.net/qq_37933018/article/details/108880100