目录
(4)disable&&disable_all&&is_disabled
(5)enable&&enable_all&&is_enabled
(6)describe&&exists&&drop&&drop_all
(10)count&&get_splits&&truncate&&truncate_preserver
一、前言
本篇文章主要讲述Hbase Shell的基本操作,如通用操作、DDL操作、DML操作,使读者能够对于Hbase Shell有基本的认识。
二、Hbase Shell
启动Hbase Shell
hbase shell
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/export/servers/hbase/lib/client-facing-thirdparty/slf4j-reload4j-1.7.33.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/export/servers/hadoop-2.10.1/share/hadoop/common/lib/slf4j-log4j12-1.7.25.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.Reload4jLoggerFactory]
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.4.11, r7e672a0da0586e6b7449310815182695bc6ae193, Tue Mar 15 10:31:00 PDT 2022
Took 0.0015 seconds
hbase:001:0>
1、通用操作
status | 提供Hbase的状态,如服务器数量 |
---|---|
version | 提供正在使用的Hbase版本 |
whoami | 提供有关用户信息 |
table_help | 为表引用命令提供帮助 |
获取所有表
hbase:001:0> list
TABLE
Student
Taxi_Data
stu
student_mr
teacher
testtable
6 row(s)
Took 0.4684 seconds
=> ["Student", "Taxi_Data", "stu", "student_mr", "teacher", "testtable"]
退出
hbase:002:0> exit
查看Hbase集群状态,可在后面加上simple、summary、detailed参数。
hbase:002:0> status
1 active master, 2 backup masters, 3 servers, 0 dead, 2.6667 average load
Took 0.1330 seconds
status 'simple'
status 'summary'
status 'detailed'
查看Hbase版本
hbase:006:0> version
2.4.11, r7e672a0da0586e6b7449310815182695bc6ae193, Tue Mar 15 10:31:00 PDT 2022
Took 0.0007 seconds
查看Hbase用户信息
hbase:007:0> whoami
root (auth:SIMPLE)
groups: root
Took 0.0435 seconds
2、DDL命令
DDL命令主要用于管理表相关的操作,例如创建表、修改表、删除表等。
create | 表示创建一个表 |
---|---|
list | 表示列出Hbase的所有表 |
alter | 表示改变一个表 |
disable | 表示禁用表 |
disable_all | 表示通过正则表达式来停用多个表 |
is_disabled | 表示验证表是否被禁用 |
enable | 表示启用一个表 |
enable_all | 表示通过正则表达式来启动指定表 |
is_enabled | 表示验证表是否已启用 |
describe | 提供一个表的描述 |
exists | 表示验证表是否存在 |
drop | 表示从Hbase中删除表 |
drop_all | 表示丢弃在命令中给出匹配regex的表 |
3、DML命令
scan | 表示扫描并返回表中的信息 |
---|---|
put | 表示向表中添加数据信息 |
get | 表示获取行或单元格的内容 |
append | 表示给某个单元格的值拼接上新的值 |
delete | 用于表示删除表中的单元格 |
deleteall | 表示删除给定行的所有单元格 |
count | 表示计数并返回表中的行的数目 |
get_splits | 表示获取表中对于的Region个数,即返回分区列表 |
truncate | 表示禁用、删除和重新创建一个指定的表 |
truncate——preserve | 表示清空表内数据,但是还会保留表中对于的Region |
4、DDL与DML操作
(1)create
create '表名','列族名1','列族名2',......
hbase:008:0> create 'abc','cf1'
Created table abc
Took 4.2834 seconds
=> Hbase::Table - abc
create '表名', {NAME => '列族名1', 属性名 => '属性值'},{NAME => '列族名2', 属性名 => '属性值'}
创建一个名为abcd的表,共有两个列族,列族info和列族other,其中info列族有两列,为num和name;other列族有一列,为class
hbase:009:0> create 'abcd',{NAME => 'info', COLUMNS => 'num,name'},{NAME => 'other', COLUMNS => 'class'}
Unknown argument ignored for column family info: COLUMNS
Unknown argument ignored for column family other: COLUMNS
Created table abcd
Took 1.3029 seconds
=> Hbase::Table - abcd
(2)list
list
list '通配符'
查询所有表
hbase:010:0> list
TABLE
Student
Taxi_Data
abc
abcd
stu
student_mr
teacher
testtable
8 row(s)
Took 0.0166 seconds
=> ["Student", "Taxi_Data", "abc", "abcd", "stu", "student_mr", "teacher", "testtable"]
查询首字母为t的表
hbase:011:0> list 't.*'
TABLE
teacher
testtable
2 row(s)
Took 0.0159 seconds
=> ["teacher", "testtable"]
(3)alter
建立或修改表、列族,即传入的列族名不存在,则为新建列族;若传入的列族存在,则为对已存在的列族修改其属性。
alter '表名', NAME => '列族名', 属性名1=> '属性值1', 属性名2=> '属性值2'
修改表abcd,新增一个列族,名为extesion,包含一个列为major
hbase:012:0> alter 'abcd', NAME => 'extesion', COLUMNS =>'major'
Unknown argument ignored for column family extesion: COLUMNS
Updating all regions with the new schema...
1/1 regions updated.
Done.
Took 2.4727 seconds
建立或多个列族
alter '表名', {NAME => '列族名1', 属性名1=> '属性值1', 属性名2=> '属性值2',...},{NAME => '列族名2', 属性名1=> '属性值1', 属性名2=> '属性值2',...}
alter 'abcd',{NAME => 'cf1',VERSION =>3},{NAME => 'cf2',VERSION =>4}
删除列族
alter '表名','delete'=>'列族名'
alter 'teacher','delete'=>'cf1'
(4)disable&&disable_all&&is_disabled
禁用单个表
disable '表名'
hbase:001:0> disable 'abcd'
Took 1.2734 seconds
hbase:002:0> scan 'abcd'
ROW COLUMN+CELL
ERROR: Table abcd is disabled!
Took 0.8663 seconds
禁用多个表
disable_all '正则表达式'
disable_all 'a.*'
查询表是否被禁用
is_disabled '表名'
is_disabled 'abcd'
(5)enable&&enable_all&&is_enabled
启用表
enable '表名'
enable 'abcd'
启用多个表
enable_all '正则表达式'
enable_all 'a.*'
查看表是否被启用
is_enabled '表名'
is_enabled 'abcd'
(6)describe&&exists&&drop&&drop_all
输出表的描述信息
describe '表名'
desc '表名'
判断表是否存在
exists '表名'
exists 'abcd'
删除表
这里需要注意,在删除表时,需要先禁用表,再删除
drop '表名'
disable 'abcd'
drop 'abcd'
删除多个表
drop_all '表名'
disabled_all 'a.*'
drop_all 'a.*'
(7)put&&append
插入数据
put '表名', '行键', '列名', '值'
put 'abcd', 'row1', 'extesion:major', 'IOT'
拼接数据
append '表名', '行键', '列名', '值'
(8) scan&&get
scan与get的区别在于,前者可获取多条数据,后者只能获取单条数据
scan '表名'
get '表名', '行键'
(9)delete&&deleteall
删除某列数据
delete '表名', '行键', '列名'
delete '表名', '行键', '列名',时间戳
delete 'abcd', 'row1', 'info:name'
删除整行数据,或单列数据
deleteall '表名', '行键'
deleteall '表名', '行键', '列名'
deleteall '表名', '行键', '列名',时间戳
(10)count&&get_splits&&truncate&&truncate_preserver
计算表的行的数量
count '表名'
获取表所对应的Region个数
get_splits '表名'
先删除表并重新创建一个表
truncate '表名'
清空表内的数据,保留对应的Region
truncate_preserve '表名'