1. 官网文档
[root@node1 ~]# hbase
hbase hbase-cleanup.sh hbase-common.sh hbase-config.sh hbase-daemon.sh hbase-daemons.sh hbase-jruby
[root@node1 ~]# hbase
Usage: hbase [<options>] <command> [<args>]
Options:
--config DIR Configuration direction to use. Default: ./conf
--hosts HOSTS Override the list in 'regionservers' file
--auth-as-server Authenticate to ZooKeeper using servers configuration
Commands:
Some commands take arguments. Pass no args or -h for usage.
shell Run the HBase shell
hbck Run the hbase 'fsck' tool
snapshot Tool for managing snapshots
snapshotinfo Tool for dumping snapshot information
wal Write-ahead-log analyzer
hfile Store file analyzer
zkcli Run the ZooKeeper shell
upgrade Upgrade hbase
master Run an HBase HMaster node
regionserver Run an HBase HRegionServer node
zookeeper Run a Zookeeper server
rest Run an HBase REST server
thrift Run the HBase Thrift server
thrift2 Run the HBase Thrift2 server
clean Run the HBase clean up script
classpath Dump hbase CLASSPATH
mapredcp Dump CLASSPATH entries required by mapreduce
pe Run PerformanceEvaluation
ltt Run LoadTestTool
canary Run the Canary tool
hbtop Run the HBTop tool
version Print the version
CLASSNAME Run the class named CLASSNAME
2. hbase shell
[root@node1 ~]# hbase shell
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/share/hbase/hbase-1.3.6/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/share/hadoop/hadoop-2.7.2/share/hadoop/common/lib/slf4j-log4j12-1.7.10.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.Log4jLoggerFactory]
HBase Shell; enter 'help<RETURN>' for list of supported commands.
Type "exit<RETURN>" to leave the HBase Shell
Version 1.3.6, r806dc3625c96fe2cfc03048f3c54a0b38bc9e984, Tue Oct 15 01:55:41 PDT 2019
hbase(main):001:0>
2.1 创建表
hbase(main):001:0> create 'user1','info1'
0 row(s) in 1.5810 seconds
=> Hbase::Table - user1
2.2 显示表
hbase(main):002:0> list
TABLE user1 1 row(s) in 0.0260 seconds
=> ["user1"]
2.3 显示表结构
hbase(main):003:0> describe 'user1'
Table user1 is NABLED
user1
COLUMN FAMILIES DESCRIPTION
{NAME => 'info1', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING => 'N
ONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0
'}
1 row(s) in 0.0360 seconds
2.4 将表设置为disable
hbase(main):008:0> disable 'user1'
2.5 删除表
#先要将表设置为disable,否则无法删除
hbase(main):004:0> drop 'user1'
ERROR: Table user1 is enabled. Disable it first.
Here is some help for this command:
Drop the named table. Table must first be disabled:
hbase> drop 't1'
hbase> drop 'ns1:t1'
2.6 添加字段
hbase(main):006:0> put 'user1','1232456','info1:name','kw'
0 row(s) in 0.0920 seconds
2.7 全表扫描
hbase(main):007:0> scan 'user1'
ROW COLUMN+CELL
1232456 column=info1:name, timestamp=1584019072442, value=kw
1 row(s) in 0.0300 seconds
2.8 列族中增加字段
hbase(main):008:0> put 'user1','1232456','info1:age','23'
0 row(s) in 0.0150 seconds
2.9 统计行数
hbase(main):009:0> count 'user1'
1 row(s) in 0.0290 seconds
=> 1
2.10 获取一个列族的数据
hbase(main):001:0> get 'user1','1232456','info1'
COLUMN CELL
info1:age timestamp=1584019150829, value=23
info1:name timestamp=1584019072442, value=kw
1 row(s) in 0.2050 seconds
2.11 更新字段
如果插入键值、列族、属性相同的属性,这个时候起到了更新的作用
hbase(main):002:0> put 'user1','1232456','info1:age','20'
0 row(s) in 0.0650 seconds
2.12 获取指定的属性
hbase(main):003:0> get 'user1','1232456','info1:age'
COLUMN CELL
info1:age timestamp=1584019261530, value=20
1 row(s) in 0.0210 seconds
2.13 删除数据
hbase(main):004:0> delete 'user1','1232456','info1:age'
0 row(s) in 0.0860 seconds
2.14 删除所有数据
hbase(main):030:0> deleteall 'user1','1232456'
0 row(s) in 0.0210 seconds
hbase(main):031:0> list
TABLE
user1
1 row(s) in 0.1370 seconds
=> ["user1"]
hbase(main):032:0>
2.15 创建指定保存的版本的表
hbase(main):005:0> create 'teacher',{NAME=>'username',VERSIONS=>5}
0 row(s) in 1.3360 seconds
=> Hbase::Table - teacher
hbase(main):006:0> put 'teacher','91001','username','Mary'
0 row(s) in 0.0310 seconds
hbase(main):007:0> put 'teacher','91001','username','Mary1'
0 row(s) in 0.0060 seconds
hbase(main):008:0> put 'teacher','91001','username','Mary2'
0 row(s) in 0.0060 seconds
hbase(main):009:0> put 'teacher','91001','username','Mary3'
0 row(s) in 0.0050 seconds
hbase(main):010:0> put 'teacher','91001','username','Mary4'
0 row(s) in 0.0030 seconds
hbase(main):011:0> put 'teacher','91001','username','Mary5'
0 row(s) in 0.0200 seconds
#查询时,指定查询的历史版本数。默认会查询出最新的数据。(有效取值为1到5)
hbase(main):014:0* get 'teacher','91001',{COLUMN=>'username',VERSIONS=>5}
COLUMN CELL
username: timestamp=1584019808849, value=Mary5
username: timestamp=1584019757172, value=Mary4
username: timestamp=1584019757135, value=Mary3
username: timestamp=1584019757087, value=Mary2
username: timestamp=1584019757052, value=Mary1
1 row(s) in 0.0350 seconds
hbase(main):015:0> get 'teacher','91001',{COLUMN=>'username',VERSIONS=>2}
COLUMN CELL
username: timestamp=1584019808849, value=Mary5
username: timestamp=1584019757172, value=Mary4
1 row(s) in 0.0160 seconds
————Blueicex 2020/3/12 21:24 blueice1980@126.com