1.HBase基本特点
存储数据&检索数据比较快
基于列存储的分布式的非关系型数据库
HBase通常与Hadoop结合使用
适合于存储非结构化数据的数据库
非结构化的字段数量根据用户需求而定
基于key-value存储数据
高可靠性,高性能,面向列存储,可伸缩的分布式数据库
利用HBase技术可以在低廉的PC server上搭建大数据规模的数据系统
2.表命令
1.启动命令
bin/hbase-daemon.sh start master
bin/hbase-daemon.sh start regionserver
bin/hbase shell
2.创建
hbase(main):001:0> create 'class','info'
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/opt/modules/hbase-0.98.6-hadoop2/lib/slf4j-log4j12-1.6.4.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/opt/modules/hadoop-2.5.0-cdh5.3.6/share/hadoop/common/lib/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
2018-11-15 12:29:01,288 WARN [main] util.NativeCodeLoader: Unable to load native-hadoop library for your platform... using builtin-java classes where applicable
0 row(s) in 2.6630 seconds
=> Hbase::Table - class
hbase(main):002:0>
create ‘表名’,‘列簇’,这里表名为class,列簇是infomation的简写info。
用 list ‘class’ 可以显示表格信息
也可以用 describe ‘class’ 显示表格信息
3.插入表数据
put ‘表名’,‘行键’,‘列族:列名’,‘值’
hbase(main):003:0> put 'class','1','info:classID','six'
0 row(s) in 0.1140 seconds
hbase(main):004:0> put 'class','1','info:teacher','mr.hu'
0 row(s) in 0.0110 seconds
hbase(main):005:0> put 'class','2','info:number','57'
0 row(s) in 0.0110 seconds
hbase(main):006:0> put 'class','2','info:teacher','mr.wang'
0 row(s) in 0.0130 seconds
表中列名信息不一样,行键1是插入的classID’,行键2是’number’
4.查看表数据
get ‘表名’,‘行键名’,
hbase(main):007:0> get 'class','1'
COLUMN CELL
info:classID timestamp=1542256877552, value=six
info:grade timestamp=1542256877386, value=four
info:teacher timestamp=1542256894908, value=mr.hu
3 row(s) in 0.0360 seconds
hbase(main):008:0> get 'class','2'
COLUMN CELL
info:number timestamp=1542257013919, value=57
info:teacher timestamp=1542257023323, value=mr.wang
2 row(s) in 0.0150 seconds
通过指定的列进行查询
get ‘表名’,行键名’,‘列族:列名’
hbase(main):010:0> get 'class','1','info:grade'
COLUMN CELL
info:grade timestamp=1542256877386, value=four
1 row(s) in 0.0140 seconds
通过scan全表扫描
scan 'class'
ROW COLUMN+CELL
1 column=info:classID, timestamp=1542256877552, value=six
1 column=info:grade, timestamp=1542256877386, value=four
1 column=info:teacher, timestamp=1542256894908, value=mr.hu
2 column=info:number, timestamp=1542257013919, value=57
2 column=info:teacher, timestamp=1542257023323, value=mr.wang
2 row(s) in 0.0790 seconds
相当于 sql 表中select classID,grade from class;
hbase(main):012:0> scan 'class',{COLUMNS => ['info:grade','info:classID']}
ROW COLUMN+CELL
1 column=info:classID, timestamp=1542256877552, value=six
1 column=info:grade, timestamp=1542256877386, value=four
1 row(s) in 0.0230 seconds
删除表
删除表时一定要先禁用表再删除表。
hbase(main):013:0> drop 'class'
ERROR: Table class 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'
只有这样才能删除掉。
hbase(main):016:0> disable 'class'
0 row(s) in 1.4960 seconds
hbase(main):017:0> drop 'class'
0 row(s) in 0.3480 seconds