15分钟熟悉HBase Shell命令

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


名称


命令表达式


创建表


create ‘表名称‘, ‘列名称1‘,‘列名称2‘,‘列名称N‘


添加记录


put ‘表名称‘, ‘行名称‘, ‘列名称:‘, ‘值‘


查看记录


get ‘表名称‘, ‘行名称‘


查看表中的记录总数


count  ‘表名称‘


删除记录


delete  ‘表名‘ ,‘行名称‘ , ‘列名称‘


删除一张表


先要屏蔽该表,才能对该表进行删除,第一步 disable ‘表名称‘ 第二步  drop ‘表名称‘


查看所有记录


scan "表名称"


查看某个表某个列中所有数据


scan "表名称" , [‘列名称:‘]


更新记录


就是重写一遍进行覆盖

一、一般操作

1.查询服务器状态

hbase(main):011:0> status

1 active master, 0 backup masters, 1 servers, 0 dead, 4.0000 average load

2.查询版本

hbase(main):012:0> version

1.2.1, r8d8a7107dc4ccbf36a92f64675dc60392f85c015, Wed Mar 30 11:19:21 CDT 2016

二、DDL操作

1.创建一个表

hbase(main):013:0> create ‘table‘,‘column_famaly‘,‘column_famaly1‘,‘column_famaly2‘

0 row(s) in 94.9160 seconds

=> Hbase::Table - table

2.列出所有表

hbase(main):014:0> list

TABLE

stu

table

test

3 row(s) in 0.0570 seconds

=> ["stu", "table", "test"]

3.获得表的描述

hbase(main):015:0> describe ‘table‘

Table table is ENABLED

table

COLUMN FAMILIES DESCRIPTION

{NAME => ‘column_famaly‘, DATA_BLOCK_ENCODING => ‘NONE‘, BLOOMFILTER => ‘ROW‘, R

EPLICATION_SCOPE => ‘0‘, VERSIONS => ‘1‘, COMPRESSION => ‘NONE‘, MIN_VERSIONS =>

‘0‘, TTL => ‘FOREVER‘, KEEP_DELETED_CELLS => ‘FALSE‘, BLOCKSIZE => ‘65536‘, IN_

MEMORY => ‘false‘, BLOCKCACHE => ‘true‘}

{NAME => ‘column_famaly1‘, DATA_BLOCK_ENCODING => ‘NONE‘, BLOOMFILTER => ‘ROW‘,

REPLICATION_SCOPE => ‘0‘, VERSIONS => ‘1‘, COMPRESSION => ‘NONE‘, MIN_VERSIONS =

> ‘0‘, TTL => ‘FOREVER‘, KEEP_DELETED_CELLS => ‘FALSE‘, BLOCKSIZE => ‘65536‘, IN

_MEMORY => ‘false‘, BLOCKCACHE => ‘true‘}

{NAME => ‘column_famaly2‘, DATA_BLOCK_ENCODING => ‘NONE‘, BLOOMFILTER => ‘ROW‘,

REPLICATION_SCOPE => ‘0‘, VERSIONS => ‘1‘, COMPRESSION => ‘NONE‘, MIN_VERSIONS =

> ‘0‘, TTL => ‘FOREVER‘, KEEP_DELETED_CELLS => ‘FALSE‘, BLOCKSIZE => ‘65536‘, IN

_MEMORY => ‘false‘, BLOCKCACHE => ‘true‘}

3 row(s) in 0.0430 seconds

4.删除一个列族     alter,disable,enable

hbase(main):016:0> alter ‘table‘,{NAME=>‘column_famaly‘,METHOD=>‘delete‘}

Updating all regions with the new schema...

1/1 regions updated.

Done.

0 row(s) in 3.0220 seconds

hbase(main):018:0> describe ‘table‘

Table table is ENABLED

table

COLUMN FAMILIES DESCRIPTION

