1、进入hbase的shell
hbase提供了一个shell的终端给用户交互
[root@hadoop3 conf]# hbase shell
退出使用quit或者ctrl+c
需要关闭hadoop的安全模式不然进行一些操作,比如scan会卡住
进入到hadoop的bin目录下
在启动hbase之前
[root@hadoop3 conf]# hadoop dfsadmin -safemode leave
2、创建表
create ‘表名’,’列族1’,’列族2’,…’列族n’
craete 'user','info1','info2'
3、查看所有表
list
4、描述表
describe 'user'
Table user is ENABLED
COLUMN FAMILIES DESCRIPTION
{NAME => 'info1', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', VERSIONS => '1', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => 'FOREVER', KE
EP_DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'}
{NAME => 'info2', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', VERSIONS => '1', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => 'FOREVER', KE
EP_DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'}
2 row(s) in 0.0790 seconds
5、删除表
hbase(main):033:0> disable 'user'
0 row(s) in 1.4110 seconds
hbase(main):034:0> drop 'user'
0 row(s) in 0.2330 seconds
hbase(main):035:0> list
TABLE
0 row(s) in 0.0450 seconds
6、判断表是否存在
hbase(main):040:0> exists 'user'
Table user does exist
0 row(s) in 0.0980 seconds
7、向表中添加数据
hbase(main):041:0> put 'user','1234','info1:name','zhangsan'
0 row(s) in 0.1310 seconds
hbase没有直接修改操作,但是可以覆盖,只要rowkey跟列族列名一致就会覆盖
比如这里要修改上面插入数据的info:name为’eve’
hbase(main):041:0> put 'user','1234','info1:name','eve'
0 row(s) in 0.1310 seconds
hbase(main):042:0> scan 'user1'
ROW COLUMN+CELL
1234 column=info1:name, timestamp=1509304915052, value=eve
8、扫描整个表
hbase(main):043:0> scan 'user'
9、查询记录数
rowkey相同只算一条
hbase(main):066:0> count 'user'
2 row(s) in 0.0340 seconds
=> 2
10、查询
查询某一行
hbase(main):067:0> get 'user','1234'
COLUMN CELL
info1:age timestamp=1547125476542, value=18
info1:name timestamp=1547125469727, value=eve
info2:favor timestamp=1547125482454, value=eat
3 row(s) in 0.0330 seconds
查询某个列族:
hbase(main):068:0> get 'user','1234','info1'
COLUMN CELL
info1:age timestamp=1547125476542, value=18
info1:name timestamp=1547125469727, value=eve
2 row(s) in 0.0280 seconds
查询某个列:
hbase(main):068:0> get 'user','1234','info1'
COLUMN CELL
info1:age timestamp=1547125476542, value=18
info1:name timestamp=1547125469727, value=eve
2 row(s) in 0.0280 seconds
查询某个时间戳版本
不知道时间戳
先将这一个列族修改为能选择三个版本的列族,可以随便选择查多少个版本,查的版本只要比存的版本少就行
hbase(main):069:0> alter 'user' ,{NAME=>'info1',VERSIONS=>3}
hbase(main):070:0> get 'user','1234',{COLUMN=>'info1:name',VERSIONS=>3}
知道时间戳
hbase(main):071:0> get 'user', '1234', {COLUMN => 'info1:name',TIMESTAMP => 1538014481194}
11、删除记录
删除列族下的某一列
hbase(main):071:0> delete 'user','1234','info1:name'
0 row(s) in 0.0170 seconds
删除某一列族
hbase(main):072:0> delete 'user','1234','info2'
0 row(s) in 0.0230 seconds
删除某一行
hbase(main):073:0> deleteall 'user','1234'
0 row(s) in 0.0310 seconds
12、清空表
hbase(main):074:0> truncate 'user'
Truncating 'user' table (it may take a while):
- Disabling table...
- Truncating table...
0 row(s) in 1.4540 seconds
hbase(main):075:0> scan 'user'
ROW COLUMN+CELL
0 row(s) in 0.0260 seconds
网友评论