Hbase shell

HBase总结(十三)HBase Shell 常用命令及例子
2014-10-13 11:30 3482人阅读 评论(0) 收藏 举报
分类:
Hbase(22)

版权声明:本文为博主原创文章,未经博主允许不得转载。

下面我们看看HBase Shell的一些基本操作命令,我列出了几个常用的HBase Shell命令,如下:

名称
    
命令表达式
创建表
    
create ‘表名称‘, ‘列名称1‘,‘列名称2‘,‘列名称N‘
添加记录      
    
put ‘表名称‘, ‘行名称‘, ‘列名称:‘, ‘值‘
查看记录
    
get ‘表名称‘, ‘行名称‘
查看表中的记录总数
    
count  ‘表名称‘
删除记录
    
delete  ‘表名‘ ,‘行名称‘ , ‘列名称‘
删除一张表
    
先要屏蔽该表,才能对该表进行删除,第一步 disable ‘表名称‘ 第二步 drop ‘表名称‘
查看所有记录
    
scan "表名称"  
查看某个表某个列中所有数据
    
scan "表名称" , [‘列名称:‘]
更新记录
    
就是重写一遍进行覆盖

一、一般操作
1.查询服务器状态
hbase(main):024:0>status
3 servers, 0 dead,1.0000 average load

2.查询hive版本

hbase(main):025:0>version
0.90.4, r1150278,Sun Jul 24 15:53:29 PDT 2011

二、DDL操作

1.创建一个表
hbase(main):011:0>create ‘member‘,‘member_id‘,‘address‘,‘info‘   
0 row(s) in 1.2210seconds

2.获得表的描述
hbase(main):012:0>list
TABLE                                                                                                                                                       
member                                                                                                                                                      
1 row(s) in 0.0160seconds
hbase(main):006:0>describe ‘member‘
DESCRIPTION                                                                                          ENABLED                                               
{NAME => ‘member‘, FAMILIES => [{NAME=> ‘address‘, BLOOMFILTER => ‘NONE‘, REPLICATION_SCOPE => ‘0‘, true                                                 
  VERSIONS => ‘3‘, COMPRESSION => ‘NONE‘,TTL => ‘2147483647‘, BLOCKSIZE => ‘65536‘, IN_MEMORY => ‘fa                                                       
lse‘, BLOCKCACHE => ‘true‘}, {NAME =>‘info‘, BLOOMFILTER => ‘NONE‘, REPLICATION_SCOPE => ‘0‘, VERSI                                                       
ONS => ‘3‘, COMPRESSION => ‘NONE‘, TTL=> ‘2147483647‘, BLOCKSIZE => ‘65536‘, IN_MEMORY => ‘false‘,                                                        
BLOCKCACHE => ‘true‘}]}                                                                                                                                    
1 row(s) in 0.0230seconds

3.删除一个列族,alter,disable,enable
我们之前建了3个列族,但是发现member_id这个列族是多余的,因为他就是主键,所以我们要将其删除。
hbase(main):003:0>alter ‘member‘,{NAME=>‘member_id‘,METHOD=>‘delete‘}

ERROR: Table memberis enabled. Disable it first before altering.

报错,删除列族的时候必须先将表给disable掉。
hbase(main):004:0>disable ‘member‘                                  
0 row(s) in 2.0390seconds
hbase(main):005:0>alter‘member‘,NAME=>‘member_id‘,METHOD=>‘delete‘
0 row(s) in 0.0560seconds
hbase(main):006:0>describe ‘member‘
DESCRIPTION                                                                                          ENABLED                                               
{NAME => ‘member‘, FAMILIES => [{NAME=> ‘address‘, BLOOMFILTER => ‘NONE‘, REPLICATION_SCOPE => ‘0‘,false                                                 
  VERSIONS => ‘3‘, COMPRESSION => ‘NONE‘,TTL => ‘2147483647‘, BLOCKSIZE => ‘65536‘, IN_MEMORY => ‘fa                                                       
lse‘, BLOCKCACHE => ‘true‘}, {NAME =>‘info‘, BLOOMFILTER => ‘NONE‘, REPLICATION_SCOPE => ‘0‘, VERSI                                                       
ONS => ‘3‘, COMPRESSION => ‘NONE‘, TTL=> ‘2147483647‘, BLOCKSIZE => ‘65536‘, IN_MEMORY => ‘false‘,                                                        
BLOCKCACHE => ‘true‘}]}                                                                                                                                    
1 row(s) in 0.0230seconds
该列族已经删除,我们继续将表enable
hbase(main):008:0> enable ‘member‘  
0 row(s) in 2.0420seconds