{NAME => ‘column_famaly1‘, DATA_BLOCK_ENCODING => ‘NONE‘, BLOOMFILTER => ‘ROW‘,

REPLICATION_SCOPE => ‘0‘, VERSIONS => ‘1‘, COMPRESSION => ‘NONE‘, MIN_VERSIONS =

> ‘0‘, TTL => ‘FOREVER‘, KEEP_DELETED_CELLS => ‘FALSE‘, BLOCKSIZE => ‘65536‘, IN

_MEMORY => ‘false‘, BLOCKCACHE => ‘true‘}

{NAME => ‘column_famaly2‘, DATA_BLOCK_ENCODING => ‘NONE‘, BLOOMFILTER => ‘ROW‘,

REPLICATION_SCOPE => ‘0‘, VERSIONS => ‘1‘, COMPRESSION => ‘NONE‘, MIN_VERSIONS =

> ‘0‘, TTL => ‘FOREVER‘, KEEP_DELETED_CELLS => ‘FALSE‘, BLOCKSIZE => ‘65536‘, IN

_MEMORY => ‘false‘, BLOCKCACHE => ‘true‘}

2 row(s) in 0.0520 seconds

5.drop一个表

hbase(main):019:0> drop ‘stu‘

ERROR: Table stu 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‘

报错了,因为要把表格设置为disable 

6.把表设置为disable

hbase(main):020:0> disable ‘stu‘

0 row(s) in 2.3150 seconds

再删除一个表

hbase(main):021:0> drop ‘stu‘

0 row(s) in 1.2820 seconds

列出所有表

hbase(main):022:0> list

TABLE

table

test

2 row(s) in 0.0240 seconds

=> ["table", "test"]

7.查询表是否存在

hbase(main):023:0> exists ‘stu‘

Table stu does not exist

0 row(s) in 0.0380 seconds

hbase(main):024:0> exists ‘table‘

Table table does exist

0 row(s) in 0.0280 seconds

8.判断表是否enable

hbase(main):025:0> is_enabled ‘table‘

true

0 row(s) in 0.0150 seconds

9.判断表是否disable

hbase(main):026:0> is_disabled ‘table‘

false

0 row(s) in 0.0140 seconds

把表设为disable

hbase(main):027:0> disable ‘table‘

0 row(s) in 33.2980 seconds

hbase(main):028:0> is_disabled ‘table‘

true

0 row(s) in 0.0140 seconds

三、DML操作

1.插入几条记录

hbase(main):029:0> put ‘table‘,‘id‘,‘column_famaly1:name‘,‘tanggao‘

ERROR: Failed 1 action: NotServingRegionException: 1 time,

Here is some help for this command:

Put a cell ‘value‘ at specified table/row/column and optionally

timestamp coordinates.  To put a cell value into table ‘ns1:t1‘ or ‘t1‘

at row ‘r1‘ under column ‘c1‘ marked with the time ‘ts1‘, do:

hbase> put ‘ns1:t1‘, ‘r1‘, ‘c1‘, ‘value‘

hbase> put ‘t1‘, ‘r1‘, ‘c1‘, ‘value‘

hbase> put ‘t1‘, ‘r1‘, ‘c1‘, ‘value‘, ts1

hbase> put ‘t1‘, ‘r1‘, ‘c1‘, ‘value‘, {ATTRIBUTES=>{‘mykey‘=>‘myvalue‘}}

hbase> put ‘t1‘, ‘r1‘, ‘c1‘, ‘value‘, ts1, {ATTRIBUTES=>{‘mykey‘=>‘myvalue‘}}

hbase> put ‘t1‘, ‘r1‘, ‘c1‘, ‘value‘, ts1, {VISIBILITY=>‘PRIVATE|SECRET‘}

The same commands also can be run on a table reference. Suppose you had a reference

t to table ‘t1‘, the corresponding command would be:

hbase> t.put ‘r1‘, ‘c1‘, ‘value‘, ts1, {ATTRIBUTES=>{‘mykey‘=>‘myvalue‘}}

报错了,因为要把表设为enable 

