Hbase shell 常用命令笔记
Posted ZeroTeam_麒麟
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Hbase shell 常用命令笔记相关的知识,希望对你有一定的参考价值。
下面我们看看 HBase Shell 的一些基本操作命令,我列出了几个常用的 HBase Shell 命令,如下:一、一般操作
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
以上是关于Hbase shell 常用命令笔记的主要内容,如果未能解决你的问题,请参考以下文章