1. list命令

该命令列出hbase中所有的表

hbase(main):007:0* list
TABLE
SYSTEM:CATALOG
SYSTEM:FUNCTION
SYSTEM:MUTEX
SYSTEM:SEQUENCE
SYSTEM:STATS
iot_flow_cdr_201805
iot_msg_cdr_201805
iot_voice_cdr_201805
8 row(s) in 0.0200 seconds
=> ["SYSTEM:CATALOG", "SYSTEM:FUNCTION", "SYSTEM:MUTEX", "SYSTEM:SEQUENCE", "SYSTEM:STATS", "iot_flow_cdr_201805", "iot_msg_cdr_201805", "iot_voice_cdr_201805"]

2. desc(describe)命令

查看表的详细信息

hbase(main):012:0* desc 'iot_flow_cdr_201805'
Table iot_flow_cdr_201805 is ENABLED
iot_flow_cdr_201805, {TABLE_ATTRIBUTES => {coprocessor$1 => '|org.apache.phoenix.coprocessor.ScanRegionObserver|805306366|', coprocessor
$2 => '|org.apache.phoenix.coprocessor.UngroupedAggregateRegionObserver|805306366|', coprocessor$3 => '|org.apache.phoenix.coprocessor.G
roupedAggregateRegionObserver|805306366|', coprocessor$4 => '|org.apache.phoenix.coprocessor.ServerCachingEndpointImpl|805306366|'}
COLUMN FAMILIES DESCRIPTION
{NAME => 'info', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', VERSIONS => '1', COMPRESSION => 'SNAPPY'
, TTL => 'FOREVER', MIN_VERSIONS => '0', KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'
}
1 row(s) in 0.0780 seconds

其中:NANE指列簇名,VERSIONS指版本号,COMPRESSION指压缩算法,TTL指生存时间(过期时间)

3. create命令

create创建表,help 'create'查看该命令的用法

hbase(main):015:0* help 'create'
Creates a table. Pass a table name, and a set of column family
specifications (at least one), and, optionally, table configuration.
Column specification can be a simple string (name), or a dictionary
(dictionaries are described below in main help output), necessarily
including NAME attribute.
Examples: Create a table with namespace=ns1 and table qualifier=t1
hbase> create 'ns1:t1', {NAME => 'f1', VERSIONS => 5} Create a table with namespace=default and table qualifier=t1
hbase> create 't1', {NAME => 'f1'}, {NAME => 'f2'}, {NAME => 'f3'}
hbase> # The above in shorthand would be the following:
hbase> create 't1', 'f1', 'f2', 'f3'
hbase> create 't1', {NAME => 'f1', VERSIONS => 1, TTL => 2592000, BLOCKCACHE => true}
hbase> create 't1', {NAME => 'f1', CONFIGURATION => {'hbase.hstore.blockingStoreFiles' => '10'}}

部分参数说明:

NAME:指定列簇名

VERSION:指定版本号(默认为1)

TTL:指定表超时时间,超过该时间的row会被删除

COMPRESSION:指定压缩方式,hbase支持的压缩算法有gzip、lzo、snappy/Zippy

这里我创建一个test表,包含一个列簇info,压缩方式为snappy

hbase(main):020:0* create 'test',{NAME=>'info','COMPRESSION'=>'snappy'}
0 row(s) in 2.3540 seconds => Hbase::Table - test
hbase(main):021:0> desc 'test'
Table test is ENABLED
test
COLUMN FAMILIES DESCRIPTION
{NAME => 'info', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', VERSIONS => '1', COMPRESSION => 'SNAPPY'
, MIN_VERSIONS => '0', TTL => 'FOREVER', KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'
}
1 row(s) in 0.0480 seconds

4. 插入数据put

使用help ‘put’命令查看帮助

hbase(main):025:0* help 'put'
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'}

参数说明:

t1:指定表名

r1:指定rowkey值

c1:指定列名,注意指定列名时,要带上列簇,格式为 列簇名:列名

value:指定列值

现在,我往test表中插入几条数据

hbase(main):028:0* put 'test','1','info:name','tom'
0 row(s) in 0.4460 seconds hbase(main):029:0> put 'test','1','info:age','18'
0 row(s) in 0.0140 seconds

5.获取数据get

help 'get'查看该命令的用法

hbase(main):031:0* help 'get'
Get row or cell contents; pass table name, row, and optionally
a dictionary of column(s), timestamp, timerange and versions. Examples: hbase> get 'ns1:t1', 'r1'
hbase> get 't1', 'r1'
hbase> get 't1', 'r1', {TIMERANGE => [ts1, ts2]}
hbase> get 't1', 'r1', {COLUMN => 'c1'}
hbase> get 't1', 'r1', {COLUMN => ['c1', 'c2', 'c3']}
hbase> get 't1', 'r1', {COLUMN => 'c1', TIMESTAMP => ts1}
hbase> get 't1', 'r1', {COLUMN => 'c1', TIMERANGE => [ts1, ts2], VERSIONS => 4}
hbase> get 't1', 'r1', {COLUMN => 'c1', TIMESTAMP => ts1, VERSIONS => 4}
hbase> get 't1', 'r1', {FILTER => "ValueFilter(=, 'binary:abc')"}
hbase> get 't1', 'r1', 'c1'
hbase> get 't1', 'r1', 'c1', 'c2'
hbase> get 't1', 'r1', ['c1', 'c2']
hbase> get 't1', 'r1', {COLUMN => 'c1', ATTRIBUTES => {'mykey'=>'myvalue'}}
hbase> get 't1', 'r1', {COLUMN => 'c1', AUTHORIZATIONS => ['PRIVATE','SECRET']}
hbase> get 't1', 'r1', {CONSISTENCY => 'TIMELINE'}
hbase> get 't1', 'r1', {CONSISTENCY => 'TIMELINE', REGION_REPLICA_ID => 1}

参数说明:

t1:指定表名

r1:指定rowkey查询

c1:指定列名查询

现在我们查询刚才test表中的数据

#指定rowkey查询
hbase(main):035:0* get 'test','1'
COLUMN CELL
info:age timestamp=1526396011498, value=18
info:name timestamp=1526396001809, value=tom
2 row(s) in 0.0580 seconds #指定rowkey和列名查询,注意指定列名时要以列簇名为前缀
hbase(main):037:0* get 'test','1',{COLUMN=> 'info:name'}
COLUMN CELL
info:name timestamp=1526396001809, value=tom
1 row(s) in 0.0280 seconds #指定rowkey和列簇查询
hbase(main):042:0* get 'test','1','info'
COLUMN CELL
info:age timestamp=1526396011498, value=18
info:name timestamp=1526396001809, value=tom
2 row(s) in 0.0170 seconds

6. 扫描表scan

scan命令是用来查询hbase表数据,可以全表扫描列出所有数据,也可以指定扫描条件过滤数据,该命令的用法很丰富,过滤条件很多。这里简单列举两个个

#全表扫描
hbase(main):044:0* scan 'test'
ROW COLUMN+CELL
1 column=info:age, timestamp=1526396011498, value=18
1 column=info:name, timestamp=1526396001809, value=tom
1 row(s) in 0.0610 seconds #先插入两条数据
hbase(main):045:0> put 'test','2','info:name','jerry'
0 row(s) in 0.0190 seconds hbase(main):046:0> put 'test','11','info:name','mary'
0 row(s) in 0.0160 seconds #根据rowkey前缀,过滤扫描
hbase(main):047:0> scan 'test',{ROWPREFIXFILTER => '1'}
ROW COLUMN+CELL
1 column=info:age, timestamp=1526396011498, value=18
1 column=info:name, timestamp=1526396001809, value=tom
11 column=info:name, timestamp=1526396516873, value=mary
2 row(s) in 0.0310 seconds

7. 删除命令delete

该命令只能删除某个rowkey的某一列数据,不能整行删除

#比如我删除rowkey为1的info:age这列数据
hbase(main):049:0* delete 'test','1','info:age'
0 row(s) in 0.0590 seconds hbase(main):050:0> get 'test','1'
COLUMN CELL
info:name timestamp=1526396001809, value=tom
1 row(s) in 0.0150 seconds

8. deleteall命令

这个命令和delete相比,它可以直接删除删除一行数据,而delete指定删除指定列数据,

比如删除test表中rowkey为2的整行数据

hbase(main):054:0* deleteall 'test','2'
0 row(s) in 0.0140 seconds hbase(main):055:0> scan 'test'
ROW COLUMN+CELL
1 column=info:name, timestamp=1526396001809, value=tom
11 column=info:name, timestamp=1526396516873, value=mary
2 row(s) in 0.0190 seconds

9. disable、enable、is_enabled和exists命令

disable使某张表处于不可用状态,enable则是恢复表为正常状态,is_enabled是判断表的状态,exists是判断表是否存在

hbase(main):058:0* disable 'test'
0 row(s) in 2.3280 seconds hbase(main):059:0> is_enabled 'test'
false
0 row(s) in 0.0630 seconds hbase(main):061:0> enable 'test'
0 row(s) in 1.2760 seconds hbase(main):063:0> exists 'test'
Table test does exist
0 row(s) in 0.0200 seconds

10. 清空表truncate和删除表drop

truncate命令清空表数据,drop删除表,注意删除表之前,需要disable表

hbase(main):066:0* truncate 'test'
Truncating 'test' table (it may take a while):
- Disabling table...
- Truncating table...
0 row(s) in 3.6610 seconds hbase(main):067:0> scan 'test'
ROW COLUMN+CELL
0 row(s) in 0.3420 seconds #删除表前,先disable该表
hbase(main):068:0> disable 'test'
0 row(s) in 2.2660 seconds hbase(main):069:0> drop 'test'
0 row(s) in 1.2660 seconds

11. move命令

该命令用于region的转移,当你发现多个regionserver间的region分配不均时,可以使用该命令转移region来进行平衡

12. balance_switch命令

该命令用于开启或关闭regionserver的自动平衡功能,balance_switch true开启,balance_switch false关闭,开启后,regionserver之间的region会自动进行平衡。balance_switch status可查看当前balance状态。

HBase shell的使用记录的更多相关文章

  1. Hbase记录-Hbase shell使用命令

    1.进入hbase shell  执行./bin/hbase shell 2.进入后,help  帮助信息,如可以使用help 'create' 3.创建表:create 'test','cf'  表 ...

  2. Hbase记录-shell脚本嵌入hbase shell命令

    第一种方式:hbase shell test.txt test.txt:list 第二种方式:<<EOF重定向输入 我们经常在shell脚本程序中用<<EOF重定向输入,将我们 ...

  3. Hbase记录-Hbase shell使用

    HBase Shell HBase包含可以与HBase进行通信的Shell. HBase使用Hadoop文件系统来存储数据.它拥有一个主服务器和区域服务器.数据存储将在区域(表)的形式.这些区域被分割 ...

  4. Linux巩固记录(8) Hbase shell 基本使用

    继续前几篇内容,讲解hbase基本使用 1.进入hbase shell: hbase有很多种操作方式,比如shell,java客户端,webUI等,可以直接输入hbase进行提示 [root@mast ...

  5. HBase Shell操作

    Hbase 是一个分布式的.面向列的开源数据库,其实现是建立在google 的bigTable 理论之上,并基于hadoop HDFS文件系统.     Hbase不同于一般的关系型数据库(RDBMS ...

  6. HBase Shell 常用命令及例子

    下面我们看看HBase Shell的一些基本操作命令,我列出了几个常用的HBase Shell命令,如下: 名称 命令表达式 创建表 create '表名称', '列名称1','列名称2','列名称N ...

  7. hbase shell command

    进入hbase shell console $HBASE_HOME/bin/hbase shell 如果有kerberos认证,需要事先使用相应的keytab进行一下认证(使用kinit命令),认证成 ...

  8. hbase shell 基本命令总结

    访问hbase,以及操作hbase,命令不用使用分号hbase shell 进入hbase list 查看表hbase shell -d hbase(main):024:0> scan '.ME ...

  9. hbase shell 常用命令

    进入hbase shell console$HBASE_HOME/bin/hbase shell如果有kerberos认证,需要事先使用相应的keytab进行一下认证(使用kinit命令),认证成功之 ...

随机推荐

  1. 简单快速搭建钓鱼wifi

    前言 钓鱼wifi是很久的话题了,但是传统的方法可能比较麻烦需要手动配置dhcp,dns,网卡,流量转发,比较麻烦,而且还有根据每次的网络环境需要重新的配置,这里介绍用WIFIpumpkin3工具简单 ...

  2. Virtuoso 中如何优化 Library Manager 的显示

    https://www.cnblogs.com/yeungchie/ 主要从 cds.lib 文件去入手. 假设现在想把 Virtuoso 预装的库整理到 preload 分类(库)中. 首先创建一个 ...

  3. 【服务器部署】Django+宝塔+Nginx_uwsgi部署

    :CentOS安装脚本: yum install -y wget && wget -O install.sh http://download.bt.cn/install/install ...

  4. 正则表达式截取xml

    $str = '<Ips><GateWayRsp><head><ReferenceID>123</ReferenceID><RspCo ...

  5. python中a, b = a, a + b这条语句是如何执行的?

    a,b=b,a+b,这条语句在"理解"上还是与C语言有些差别的.在Python中,可以做下面的方式理解:首先,把等号右边的算式分别算完再说,然后按照一一对应的关系把值赋给等号左边的 ...

  6. python 列表和字典的引用与复制(copy)

    列表或字典的引用: 引用针对变量的时候,传递引用后,对引用后的对象的值进行改变是不会影响到原值的:而列表不一样如: spam =42 cheese = spam spam =100 print(spa ...

  7. 牛客网数据库SQL实战解析(51-61题)

    牛客网SQL刷题地址: https://www.nowcoder.com/ta/sql?page=0 牛客网数据库SQL实战解析(01-10题): https://blog.csdn.net/u010 ...

  8. make编译出错 usr/bin/ld: /data/app/openssl/lib/libcrypto.a(ecs_asn1.o): relocation R_X86_64_PC32 against symbol `ECDSA_SIG_it' can not be used when making a shared object; recompile with -fPIC

    当make编译出现错误 usr/bin/ld: /data/app/openssl/lib/libcrypto.a(ecs_asn1.o): relocation R_X86_64_PC32 agai ...

  9. 我是怎样刚拿饿了么P7 offer,然后途虎一轮游的

    今年初拿了个饿了么P7的offer,于此同时大家顺便看看我怎么途虎一轮游的.废话不多说,直接上题吧. 一面 首先上来就是自我介绍,简单的说下自己的项目经验,涉及的技术栈之类的. 然后每一轮必问的问题来 ...

  10. Min Cost Climbing Stairs [746]

    Min Cost Climbing Stairs [746] 题目描述 简单来说就是:要跳过当前楼梯需要花费当前楼梯所代表的价值cost[i], 花费cost[i]之后,可以选择跳一阶或者两阶楼梯,以 ...