Shell常用命令。
1.进入与退出hbase shell命令行窗口
[root@repo ~]# hbase shell
hbase(main):001:0>
hbase(main):001:0> exit
[root@repo ~]#
2.查看某个命令的详细使用
help 'create'
3.general组中命令
--(1) 查看集群状态
hbase(main):078:0> status
1 active master, 0 backup masters, 1 servers, 0 dead, 3.0000 average load
--(2) 查看集群版本
hbase(main):079:0> version
1.2.6, rUnknown, Mon May 29 02:25:32 CDT 2017
--(3) 当前登录用户角色信息
hbase(main):080:0> whoami
root (auth:SIMPLE)
groups: root
--(4) 查看对某张表进行操作的基本命令
hbase(main):081:0> table_help
4.ddl组中命令
(1) 查看数据库中有哪些表
hbase(main):004:0> list
TABLE
FileTable
1 row(s) in 0.2010 seconds
=> ["FileTable"]
(2) 建表
# create '表名', '列族1', '列族2'...
hbase(main):002:0> create 'person', 'name', 'age'
# 等价于
hbase(main):002:0> create 'person',{NAME=>'name' },{NAME=>'age'}
# 建表时可以指定表属性信息
hbase(main):005:0> create 'user_info',{NAME=>'base_info',VERSIONS=>3 },{NAME=>'extra_info',IN_MEMORY=>'true'}
(3) 查看表属性信息
hbase(main):006:0> desc 'person'
Table person is ENABLED
person
COLUMN FAMILIES DESCRIPTION
{NAME => 'age', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => '
NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}
{NAME => 'name', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION =>
'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}
2 row(s) in 0.1690 seconds
(4) alter 修改表
# 添加一个列族
alter 'person', 'gender'
# 删除列族
alter 'person', {NAME => 'age', METHOD => 'delete'}
或者
hbase(main):004:0> alter 'person','delete'=>'age'
Updating all regions with the new schema...
1/1 regions updated.
Done.
0 row(s) in 2.4350 seconds
(5) 判断表是否存在
hbase(main):011:0> exists 'FileTable'
Table FileTable does exist
0 row(s) in 0.0380 seconds
(6) 禁用表与启用表
hbase(main):012:0> disable 'FileTable'
0 row(s) in 2.2970 seconds
hbase(main):013:0> is_disabled 'FileTable'
true
0 row(s) in 0.0200 seconds
hbase(main):014:0> enable 'FileTable'
0 row(s) in 1.3110 seconds
hbase(main):015:0> is_enabled 'FileTable'
true
0 row(s) in 0.0230 seconds
(7) 删除表
hbase(main):016:0> disable 'FileTable'
0 row(s) in 2.2860 seconds
hbase(main):018:0> drop 'FileTable'
0 row(s) in 1.2620 seconds
5.dml组中命令
(1) 插入数据
hbase(main):022:0> put 'person','s001','name:zhangsan','gender:男'
0 row(s) in 0.1020 seconds
# 查询表中有多少行
hbase(main):035:0> count 'person'
1 row(s) in 0.0470 seconds
=> 1
(2) 查询数据
#根据ID查询单个记录
hbase(main):023:0> get 'person','s001'
COLUMN CELL
name:zhangsan timestamp=1682040628187, value=gender:\xE7\x94\xB7
1 row(s) in 0.0270 seconds
#查询整表数据
hbase(main):028:0> scan 'person'
ROW COLUMN+CELL
s001 column=name:zhangsan, timestamp=1682040628187, value=gender:\xE7\x94\xB7
s002 column=name:lisi, timestamp=1682040984888, value=gender\xEF\xBC\x9An\xE5\xA5\xB3\xE2\x80\x98\x0A
2 row(s) in 0.0470 seconds
(3) 删除数据
# 删除整行的值
hbase(main):033:0> deleteall 'person','s001'
0 row(s) in 0.0430 seconds
小技巧: hbase shell命令行下,如果输入错误,想回退,发现回退命令不生效。我们可以按住ctrl,然后再按backspace/delete键,就可以回退。