hbase(main):030:0> enable ‘table‘

0 row(s) in 1.3620 seconds

插入几条记录

hbase(main):031:0> put ‘table‘,‘id‘,‘column_famaly1:name‘,‘tanggao‘

0 row(s) in 0.0460 seconds

hbase(main):032:0> put ‘table‘,‘id‘,‘column_famaly1:age‘,‘20‘

0 row(s) in 0.0150 seconds

hbase(main):033:0> put ‘table‘,‘id‘,‘column_famaly1:sex‘,‘boy‘

0 row(s) in 0.0190 seconds

2.获取一条数据

获取一个id的所有数据

hbase(main):034:0> get ‘table‘,‘id‘

COLUMN                CELL

column_famaly1:age   timestamp=1463055735107, value=20

column_famaly1:name  timestamp=1463055709542, value=tanggao

column_famaly1:sex   timestamp=1463055753395, value=boy

3 row(s) in 0.3200 seconds

获取一个id,一个列族的所有数据

hbase(main):035:0> get ‘table‘,‘id‘,‘column_famaly1‘

COLUMN                CELL

column_famaly1:age   timestamp=1463055735107, value=20

column_famaly1:name  timestamp=1463055709542, value=tanggao

column_famaly1:sex   timestamp=1463055753395, value=boy

3 row(s) in 0.0270 seconds

获取一个id,一个列族中一个列的所有数据

hbase(main):036:0> get ‘table‘,‘id‘,‘column_famaly1:name‘

COLUMN                CELL

column_famaly1:name  timestamp=1463055709542, value=tanggao

1 row(s) in 0.0140 seconds

3.更新一条记录

把id的age修改为22

hbase(main):037:0> put ‘table‘,‘id‘,‘column_famaly1:age‘,‘22‘

0 row(s) in 0.0160 seconds

hbase(main):038:0> get ‘table‘,‘id‘,‘column_famaly1:age‘

COLUMN                CELL

column_famaly1:age   timestamp=1463055893492, value=22

1 row(s) in 0.0190 seconds

4.通过timestamp来获取两个版本的数据

hbase(main):039:0> get ‘table‘,‘id‘,{COLUMN=>‘column_famaly1:age‘,TIMESTAMP=>1463055735107}

COLUMN                CELL

column_famaly1:age   timestamp=1463055735107, value=20

1 row(s) in 0.0340 seconds

hbase(main):040:0> get ‘table‘,‘id‘,{COLUMN=>‘column_famaly1:age‘,TIMESTAMP=>1463055893492}

COLUMN                CELL

column_famaly1:age   timestamp=1463055893492, value=22

1 row(s) in 0.0140 seconds

5.全表扫描

hbase(main):041:0> scan ‘table‘

ROW                   COLUMN+CELL

id                   column=column_famaly1:age, timestamp=1463055893492, value=

22

id                   column=column_famaly1:name, timestamp=1463055709542, value

=tanggao

id                   column=column_famaly1:sex, timestamp=1463055753395, value=

boy

1 row(s) in 0.1520 seconds

6.删除行健为id的值的‘column_famaly1:age’字段

hbase(main):042:0> delete ‘table‘,‘id‘,‘column_famaly1:age‘

0 row(s) in 0.0200 seconds

hbase(main):043:0> get ‘table‘,‘id‘

COLUMN                CELL

column_famaly1:name  timestamp=1463055709542, value=tanggao

column_famaly1:sex   timestamp=1463055753395, value=boy

2 row(s) in 0.2430 seconds

7.删除整行

hbase(main):044:0> deleteall ‘table‘,‘id‘

0 row(s) in 0.0550 seconds

8.查询表中有多少行

hbase(main):045:0> count ‘table‘

0 row(s) in 0.0450 seconds

=> 0

再插入几条记录

hbase(main):046:0> put ‘table‘,‘id‘,‘column_famaly1:age‘,‘20‘

0 row(s) in 0.0160 seconds