4.列出所有的表
hbase(main):028:0>list
TABLE                                                                                                                                                       
member                                                                                                                                                      
temp_table                                                                                                                                                  
2 row(s) in 0.0150seconds

5.drop一个表
hbase(main):029:0>disable ‘temp_table‘
0 row(s) in 2.0590seconds

hbase(main):030:0>drop ‘temp_table‘
0 row(s) in 1.1070seconds

6.查询表是否存在
hbase(main):021:0>exists ‘member‘
Table member doesexist                                                                                                                                     
0 row(s) in 0.1610seconds

7.判断表是否enable
hbase(main):034:0>is_enabled ‘member‘
true                                                                                                                                                        
0 row(s) in 0.0110seconds

8.判断表是否disable
hbase(main):032:0>is_disabled ‘member‘
false                                                                                                                                                       
0 row(s) in 0.0110seconds

三、DML操作

1.插入几条记录
put‘member‘,‘scutshuxue‘,‘info:age‘,‘24‘
put‘member‘,‘scutshuxue‘,‘info:birthday‘,‘1987-06-17‘
put‘member‘,‘scutshuxue‘,‘info:company‘,‘alibaba‘
put‘member‘,‘scutshuxue‘,‘address:contry‘,‘china‘
put‘member‘,‘scutshuxue‘,‘address:province‘,‘zhejiang‘
put‘member‘,‘scutshuxue‘,‘address:city‘,‘hangzhou‘

put‘member‘,‘xiaofeng‘,‘info:birthday‘,‘1987-4-17‘
put‘member‘,‘xiaofeng‘,‘info:favorite‘,‘movie‘
put‘member‘,‘xiaofeng‘,‘info:company‘,‘alibaba‘
put‘member‘,‘xiaofeng‘,‘address:contry‘,‘china‘
put‘member‘,‘xiaofeng‘,‘address:province‘,‘guangdong‘
put‘member‘,‘xiaofeng‘,‘address:city‘,‘jieyang‘
put‘member‘,‘xiaofeng‘,‘address:town‘,‘xianqiao‘

2.获取一条数据
获取一个id的所有数据
hbase(main):001:0>get ‘member‘,‘scutshuxue‘
COLUMN                                   CELL                                                                                                               
address:city                           timestamp=1321586240244, value=hangzhou                                                                            
address:contry                         timestamp=1321586239126, value=china                                                                               
address:province                       timestamp=1321586239197, value=zhejiang                                                                            
info:age                               timestamp=1321586238965, value=24                                                                                  
info:birthday                          timestamp=1321586239015, value=1987-06-17                                                                          
info:company                           timestamp=1321586239071, value=alibaba                                                                             
6 row(s) in 0.4720seconds

获取一个id,一个列族的所有数据
hbase(main):002:0>get ‘member‘,‘scutshuxue‘,‘info‘
COLUMN                                   CELL                                                                                                               
info:age                               timestamp=1321586238965, value=24                                                                                  
info:birthday                          timestamp=1321586239015, value=1987-06-17                                                                          
info:company                           timestamp=1321586239071, value=alibaba                                                                             
3 row(s) in 0.0210seconds

获取一个id,一个列族中一个列的所有数据
hbase(main):002:0>get ‘member‘,‘scutshuxue‘,‘info:age‘
COLUMN                                   CELL                                                                                                               
info:age                               timestamp=1321586238965, value=24                                                                                  
1 row(s) in 0.0320seconds

6.更新一条记录
将scutshuxue的年龄改成99
hbase(main):004:0>put ‘member‘,‘scutshuxue‘,‘info:age‘ ,‘99‘
0 row(s) in 0.0210seconds

hbase(main):005:0>get ‘member‘,‘scutshuxue‘,‘info:age‘
COLUMN                                   CELL                                                                                                               
info:age                               timestamp=1321586571843, value=99                                                                                  
1 row(s) in 0.0180seconds

