hbase 常用命令

2 篇文章 0 订阅

查看有哪些表

hbase(main):030:0> list
TABLE                                                                                                                                                                                          
mytable                                                                                                                                                                                        
t_users                                                                                                                                                                                        
test                                                                                                                                                                                           
3 row(s) in 0.0160 seconds

=> ["mytable", "t_users", "test"]

创建表

# 语法:create <table>, {NAME => <family>, VERSIONS => <VERSIONS>}
#或者 create <table>,<列>

hbase(main):024:0> create 't_users','info'
0 row(s) in 1.2600 seconds

=> Hbase::Table - t_users

查看表结构

hbase(main):028:0> describe 't_users'
Table t_users is ENABLED                                                                                                                                                                       
t_users                                                                                                                                                                                        
COLUMN FAMILIES DESCRIPTION                                                                                                                                                                    
{NAME => 'info', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', VERSIONS => '1', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => 'FOREVER', KEEP_DELETED_CEL
LS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'}                                                                                                               
1 row(s) in 0.0440 seconds

修改表结构

#修改表结构必须先disable

# 语法:alter 't1', {NAME => 'f1'}, {NAME => 'f2', METHOD => 'delete'}
# 例如:修改表test1的cf的TTL为180天
hbase(main)> disable 'test1'
hbase(main)> alter 'test1',{NAME=>'body',TTL=>'15552000'},{NAME=>'meta', TTL=>'15552000'}
hbase(main)> enable 'test1'

删除表

#分两步:首先disable,然后drop
hbase(main)> disable 'tableName'
hbase(main)> drop 'tableName'

添加数据

#put
# 语法:put <table>,<rowkey>,<family:column>,<value>
hbase(main):010:0> put 'mytable','first','cf:message','hello' 
0 row(s) in 0.0610 seconds

查询数据

# 语法:get <table>,<rowkey>,[<family:column>,....]

hbase(main):021:0> get 'mytable','last' 
COLUMN                                           CELL                                                                                                                                          
 cf:_version                                     timestamp=1492179089588, value=1.1                                                                                                            
 cf:message                                      timestamp=1492178911594, value=xuyw                                                                                                           
2 row(s) in 0.0330 seconds

扫描表

# 语法:scan <table>, {COLUMNS => [ <family:column>,.... ], LIMIT => num}
# 例如:扫描表test的前4条数据
hbase(main)> scan 'test',{LIMIT=>4}

查询表中的数据行数


# 语法:count <table>, {INTERVAL => intervalNum, CACHE => cacheNum}

删除行中的某个列值(删除整行,无需列名)

# 语法:delete <table>, <rowkey>,  <family:column> , 必须指定列名

hbase(main)> delete 'test','last','cf:msg'

删除表中的所有数据


# 语法: truncate <table>
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值