hbase(main):047:0> put ‘table‘,‘id‘,‘column_famaly1:name‘,‘tanggao‘

0 row(s) in 0.0120 seconds

hbase(main):048:0> put ‘table‘,‘id‘,‘column_famaly2:name‘,‘tanggao2‘

0 row(s) in 0.0120 seconds

hbase(main):001:0> put ‘table‘,‘id‘,‘column_famaly2:age‘,‘22‘

0 row(s) in 0.4690 seconds

9.给‘id’这个行健增加‘column_famaly1:addr‘字段,并使用counter实现递增

hbase(main):002:0> incr ‘table‘,‘id‘,‘column_famaly1:addr‘

COUNTER VALUE = 1

0 row(s) in 0.0340 seconds

hbase(main):003:0> incr ‘table‘,‘id‘,‘column_famaly1:addr‘

COUNTER VALUE = 2

0 row(s) in 9.6250 seconds

hbase(main):004:0> get ‘table‘,‘id‘,‘column_famaly1:addr‘

COLUMN                CELL

column_famaly1:addr  timestamp=1463056705124, value=\x00\x00\x00\x00\x00\x00\x0

0\x02

1 row(s) in 0.3930 seconds

hbase(main):005:0> incr ‘table‘,‘id‘,‘column_famaly1:addr‘

COUNTER VALUE = 3

0 row(s) in 7.3880 seconds

10.获取当前count的值

hbase(main):006:0> get_counter ‘table‘,‘id‘,‘column_famaly1:addr‘

COUNTER VALUE = 3

11.将整张表清空

hbase(main):007:0> truncate ‘table‘

Truncating ‘table‘ table (it may take a while):

- Disabling table...

- Truncating table...

0 row(s) in 4.1510 seconds

hbase(main):008:0>

时间: 2024-10-29 19:12:04

15分钟熟悉HBase Shell命令的相关文章

HBASE SHELL 命令使用

HBASE SHELL命令的使用 在hbase shell客户端有许多的操作命令,今天回顾并且总结一二,希望和广大读者共同进步,并且悉心聆听你们的意见.在此的hbase版本是:HBase 1.2.0-cdh5.10.0. HBASE SHELL命令总结如下: hbase(main):001:0> help HBase Shell, version 1.2.0-cdh5.10.0, rUnknown, Fri Jan 20 12:13:18 PST 2017 Type 'help "COMM

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命令篇

最近在XX项目的测试过程中,接触到一些HBase的东西,希望能站在测试的角度,把过程记录下来,期望对快速了解它有点帮助.作为一个初次接触它的人来说,需要迫切掌握其中基本的概念,这里就不赘述了. HBase Shell是HBase提供的便捷的访问方式,首先你需要搭建HBase的环境,可以参考 http://hbase.apache.org/book/quickstart.html 和http://hbase.apache.org/book/notsoquick.html. 1.进入Hbase Sh

hbase shell命令使用

1.hbase shell命令行没有模糊查询,但有一个类似的模糊查询,过滤器 scan 'GPS:***SITE',{FILTER=>"PrefixFilter('122600410181181116142256')"} //这个使用的是前缀过滤 原文地址:https://www.cnblogs.com/kaiwen03/p/9969685.html

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

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

hadoop(九) - hbase shell命令及Java接口

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

Hadoop之——Hbase Shell命令

转载请注明出处:http://blog.csdn.net/l1028386804/article/details/46463503 HBASE Shell 进入Habse数据库终端:#$HBASE_HOME/bin/hbase shell 创建表 >create'users','user_id','address','info' 表users,有三个列族user_id,address,info 列出全部表 >list 得到表的描述 >describe 'users 创建表 >cre

HBase shell 命令入门

HBase Shell 名字可归类以下6部分: 1) General  HBase shell commands status Show cluster status. Can be 'summary', 'simple', or 'detailed'. The default is 'summary'. hbase> status hbase> status 'simple' hbase> status 'summary' hbase> status 'detailed' ver