3.通过timestamp来获取两个版本的数据
hbase(main):010:0>get ‘member‘,‘scutshuxue‘,{COLUMN=>‘info:age‘,TIMESTAMP=>1321586238965}
COLUMN                                   CELL                                                                                                               
info:age                               timestamp=1321586238965, value=24                                                                                  
1 row(s) in 0.0140seconds

hbase(main):011:0>get ‘member‘,‘scutshuxue‘,{COLUMN=>‘info:age‘,TIMESTAMP=>1321586571843}
COLUMN                                   CELL                                                                                                               
info:age                               timestamp=1321586571843, value=99                                                                                  
1 row(s) in 0.0180seconds

4.全表扫描:
hbase(main):013:0>scan ‘member‘
ROW                                     COLUMN+CELL                                                                                                        
scutshuxue                             column=address:city, timestamp=1321586240244, value=hangzhou                                                       
scutshuxue                             column=address:contry, timestamp=1321586239126, value=china                                                        
scutshuxue                             column=address:province, timestamp=1321586239197, value=zhejiang                                                   
scutshuxue                              column=info:age,timestamp=1321586571843, value=99                                                                 
scutshuxue                             column=info:birthday, timestamp=1321586239015, value=1987-06-17                                                    
scutshuxue                             column=info:company, timestamp=1321586239071, value=alibaba                                                        
temp                                   column=info:age, timestamp=1321589609775, value=59                                                                 
xiaofeng                               column=address:city, timestamp=1321586248400, value=jieyang                                                        
xiaofeng                               column=address:contry, timestamp=1321586248316, value=china                                                        
xiaofeng                               column=address:province, timestamp=1321586248355, value=guangdong                                                  
xiaofeng                               column=address:town, timestamp=1321586249564, value=xianqiao                                                       
xiaofeng                               column=info:birthday, timestamp=1321586248202, value=1987-4-17                                                     
xiaofeng                               column=info:company, timestamp=1321586248277, value=alibaba                                                        
xiaofeng                               column=info:favorite, timestamp=1321586248241, value=movie                                                         
3 row(s) in 0.0570seconds

5.删除id为temp的值的‘info:age’字段
hbase(main):016:0>delete ‘member‘,‘temp‘,‘info:age‘
0 row(s) in 0.0150seconds
hbase(main):018:0>get ‘member‘,‘temp‘
COLUMN                                   CELL                                                                                                               
0 row(s) in 0.0150seconds

6.删除整行

hbase(main):001:0>deleteall ‘member‘,‘xiaofeng‘
0 row(s) in 0.3990seconds

7.查询表中有多少行:
hbase(main):019:0>count ‘member‘                                        
2 row(s) in 0.0160seconds

8.给‘xiaofeng’这个id增加‘info:age‘字段,并使用counter实现递增
hbase(main):057:0*incr ‘member‘,‘xiaofeng‘,‘info:age‘                    
COUNTER VALUE = 1

hbase(main):058:0>get ‘member‘,‘xiaofeng‘,‘info:age‘
COLUMN                                   CELL                                                                                                               
info:age                               timestamp=1321590997648, value=\x00\x00\x00\x00\x00\x00\x00\x01                                                    
1 row(s) in 0.0140seconds

hbase(main):059:0>incr ‘member‘,‘xiaofeng‘,‘info:age‘
COUNTER VALUE = 2

hbase(main):060:0>get ‘member‘,‘xiaofeng‘,‘info:age‘
COLUMN                                   CELL                                                                                                               
info:age                               timestamp=1321591025110, value=\x00\x00\x00\x00\x00\x00\x00\x02                                                    
1 row(s) in 0.0160seconds

获取当前count的值
hbase(main):069:0>get_counter ‘member‘,‘xiaofeng‘,‘info:age‘
COUNTER VALUE = 2
 
9.将整张表清空:
hbase(main):035:0>truncate ‘member‘
Truncating ‘member‘table (it may take a while):
- Disabling table...
- Dropping table...
- Creating table...
0 row(s) in 4.3430seconds

可以看出,hbase是先将掉disable掉,然后drop掉后重建表来实现truncate的功能的。

时间: 2024-10-29 19:11:24

Hbase shell的相关文章

hbase shell 命令

