HBase 常用 Shell 命令
1.HBase 常用命令
启动 hdfs、zookeeper、hbase 服务
start-all.sh
zkServer.sh start
start-hbase.sh
# 使用 HBase 命令行
[hadoop@master hbase]$ hbase shell
HBase Shell
Use "help" to get list of supported commands.
Use "exit" to quit this interactive shell.
Version 1.7.1, r2d9273667e418e7023f9104a830cdcb8233b6f25, Fri Jul 16 00:20:26 PDT 2021
# 建立表 scores建立表 scores,两个列簇:grade 和 course
hbase(main):001:0> create 'scores','grade','course'
0 row(s) in 1.4570 seconds
=> Hbase::Table - scores
# 查看数据库状态
hbase(main):002:0> status
1 active master, 0 backup masters, 2 servers, 0 dead, 1.5000 average load
# 查看数据库版本
hbase(main):003:0> version
1.7.1, r2d9273667e418e7023f9104a830cdcb8233b6f25, Fri Jul 16 00:20:26 PDT 2021
# 查看表
hbase(main):004:0> list
TABLE
scores
1 row(s) in 0.0150 seconds
=> ["scores"]
# 插入记录 1:jie,grade: 143cloud
# hbase(main):005:0> put 'scores','jie','grade:','146cloud'
0 row(s) in 0.1020 seconds
# 插入记录 2:jie,course:math,86
hbase(main):006:0> put 'scores','jie','course:math','86'
0 row(s) in 0.0130 seconds
# 插入记录 3:jie,course:cloud,92
hbase(main):007:0> put 'scores','jie','course:cloud','92'
0 row(s) in 0.0080 seconds
# 插入记录 4:shi,grade:133soft
hbase(main):008:0> put 'scores','shi','grade:','133soft'
0 row(s) in 0.0080 seconds
# 插入记录 5:shi,grade:math,87
hbase(main):009:0> put 'scores','shi','course:math','87'
0 row(s) in 0.0100 seconds
# 插入记录 6:shi,grade:cloud,96
hbase(main):010:0> put 'scores','shi','course:cloud','96'
0 row(s) in 0.0090 seconds
# 读取 jie 的记录
hbase(main):011:0> get 'scores','jie'
COLUMN CELL
course:cloud timestamp=1650437146000, value=92
course:math timestamp=1650437136613, value=86
grade: timestamp=1650437121258, value=146cloud
1 row(s) in 0.0200 seconds
# 读取 jie 的班级
hbase(main):012:0> get 'scores','jie','grade'
COLUMN CELL
grade: timestamp=1650437121258, value=146cloud
1 row(s) in 0.0070 seconds
# 查看整个表记录
hbase(main):013:0> scan 'scores'
ROW COLUMN+CELL
jie column=course:cloud, timestamp=1650437146000, value=92
jie column=course:math, timestamp=1650437136613, value=86
jie column=grade:, timestamp=1650437121258, value=146cloud
shi column=course:cloud, timestamp=1650437171706, value=96
shi column=course:math, timestamp=1650437165264, value=87
shi column=grade:, timestamp=1650437157269, value=133soft
2 row(s) in 0.0150 seconds
# 按例查看表记录
hbase(main):014:0> scan 'scores',{COLUMNS=>'course'}
ROW COLUMN+CELL
jie column=course:cloud, timestamp=1650437146000, value=92
jie column=course:math, timestamp=1650437136613, value=86
shi column=course:cloud, timestamp=1650437171706, value=96
shi column=course:math, timestamp=1650437165264, value=87
2 row(s) in 0.0090 seconds
# 删除指定记录
hbase(main):015:0> delete 'scores','shi','grade'
0 row(s) in 0.0190 seconds
# 删除后,执行 scan 命令
hbase(main):016:0> scan 'scores'
ROW COLUMN+CELL
jie column=course:cloud, timestamp=1650437146000, value=92
jie column=course:math, timestamp=1650437136613, value=86
jie column=grade:, timestamp=1650437121258, value=146cloud
shi column=course:cloud, timestamp=1650437171706, value=96
shi column=course:math, timestamp=1650437165264, value=87
2 row(s) in 0.0170 seconds
# 增加新的列簇
hbase(main):017:0> alter 'scores',NAME=>'age'
Updating all regions with the new schema...
0/1 regions updated.
1/1 regions updated.
Done.
0 row(s) in 2.9240 seconds
# 查看表结构
hbase(main):018:0> describe 'scores'
Table scores is ENABLED
scores
COLUMN FAMILIES DESCRIPTION
{NAME => 'age', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DEL
ETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION =
> 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATIO
N_SCOPE => '0'}
{NAME => 'course', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_
DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSIO
N => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICA
TION_SCOPE => '0'}
{NAME => 'grade', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_D
ELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION
=> 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICAT
ION_SCOPE => '0'}
3 row(s) in 0.0200 seconds
# 删除列簇
hbase(main):019:0> alter 'scores',NAME=>'age',METHOD=>'delete'
Updating all regions with the new schema...
1/1 regions updated.
Done.
0 row(s) in 2.1330 seconds
# 删除表
hbase(main):020:0> disable 'scores'
0 row(s) in 2.2540 seconds
# 退出
hbase(main):021:0> quit
2.关闭 HBase
# 在 master 节点关闭 HBase。
[hadoop@master ~]$ stop-hbase.sh
# 在所有节点关闭 ZooKeeper。
[hadoop@master ~]$ zkServer.sh stop
[hadoop@slave1 ~]$ zkServer.sh stop
[hadoop@slave2 ~]$ zkServer.sh stop
# 在 master 节点关闭 Hadoop。
[hadoop@master ~]$ stop-all.sh