#引号不能省略
help 'status'
1. status
hbase(main):002:0> status
1 active master, 0 backup masters, 3 servers, 0 dead, 1.0000 average load
version
hbase(main):003:0> version
1.3.1, r930b9a55528fe45d8edce7af42fef2d35e77677a, Thu Apr 6 19:36:54 PDT 2017
HBase命名空间:它是系统级别的命名空间,通常包含HBase自身的元数据和系统表。这些系统表存储了HBase集群的结构和配置信息,对于HBase的运行和管理至关重要。例如,HBase中的hbase:meta表就位于这个命名空间中,它保存了所有用户表的元数据,包括表名、列族信息以及每个表的RegionServer位置等。
default命名空间:这是为用户创建的默认命名空间。当用户在HBase中创建表而没有指定命名空间时,表会被创建在default命名空间中。这个命名空间是为用户自定义表设计的,用户可以在这个命名空间中创建、管理和查询自己的数据表。
NAMESPACE 是一个用于组织和管理表的高级特性。
list_namespace
hbase(main):001:0> list_namespace
NAMESPACE
default
hbase
2 row(s) in 0.1380 seconds
list_namespace_tables'hbase'
hbase(main):003:0> list_namespace_tables'hbase'
TABLE
meta
namespace
2 row(s) in 0.0190 seconds
命令格式:create ‘空间名’
create_namespace 'my_ns1'
hbase(main):005:0> create_namespace 'my_ns1'
0 row(s) in 0.8950 seconds
describe_namespace 'my_ns1'
hbase(main):007:0> describe_namespace 'my_ns1'
DESCRIPTION
{NAME => 'my_ns1'}
1 row(s) in 0.0140 seconds
drop_namespace 'my_ns1'
hbase(main):008:0> drop_namespace 'my_ns1'
0 row(s) in 0.8860 seconds
命令格式:create ‘表名’,‘列名1’,‘列名2…
create 'scores','student','courses'
hbase(main):004:0> create 'scores','student','courses'
0 row(s) in 1.2310 seconds
=> Hbase::Table - scores
describe ‘scores'
hbase(main):001:0> describe 'scores'
Table scores is ENABLED
scores
COLUMN FAMILIES DESCRIPTION
{NAME => 'courses', 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 => 'student', 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'}
exists
增加department列族
disable 'scores'#关闭
alter 'scores',{NAME => 'department',VERSIONS => 3}
enable 'scores'#启动
hbase(main):002:0> disable 'scores'
0 row(s) in 2.2620 seconds
hbase(main):003:0> alter 'scores',{NAME => 'department',VERSIONS => 3}
Updating all regions with the new schema...
1/1 regions updated.
Done.
0 row(s) in 1.8990 seconds
hbase(main):004:0> enable 'scores'
disable 'scores'#关闭
alter 'scores',{NAME => 'department',METHOD => 'delete'}
enable 'scores'#启动
hbase(main):005:0> disable 'scores'
0 row(s) in 2.2510 seconds
hbase(main):006:0> alter 'scores',{NAME => 'department',METHOD => 'delete'}
Updating all regions with the new schema...
1/1 regions updated.
Done.
0 row(s) in 2.1410 seconds
hbase(main):007:0> enable 'scores'
0 row(s) in 1.2380 seconds
exists 'scores'
hbase(main):001:0> exists 'scores'
Table scores does exist
0 row(s) in 0.1580 seconds
is_enabled 'scores'
is_disabled 'scores'
hbase(main):002:0> is_enabled 'scores'
true
0 row(s) in 0.0170 seconds
hbase(main):003:0> is_disabled 'scores'
false
0 row(s) in 0.0170 seconds
disable 'scores'
drop 'scores'
exists 'scores'
hbase(main):004:0> disable 'scores'
0 row(s) in 2.2870 seconds
hbase(main):005:0> drop 'scores'
0 row(s) in 1.2570 seconds
Table scores does not exist
0 row(s) in 0.1960 seconds
格式:put ‘表名’, ‘行键’, ‘列族:列名’, ‘值’
put 'scores','1','student:name','xiaoming'
put 'scores','1','courses:python','90'
put 'scores','1','courses:java','90'
put 'scores','2','student:name','xiaokai'
put 'scores','2','courses:python','80'
put 'scores','2','courses:java','80'
put 'scores','3','student:name','xiaohong'
put 'scores','3','courses:python','95'
put 'scores','3','courses:java','95'
hbase(main):001:0> put 'scores','1','student:name','xiaoming'
0 row(s) in 0.2580 seconds
hbase(main):002:0> put 'scores','1','courses:python','90'
0 row(s) in 0.0200 seconds
hbase(main):003:0> put 'scores','1','courses:java','90'
0 row(s) in 0.0140 seconds
hbase(main):004:0>
get 'scores','1'
get 'scores','1','courses'
get 'scores','1','courses:python'
hbase(main):001:0> get 'scores','1'
COLUMN CELL
courses:java timestamp=1707682372256, value=90
courses:python timestamp=1707682367650, value=90
student:name timestamp=1707682361045, value=xiaoming
1 row(s) in 0.1960 seconds
hbase(main):002:0> get 'scores','1','courses'
COLUMN CELL
courses:java timestamp=1707682372256, value=90
courses:python timestamp=1707682367650, value=90
1 row(s) in 0.0190 seconds
hbase(main):003:0> get 'scores','1','courses:python'
COLUMN CELL
courses:python timestamp=1707682367650, value=90
1 row(s) in 0.0130 seconds
scan 'scores'
scan 'scores',{LIMIT=>2}
scan 'scores',{STARTROW=>'1',ENDROW=>3}
scan 'scores',{COLUMN=>'courses:python'}
hbase(main):004:0> scan 'scores'
ROW COLUMN+CELL
1 column=courses:java, timestamp=1707682372256, value=90
1 column=courses:python, timestamp=1707682367650, value=90
1 column=student:name, timestamp=1707682361045, value=xiaoming
2 column=courses:java, timestamp=1707682397313, value=80
2 column=courses:python, timestamp=1707682394587, value=80
2 column=student:name, timestamp=1707682391577, value=xiaokai
3 column=courses:java, timestamp=1707682406376, value=95
3 column=courses:python, timestamp=1707682403146, value=95
3 column=student:name, timestamp=1707682400472, value=xiaohong
3 row(s) in 0.0440 seconds
count 'scores'
hbase(main):001:0> count 'scores'
3 row(s) in 0.2330 seconds
=> 3
删除scores表中的列english
delete 'scores','1','courses:python'
delete 'scores','1','courses'
hbase(main):002:0> delete 'scores','1','courses:python'
0 row(s) in 0.0620 seconds
deleteall 'scores','1'
hbase(main):003:0> deleteall 'scores','1'
0 row(s) in 0.0160 seconds
hbase(main):004:0> scan 'scores'
ROW COLUMN+CELL
2 column=courses:java, timestamp=1707682397313, value=80
2 column=courses:python, timestamp=1707682394587, value=80
2 column=student:name, timestamp=1707682391577, value=xiaokai
3 column=courses:java, timestamp=1707682406376, value=95
3 column=courses:python, timestamp=1707682403146, value=95
3 column=student:name, timestamp=1707682400472, value=xiaohong
2 row(s) in 0.0210 seconds
truncate 'scores'
hbase(main):005:0> truncate 'scores'
Truncating 'scores' table (it may take a while):
- Disabling table...
- Truncating table...
0 row(s) in 3.5240 seconds
hbase(main):006:0> scan 'scores'
ROW COLUMN+CELL
0 row(s) in 0.1390 seconds
hbase(main):007:0>
**HBase权限与命令对照表**
hbase.security.authorization</name>
true</value>
</property>
hbase.coprocessor.master.classes</name>
org.apache.hadoop.hbase.security.access.AccessController</value>
</property>
hbase.coprocessor.region.classes</name>
org.apache.hadoop.hbase.security.access.AccessController,
org.apache.hadoop.hbase.security.token.TokenProvider</value>
</property>
hbase.superuser</name>
hbase,root,administrator</value>
</property>
hbase(main):004:0> grant 'xiaoxi','W','@my_ns'
hbase(main):005:0> revoke 'xiaoxi','@my_ns'