1.首先要打开hbase,使用jps查看进程 jps是java进程状态工具,它会返回进程ID和服务名称 [email protected]:~/Apache/hbase-0.94.15-security$ jps 3082 NameNode 6245 HRegionServer 3493 JobTracker 6064 HMaster 5999 HQuorumPeer 3638 TaskTracker 3259 DataNode 3413 SecondaryNameNode 6320 Jps 2

Hbase shell操作(完整版记录)

1.进入Hbase命令行 >hbase shell 退出命令行 >quit 2.创建表 >create 'users','user_id','address','info' 3.查看所有表 >list 4.查看表结构 >describe 'users' 5.删除表: >disable 'users' >drop 'users' 6.新增数据 >put 'users','xiaowang','info:age','26' >put 'users','xi

hadoop(九) - hbase shell命令

1. 进入hbase命令行  ./hbase shell 2. 显示hbase中的表  list 3. 创建user表,包含info.data两个列族 create 'user', 'info1', 'data1' create 'user', {NAME => 'info', VERSIONS => '3'} 4. 向表中插入信息: 向user表中插入信息,row key为rk0001,列族info中添加name列标示符,值为zhangsan put 'user', 'rk0001', 'i

hbase shell常用命令

hive常用命令 show tables; 列出hive里面所有数据表名 desc userProfile; 显示数据表userProfile的基本表字段及字段type desc extended trackinfo; 显示数据表trackinfo的详细信息,包括字段说明,数据表等 /usr/local/cloud/hive/bin/hive 进入hive数据库 select attribute_name from pms_attribute where attribute_id=21000 a

hbase shell删除没实用

用Xshell登陆linux主机后,在hbase shell下不能使用backspace和delete删除误输的指令,这是Xshell的配置问题: 在File->Properties->Terminal->Keyboard下,把DELETE/BACKSPACE key sequence选为ASCII 127. 如此以来,就能使用backspace了

云计算--hbase shell

具体的 HBase Shell 命令如下表 1.1-1 所示: 下面我们将以"一个学生成绩表"的例子来详细介绍常用的 HBase 命令及其使用方法. 这里 grad 对于表来说是一个列,course 对于表来说是一个列族,这个列族由三个列组成 china.math 和 english,当然我们可以根据我们的需要在 course 中建立更多的列族,如computer,physics 等相应的列添加入 course 列族.(备注:列族下面的列也是可以没有名字的.)1). create 命令

HBase shell 命令。

HBase shell 命令. 进入hbase shell console$HBASE_HOME/bin/hbase shell如果有kerberos认证,需要事先使用相应的keytab进行一下认证(使用kinit命令),认证成功之后再使用hbase shell进入可以使用whoami命令可查看当前用户 hbase(main)> whoami 表的管理1)查看有哪些表 hbase(main)> list 2)创建表 # 语法:create <table>, {NAME =>

HBase基本概念和hbase shell常用命令用法

1. 简介 HBase是一个分布式的.面向列的开源数据库,源于google的一篇论文<bigtable:一个结构化数据的分布式存储系统>.HBase是Google Bigtable的开源实现,它利用Hadoop HDFS作为其文件存储系统,利用Hadoop MapReduce来处理HBase中的海量数据,利用Zookeeper作为协同服务. 2. HBase的表结构 HBase以表的形式存储数据.表有行和列组成.列划分为若干个列族/列簇(column family). Row Key colu

HBase Shell相关

1.进入hbase命令行 ./hbase shell 2.基本命令 显示hbase中的表List list 查询user表中的所有信息Scan scan 'users' 清空user表中的数据Truncate (等同于disable + drop + create) truncate 'users' 删除表Drop disable 'user' drop 'user' 3.修改表结构 首先停用user表(新版本不用)disable 'user',最后再启用表 enable 'user' 添加新的

HBase Shell输入命令无法删除问题解决技巧

一.引言: HBase shell使用过程中,使用CRT客户端,命令输入后无法删除一直困绕着我,今天终于受不了,几番度娘,谷哥之后,终于有了解决方法,特共享给大家.二.操作步骤secureCRT中,点击[选项][回话选项][终端][仿真],右边的终端选择linux英文版本请对应选择输入: 三.删除操作 执行删除操作时,需要使用组合键:Ctrl+Back Space同时按下,不妨现在就开始尝试一下吧.