HBase Shell基本操作

启动hbase shell

hbase shell

启动后输入status可以查看当前服务器集群的状态

帮助命令help

可查看各种命令说明

表操作

查看数据库列表list

末尾不需要加分号,直接回车

hbase(main):001:0> list
TABLE                                                                                                             
0 row(s) in 0.1670 seconds

=> []
hbase(main):002:0> 

以上表示数据库中无数据
hbase shell命令输错误后,如要回退,需要Shift+Backspace或Ctrl+Backspace

创建一个表,包括一个列簇

create 'table1', 'family 1'

前面是标明,后面是列簇名,可以跟多个

hbase(main):002:0> create 'table1', 'family 1'
0 row(s) in 1.2460 seconds

=> Hbase::Table - table1
hbase(main):003:0> 

查看某一张表的介绍desc

desc+表名 (表名需要用引号引起来)

hbase(main):003:0> desc table1
NameError: undefined local variable or method `table1' for #<Object:0x999b951>

hbase(main):004:0> desc 'table1'
Table table1 is ENABLED                                                                                           
table1                                                                                                            
COLUMN FAMILIES DESCRIPTION                                                                                       
{NAME => 'family 1', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', D
ATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true', 
BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}                                                                   
1 row(s) in 0.1050 seconds

hbase(main):005:0> 

插入数据put

put+表名+行+列簇名:列名+值
put ‘table1’,‘1’,‘family 1:father’,‘Mike’
put ‘table1’,‘1’,‘family 1:mother’,‘Lily’

hbase(main):006:0> put 'table1','1','family 1:father','Mike'
0 row(s) in 0.0220 seconds
hbase(main):007:0> put 'table1','1','family 1:mother','Lily'
0 row(s) in 0.0090 seconds

获取数据get

get ‘table1’ , ‘1’

hbase(main):008:0> get 'table1' , '1'
COLUMN                        CELL                                                                                
 family 1:father              timestamp=1543824652559, value=Mike                                                 
 family 1:mother              timestamp=1543824687136, value=Lily                                                 
2 row(s) in 0.0370 seconds
hbase(main):009:0> 

修改表alter

修改列的版本

hbase(main):009:0> alter 'table1',NAME=>'family 1',VERSIONS=>2
Updating all regions with the new schema...
1/1 regions updated.
Done.
0 row(s) in 1.9170 seconds

表引用Table Reference

相当于指定一个变量名来操作表
t = get_table ‘space1:table2’
t.disable
t.drop

禁用及启用表

hbase(main):009:0> disable 'table1'
0 row(s) in 2.2480 seconds
hbase(main):010:0> enable 'table1'
0 row(s) in 1.2400 seconds
hbase(main):011:0> 

删除表

删除前需要先禁用

hbase(main):012:0> drop 'table1'
ERROR: Table table1 is enabled. Disable it first.
Here is some help for this command:
Drop the named table. Table must first be disabled:
  hbase> drop 't1'
  hbase> drop 'ns1:t1'

hbase(main):013:0> disable 'table1'
0 row(s) in 2.2270 seconds

hbase(main):014:0> drop 'table1'
0 row(s) in 1.2400 seconds

hbase(main):015:0> list
TABLE                                                                                                             
0 row(s) in 0.0050 seconds

=> []
hbase(main):016:0> 

namespace操作

查看namespace

HBase默认有两个namespace,分别为default和hbase

hbase(main):002:0> list_namespace
NAMESPACE                                                                       
default                                                                         
hbase                                                                           
2 row(s) in 0.2140 seconds

创建namespace

hbase(main):005:0> create_namespace 'space1'
0 row(s) in 0.0400 seconds
hbase(main):006:0> describe_namespace 'space1'
DESCRIPTION                                                                     
{NAME => 'space1'}                                                              
1 row(s) in 0.0180 seconds

修改namespace

增加属性Created

hbase(main):007:0> alter_namespace 'space1', {METHOD => 'set', 'Created' => 'Darren'}
0 row(s) in 0.0290 seconds
hbase(main):008:0> describe_namespace 'space1'
DESCRIPTION                                                                                           
{NAME => 'space1', Created => 'Darren'}                                                               
1 row(s) in 0.0090 seconds

删除属性Created

hbase(main):009:0> alter_namespace 'space1', {METHOD => 'unset', NAME => 'Created'}
0 row(s) in 0.0220 seconds
hbase(main):010:0> describe_namespace 'space1'
DESCRIPTION                                                                                           
{NAME => 'space1'}                                                                                    
1 row(s) in 0.0040 seconds

新建namespace下的表

hbase(main):012:0> create 'space1:table2', 'f1', 'f2'
0 row(s) in 1.2760 seconds

=> Hbase::Table - space1:table2

注:不指定namespace将在default下面创建

查看namespace下的表

hbase(main):001:0> list_namespace_tables 'space1'
TABLE                                                                                                 
table2                                                                                                
1 row(s) in 0.2170 seconds
hbase(main):001:0> desc 'space1:table2'
Table space1:table2 is ENABLED                                                                        
space1:table2                                                                                         
COLUMN FAMILIES DESCRIPTION                                                                           
{NAME => 'f1', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FAL
SE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOC
KCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}                                     
{NAME => 'f2', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FAL
SE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOC
KCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}                                     
2 row(s) in 0.2760 seconds

分区Region

查看分区

查看table2的f1列所在的分区

hbase(main):010:0> locate_region  'space1:table2', 'f1'
HOST                       REGION                                                                     
 bigdata:37003             {ENCODED => d9ccf0ed2d0f4f93d8b778c118d07618, NAME => 'space1:table2,,15450
                           98660301.d9ccf0ed2d0f4f93d8b778c118d07618.', STARTKEY => '', ENDKEY => ''} 
1 row(s) in 0.0180 seconds

查看table2分区数

hbase(main):001:0> get_splits 'space1:table2'
Total number of splits = 1

=> []
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值