参考:
https://www.cnblogs.com/charlist/p/7120377.html
http://www.cnblogs.com/liangzh/archive/2012/04/06/2434690.html
1. 启动Hbase
[root@zzf hbase-1.2.6]# pwd
/usr/local/hbase-1.2.6
[root@zzf hbase-1.2.6]# ./bin/start-hbase.sh
2. 关闭Hbase
[root@zzf hbase-1.2.6]# ./bin/close-hbase.sh
3. 进入hbase shell
[root@zzf hbase-1.2.6]# ./bin/hbase shell
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/usr/local/hbase-1.2.6/lib/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/usr/local/hadoop-2.7.6/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.2.6, rUnknown, Mon May 29 02:25:32 CDT 2017
4. 查看数据库状态
hbase(main):001:0> status
1 active master, 0 backup masters, 3 servers, 0 dead, 0.6667 average load
5. 查看数据库版本信息
hbase(main):002:0> version
1.2.6, rUnknown, Mon May 29 02:25:32 CDT 2017
6.查看当前HBase中具有哪些表
hbase(main):003:0> list
TABLE
0 row(s) in 0.1320 seconds
=> []
7. 创建表:表wordSplit,列族content
hbase(main):004:0> create 'wordSplit',{NAME => 'content',VERSIONS => 1}
0 row(s) in 5.2710 seconds
=> Hbase::Table - wordSplit
8. 查看表的结构,describe '表名'
hbase(main):005:0> describe 'wordSplit'
Table wordSplit is ENABLED
wordSplit
COLUMN FAMILIES DESCRIPTION
{NAME => 'content', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', C
OMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}
1 row(s) in 0.4150 seconds
9. 使表在线,enable '表名'
hbase(main):006:0> enable 'wordSplit'
10. 查看表是否存在,exists '表名'
hbase(main):007:0> exists 'wordSplit'
Table wordSplit does exist
0 row(s) in 0.0680 seconds
x 11. 查看表是否在线,is_enable '表名'
12. 加入一行数据,行键'zkb', 列族content的列名为“”, 值为5
hbase(main):014:0> put 'wordSplit','zkb','content:','5'
0 row(s) in 0.1640 seconds
13. 给zkb这一行的数据的列族content添加一列 <\math,97>
hbase(main):016:0> put 'wordSplit','zkb','content:math','97'
0 row(s) in 0.1500 seconds
14. 加入一行数据,行键'hjm',列族grade的列名为“” 值为4
hbase(main):017:0> put 'wordSplit','hjm','grade:','4'
这个列族必须先建好?
15. 查看wordSplit表行键为zkb的相关数据
hbase(main):018:0> get 'wordSplit','zkb'
COLUMN CELL
content: timestamp=1536717318496, value=5
content:math timestamp=1536717466960, value=97
2 row(s) in 0.1900 seconds
16. 查看wordSplit表中的所有数据,
注意:scan命令可以指定startrow,stoprow来scan多个row 例如:scan 'user_test',{COLUMNS =>'info:username',LIMIT =>10, STARTROW => 'test',STOPROW=>'test2'}
hbase(main):019:0> scan 'wordSplit'
ROW COLUMN+CELL
zkb column=content:, timestamp=1536717318496, value=5
zkb column=content:math, timestamp=1536717466960, value=97
1 row(s) in 0.1020 seconds
17. 查看wordSplit表中所有content列族的数据
hbase(main):020:0> scan 'wordSplit',{COLUMN => 'content'}
ROW COLUMN+CELL
zkb column=content:, timestamp=1536717318496, value=5
zkb column=content:math, timestamp=1536717466960, value=97
1 row(s) in 0.1260 seconds
18. 删除表wordSplit
disable 'wordSplit'
delete '表名','行键名','列族名:列名' 删除某个列
deleteall '表名','行键' 删除某个行键的所有数据
drop '表名' 删除表
19. 查看表中行数
hbase(main):007:0> count 'wordSplit'
1 row(s) in 0.2180 seconds
=> 1
20. 清空表数据
hbase(main):009:0> truncate 'device'
Truncating 'device' table (it may take a while):
- Disabling table...
- Truncating table...
0 row(s) in 4.4350 seconds
再查看表中行数:
hbase(main):010:0> count 'device'
0 row(s) in 0.2000 seconds
=> 0
21. 查看表大小
22. 修改版本数
alter 'tablename', {NAME => 'ColFam', VERSION => 4}
23. 删除某个列族
alter 'tablename', {NAME => 'ColFam', METHOD => 'delete'}
24. 增加一个列族
disable 'tablename'
alter 'tablename' {NAME => 'ColFam1', NAME => 'ColFam2'}
enable 'tablename'
25. 设置列族的最大值为256MB
alter 'tablename', {NAME => 'ColFam',METHOD => 'table_att', MAX_FILESIZE=>268435456}
26. 在创建表时实现压缩
create 'tablename', {NAME => 'ColFam', COMPRESSION => 'SNAPPY'}