Table of contents
(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
I. Introduction
This article mainly describes the basic operations of Hbase Shell, such as general operations, DDL operations, and DML operations, so that readers can have a basic understanding of Hbase Shell.
二、Hbase Shell
Start 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, general operation
status | Provide the status of Hbase, such as the number of servers |
---|---|
version | Provide the Hbase version being used |
whoami | provide information about the user |
table_help | Provides help for table reference commands |
获取所有表
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 command
DDL commands are mainly used for operations related to table management, such as creating tables, modifying tables, and deleting tables.
create | means to create a table |
---|---|
list | Indicates to list all tables of Hbase |
alter | means to change a table |
disable | Indicates that the table is disabled |
disable_all | Represents the deactivation of multiple tables through regular expressions |
is_disabled | Indicates whether the validation table is disabled |
enable | Indicates that a table is enabled |
enable_all | Indicates to start the specified table through a regular expression |
is_enabled | Indicates whether the validation table is enabled |
describe | Provide a table description |
exists | Indicates whether the verification table exists |
drop | Indicates to delete the table from Hbase |
drop_all | Indicates to discard the table matching regex given in the command |
3. DML command
scan | Indicates scanning and returning the information in the table |
---|---|
put | Indicates adding data information to the table |
get | Represents getting the content of a row or cell |
append | Indicates splicing a new value to the value of a cell |
delete | Used to denote deletion of a cell in a table |
deleteall | Indicates to delete all cells of a given row |
count | Represents a count and returns the number of rows in the table |
get_splits | Indicates the number of Regions in the obtained table, that is, returns the list of partitions |
truncate | Indicates disabling, dropping, and recreating a specified table |
truncate——preserve | Indicates that the data in the table is cleared, but the Region in the table is still retained |
4. DDL and DML operations
(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 '表名'