HBase Shell 基本命令

本文介绍一些常用的HBase Shell下的基本命令,如查看表、创建表、删除表等等。
假设你已经安装了Hadoop集群并且安装了HBase组件,通过以下方法直接进入HBase Shell,

[centos@cent-2 ~]$ hbase shell
2016-11-17 13:11:48,126 INFO  [main] Configuration.deprecation: hadoop.native.lib is deprecated. Instead, use io.native.lib.available
HBase Shell; enter 'help<RETURN>' for list of supported commands.
Type "exit<RETURN>" to leave the HBase Shell
Version 0.98.4.2.2.0.0-2041-hadoop2, r18e3e58ae6ca5ef5e9c60e3129a1089a8656f91d, Wed Nov 19 15:10:28 EST 2014

hbase(main):001:0>

下面就介绍几个比较常用的HBase Shell命令。

1 status –查看HBase状态

hbase(main):001:0> status
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/usr/hdp/2.2.0.0-2041/hadoop/lib/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/usr/hdp/2.2.0.0-2041/zookeeper/lib/slf4j-log4j12-1.6.1.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
1 servers, 0 dead, 119.0000 average load

2 version –查看HBase版本信息

hbase(main):002:0> version
0.98.4.2.2.0.0-2041-hadoop2, r18e3e58ae6ca5ef5e9c60e3129a1089a8656f91d, Wed Nov 19 15:10:28 EST 2014

3 create tablename,columnname1,…,columnnameN –创建表

hbase(main):013:0* create 'testtable','colfam1','colfam2','colfam3'
0 row(s) in 0.3450 seconds

=> Hbase::Table - testtable

4 describe tablename –描述表定义

hbase(main):014:0> describe 'testtable'
DESCRIPTION                                                                                                                        ENABLED
 'testtable', {NAME => 'colfam1', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', VERSIONS => '1',  true
 COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => 'FOREVER', KEEP_DELETED_CELLS => 'false', BLOCKSIZE => '65536', IN_MEMORY => '
 false', BLOCKCACHE => 'true'}, {NAME => 'colfam2', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0',
  VERSIONS => '1', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => 'FOREVER', KEEP_DELETED_CELLS => 'false', BLOCKSIZE => '6553
 6', IN_MEMORY => 'false', BLOCKCACHE => 'true'}, {NAME => 'colfam3', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICA
 TION_SCOPE => '0', VERSIONS => '1', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => 'FOREVER', KEEP_DELETED_CELLS => 'false',
 BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'}
1 row(s) in 0.0660 seconds

5 list –列出所有表

hbase(main):015:0> list
TABLE
TRAFODION.PERSNL.DEPT
TRAFODION.PERSNL.EMPLOYEE
TRAFODION.PERSNL.JOB
TRAFODION.PERSNL.PROJECT
TRAFODION.PERSNL.SB_HISTOGRAMS
TRAFODION.PERSNL.SB_HISTOGRAM_INTERVALS
TRAFODION.PERSNL.XDEPTMGR
...

6 put tablename,rowname,columnname,value –插入数据

hbase(main):019:0* put 'testtable','row1','colfam1','123'
0 row(s) in 0.1130 seconds

hbase(main):020:0> put 'testtable','row1','colfam1:col1','456'
0 row(s) in 0.0040 seconds

7 scan tablename –全表查询

hbase(main):021:0> scan 'testtable'
ROW                                                 COLUMN+CELL
 row1                                               column=colfam1:, timestamp=1479360510670, value=123
 row1                                               column=colfam1:col1, timestamp=1479360528526, value=456
1 row(s) in 0.0230 seconds

8 get tablename,rowname –查询表中行的数据

hbase(main):022:0> get 'testtable','row1'
COLUMN                                              CELL
 colfam1:                                           timestamp=1479360510670, value=123
 colfam1:col1                                       timestamp=1479360528526, value=456
2 row(s) in 0.0080 seconds

9 count tablename –查询表中的记录数

hbase(main):023:0> count 'testtable'
1 row(s) in 0.0200 seconds

=> 1

10 delete tablename,rowname, columnname–删除一个CELL

hbase(main):041:0> delete 'testtable','row1','colfam1:col1'
0 row(s) in 0.0050 seconds

11 disable & drop tablename –删除表

hbase(main):042:0> drop 'testtable'

ERROR: Table testtable 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):043:0> disable 'testtable'
d0 row(s) in 1.2940 seconds

hbase(main):044:0> drop 'testtable'
0 row(s) in 0.1870 seconds

12 exists tablename –判断表是否存在

hbase(main):045:0> exists 'testtable'
Table testtable does not exist
0 row(s) in 0.0200 seconds

13 disable&alter tablename –删除表中一个列族

hbase(main):008:0> describe 'testtable'
DESCRIPTION                                                                                                                        ENABLED
 'testtable', {NAME => 'colfam1', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', VERSIONS => '1',  true
 COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => 'FOREVER', KEEP_DELETED_CELLS => 'false', BLOCKSIZE => '65536', IN_MEMORY => '
 false', BLOCKCACHE => 'true'}, {NAME => 'colfam2', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0',
  VERSIONS => '1', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => 'FOREVER', KEEP_DELETED_CELLS => 'false', BLOCKSIZE => '6553
 6', IN_MEMORY => 'false', BLOCKCACHE => 'true'}
1 row(s) in 0.0220 seconds

hbase(main):016:0* disable 'testtable'
0 row(s) in 1.2080 seconds

hbase(main):011:0> alter 'testtable',NAME=>'colfam1',METHOD=>'delete'
Updating all regions with the new schema...
0/1 regions updated.
1/1 regions updated.
Done.
0 row(s) in 2.1250 seconds

hbase(main):012:0> describe 'testtable'
DESCRIPTION                                                                                                                        ENABLED
 'testtable', {NAME => 'colfam2', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', VERSIONS => '1',  true
 COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => 'FOREVER', KEEP_DELETED_CELLS => 'false', BLOCKSIZE => '65536', IN_MEMORY => '
 false', BLOCKCACHE => 'true'}
1 row(s) in 0.0270 seconds
hbase(main):018:0> enable 'testtable'
0 row(s) in 0.1840 seconds

14 truncate tablename –清空整张表

hbase(main):005:0> truncate 'testtable'
Truncating 'testtable' table (it may take a while):
 - Disabling table...
 - Dropping table...
 - Creating table...
0 row(s) in 1.5070 seconds

15 deleteall tablename rowname –删除表中整行

hbase(main):010:0> scan 'testtable'
ROW                                                 COLUMN+CELL
 row1                                               column=colfam2:col2, timestamp=1479368929186, value=abc
 row1                                               column=colfam2:col3, timestamp=1479368937219, value=def
1 row(s) in 0.0080 seconds

hbase(main):012:0> deleteall 'testtable','row1'
0 row(s) in 0.0210 seconds

hbase(main):013:0> scan 'testtable'
ROW                                                 COLUMN+CELL
0 row(s) in 0.0040 seconds
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

数据源的港湾

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值