基本命令
DDL命令
DML命令
namespace命令
高级命令
hbase和HDFS类似也提供了shell端操作指令和java客户端API
进入大hbase的客户端 hbase shell
例举出系统中所支持的所有的指令 help
查看某个命令的详细使用说明 help "command"
[root@linux01 ~]# hbase shell
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/opt/apps/hbase-2.0.4/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/opt/apps/hadoop-2.8.5/share/hadoop/common/lib/slf4j-log4j12-1.7.10.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
2020-06-10 21:58:18,209 WARN [main] util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
HBase Shell
Use "help" to get list of supported commands.
Use "exit" to quit this interactive shell.
For Reference, please visit: http://hbase.apache.org/2.0/book.html#shell
Version 2.0.4, r205e39c5704bf38568b34926dde9f1ee76e6b5d0, Fri Dec 28 22:13:42 PST 2018
Took 0.0077 seconds
hbase(main):001:0>
hbase(main):001:0> help COMMAND GROUPS: Group name: ddl Group name: namespace Group name: dml Group name: tools Group name: replication Group name: snapshots Group name: configuration Group name: quotas Group name: security Group name: procedures Group name: visibility labels Group name: rsgroup SHELL USAGE: {'key1' => 'value1', 'key2' => 'value2', ...} and are opened and closed with curley-braces. Key/values are delimited by the If you are using binary keys or values and need to enter them in the shell, use hbase> get 't1', "key\x03\x3f\xcd" The HBase shell is the (J)Ruby IRB with the above HBase-specific commands added. |
1 processlist 当前正在处理的任务列表 比如 region的移动 拆分 合并
2 version 查看hbase的版本
2.0.4, r205e39c5704bf38568b34926dde9f1ee76e6b5d0, Fri Dec 28 22:13:42 PST 2018
3 whoami 当前用户
hbase(main):006:0> whoami
root (auth:SIMPLE)
groups: root
Took 0.0617 seconds
4 table_help 查看表的基本用法
create: 建表语法
1) create "a" , "cf1" 创建一个表名为a 列族为cf1的表
2) create "b" , "cf1" , "cf2" 创建一个表名为b 有cf1和cf2两个列族的表
3) create "tb_b" , {NAME => "cf1" , VERSIONS => 3 , TTL=>60*60*24*7} 建表的时候设置列族的属性 VERSIONS存储数据的版本数 TTL 列族中数据的过期时间
alert: 修改表结构
1) alter "tb_a" , NAME=>"cf1" , VERSIONS=>3 如果列族cf1存在 修改cf1的属性
2) alter "tb_a" , NAME=>"cf2" , VERSIONS=>3, TTL=>240 如果cf2列族不存在 添加列族 并且属性设置
3) alter "tb_a" , 'delete' => 'cf1' 删除列族cf1
describe: 查看表的结构信息的 等同于 desc 命令 "表名"
hbase(main):005:0> describe "tb_b"
Table tb_b is ENABLED
tb_b
COLUMN FAMILIES DESCRIPTION
{NAME => 'cf1', VERSIONS => '1', EVICT_BLOCKS_ON_CLOSE => 'false', NEW_VERSION_BEHAVIOR =>
'false', KEEP_DELETED_CELLS => 'FALSE', CACHE_DATA_ON_WRITE => 'false', DATA_BLOCK_ENCODI
NG => 'NONE', TTL => 'FOREVER', MIN_VERSIONS => '0', REPLICATION_SCOPE => '0', BLOOMFILTER
=> 'ROW', CACHE_INDEX_ON_WRITE => 'false', IN_MEMORY => 'false', CACHE_BLOOMS_ON_WRITE =>
'false', PREFETCH_BLOCKS_ON_OPEN => 'false', COMPRESSION => 'NONE', BLOCKCACHE => 'true',
BLOCKSIZE => '65536'}
{NAME => 'cf2', VERSIONS => '1', EVICT_BLOCKS_ON_CLOSE => 'false', NEW_VERSION_BEHAVIOR =>
'false', KEEP_DELETED_CELLS => 'FALSE', CACHE_DATA_ON_WRITE => 'false', DATA_BLOCK_ENCODI
NG => 'NONE', TTL => 'FOREVER', MIN_VERSIONS => '0', REPLICATION_SCOPE => '0', BLOOMFILTER
=> 'ROW', CACHE_INDEX_ON_WRITE => 'false', IN_MEMORY => 'false', CACHE_BLOOMS_ON_WRITE =>
'false', PREFETCH_BLOCKS_ON_OPEN => 'false', COMPRESSION => 'NONE', BLOCKCACHE => 'true',
BLOCKSIZE => '65536'}
disable: 禁用表 禁用以后无法对表中的数据进行操作 disable "tb_name"
hbase(main):007:0> disable "tb_a"
Took 1.5387 seconds
disable_all: 禁用多张表 disable_all "tb.*" 根据正则表达式的规则来匹配多张表禁用
hbase(main):008:0> disableall "tb.*"
NoMethodError: undefined method `disableall' for main:Object
Did you mean? disable_all
disable
hbase(main):009:0> disable_all "tb.*"
tb_a
tb_b
Disable the above 2 tables (y/n)?
y
2 tables successfully disabled
Took 3.1963 seconds
drop: 删除表 drop "tb_name" 首先将表禁用 否则无法删除
hbase(main):013:0> drop "tb_a"
ERROR: Table tb_a is enabled. Disable it first.
Drop the named table. Table must first be disabled:
hbase> drop 't1'
hbase> drop 'ns1:t1'
drop_all: 删除多张禁用的表 根据正则表达式[匹配多张表 , 表首先禁用
enable: 启动被禁用的表 enable "表名"
enable_all: enable_all "tb.*" 启用多张表 根据正则表达式匹配
hbase(main):012:0> enable_all "tb.*"
tb_a
tb_b
Enable the above 2 tables (y/n)?
y
2 tables successfully enabled
Took 3.2971 seconds
exists: exists 表名 判断表是否存在
hbase(main):014:0> exists "tb_b"
Table tb_b does exist
Took 0.0180 seconds
=> true
hbase(main):015:0> exists "tb_x"
Table tb_x does not exist
Took 0.0058 seconds
=> false
get_table: 获取表对象
hbase(main):017:0> b=get_table "tb_b"
Took 0.0003 seconds
=> Hbase::Table - tb_b
hbase(main):018:0> b.scan
ROW COLUMN+CELL
rk001 column=cf1:age, timestamp=1591778604652, value=33
rk001 column=cf1:cc, timestamp=1591779039918, value=\x00\x00\x00\x00\x00
\x00\x00\x15
rk001 column=cf1:name, timestamp=1591778604602, value=ls
rk001 column=cf2:job, timestamp=1591778604687, value=teacher
rk002 column=cf1:name, timestamp=1591778604736, value=ls2
rk003 column=cf1:name, timestamp=1591778604764, value=ls3
rk004 column=cf1:addr, timestamp=1591778605509, value=Beijing
rk004 column=cf1:sal, timestamp=1591778604797, value=10000
is_disabled: is_disabled "tb_name" 查看表是否在禁用状态 禁用状态(true)
is_enabled: is_enabled "tb_name" 查看表是否在启用用状态
hbase(main):020:0> is_enabled "tb_b"
true
Took 0.0189 seconds
=> true
list 查看默认名称空间下的所有的表
hbase> list 列出默认名称空间下 default中的所有的表
hbase> list 'abc.*' 列举出符合正则表达式规则的表
hbase> list 'ns:abc.*' 列出出指定名称空间下的表
hbase> list 'ns:.*'
list_regions, 查看一张表的所有的region信息
hbase(main):023:0> list_regions "tb_b"
SERVER_NAME | REGION_NAME | START_KEY | END_KEY | SIZE | REQ | LOCALITY |
--------------------------- | ----------------------------------------------------- | ---------- | ---------- | ----- | ----- | ---------- |
linux02,16020,1591783680684 | tb_b,,1591774845465.cedfe661eea04155f9fc0ccb707a96d1. | | | 0 | 4 | 1.0 |
1 rows
locate_region, 查看表的行建的region位置 hbase> locate_region 'tableName', 'key0'
hbase(main):024:0> locate_region "tb_b" , "rk004"
HOST REGION
linux02:16020 {ENCODED => cedfe661eea04155f9fc0ccb707a96d1, NAME => 'tb_b,,1591774845465.cedfe661eea04155f9fc0ccb707a96d1.'
, STARTKEY => '', ENDKEY => ''}
1 row(s)
Took 0.0020 seconds
=> #
show_filters 列出系统中支持的所有的过滤器
hbase(main):025:0> show_filters
DependentColumnFilter
KeyOnlyFilter
ColumnCountGetFilter
SingleColumnValueFilter
PrefixFilter
SingleColumnValueExcludeFilter
FirstKeyOnlyFilter
ColumnRangeFilter
ColumnValueFilter
TimestampsFilter
FamilyFilter
QualifierFilter
ColumnPrefixFilter
RowFilter
MultipleColumnPrefixFilter
InclusiveStopFilter
PageFilter
ValueFilter
ColumnPaginationFilter
Took 0.0187 seconds
=> #
Group name: dml
Commands: append, count, delete, deleteall, get, get_counter, get_splits, incr, put, scan, truncate, truncate_preserve
hbase> deleteall 'ns1:t1', 'r1'
hbase> deleteall 't1', 'r1'
hbase> deleteall 't1', 'r1', 'c1'
hbase> deleteall 't1', 'r1', 'c1', ts1
hbase> deleteall 't1', 'r1', 'c1', ts1, {VISIBILITY=>'PRIVATE|SECRET'}
ROWPREFIXFILTER can be used to delete row ranges
hbase> deleteall 't1', {ROWPREFIXFILTER => 'prefix'}
hbase> deleteall 't1', {ROWPREFIXFILTER => 'prefix'}, 'c1' //delete certain column family in the row ranges
hbase> deleteall 't1', {ROWPREFIXFILTER => 'prefix'}, 'c1', ts1
hbase> deleteall 't1', {ROWPREFIXFILTER => 'prefix'}, 'c1', ts1, {VISIBILITY=>'PRIVATE|SECRET'}
hbase> t.get 'r1'
hbase> t.get 'r1', {TIMERANGE => [ts1, ts2]}
hbase> t.get 'r1', {COLUMN => 'c1'}
hbase> t.get 'r1', {COLUMN => ['c1', 'c2', 'c3']}
hbase> t.get 'r1', {COLUMN => 'c1', TIMESTAMP => ts1}
hbase> t.get 'r1', {COLUMN => 'c1', TIMERANGE => [ts1, ts2], VERSIONS => 4}
hbase> t.get 'r1', {COLUMN => 'c1', TIMESTAMP => ts1, VERSIONS => 4}
hbase> t.get 'r1', {FILTER => "ValueFilter(=, 'binary:abc')"}
hbase> t.get 'r1', 'c1'
hbase> t.get 'r1', 'c1', 'c2'
hbase> t.get 'r1', ['c1', 'c2']
hbase> t.get 'r1', {CONSISTENCY => 'TIMELINE'}
hbase> t.get 'r1', {CONSISTENCY => 'TIMELINE', REGION_REPLICA_ID => 1}
base(main):218:0> incr "tb_b" , "rk001" , "cf1:cc" , 2
COUNTER VALUE = 21
hbase(main):219:0> get_counter "tb_b" , "rk001" , "cf1:cc"
COUNTER VALUE = 21
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'}
hbase(main):031:0> scan "tb_b"
ROW COLUMN+CELL
rk001 column=cf1:age, timestamp=1591778604652, value=33
rk001 column=cf1:cc, timestamp=1591779039918, value=\x00\x00\x00\x00\x00\x00\x00\x15
rk001 column=cf1:name, timestamp=1591778604602, value=ls
rk001 column=cf2:job, timestamp=1591778604687, value=teacher
rk002 column=cf1:name, timestamp=1591778604736, value=ls2
rk003 column=cf1:name, timestamp=1591778604764, value=ls3
rk004 column=cf1:addr, timestamp=1591778605509, value=Beijing
rk004 column=cf1:sal, timestamp=1591778604797, value=10000
4 row(s)
Group name: namespace
Commands: alter_namespace, create_namespace, describe_namespace, drop_namespace, list_namespace, list_namespace_tables