Hbase常用命令
Hbase常用命令
AlexHbase常用命令
进入命令行
cd /usr/local/src/hbase-0.98.24/bin
- [root@master bin]#
./hbase shell
1
2
3HBase Shell; enter 'help<RETURN>' for list of supported commands.
Type "exit<RETURN>" to leave the HBase Shell
Version 0.98.0-hadoop1, r1565492, Thu Feb 6 16:20:15 PST 2014 - 查看服务器状态
1
2hbase(main):001:0> status
3 servers, 0 dead, 1.3333 average load - 查看hive版本
1
2hbase(main):002:0> version
0.98.0-hadoop1, r1565492, Thu Feb 6 16:20:15 PST 2014
DDL操作
创建表: create
表名称
,列名称1
,列名称2
,列名称N
1
2hbase(main):010:0> create 'mytablename','id','name','age'
0 row(s) in 0.4220 seconds列出所有表
1
2
3
4hbase(main):011:0> list
TABLE
mytablename
1 row(s) in 0.0170 seconds获取表描述信息
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27hbase(main):022:0> describe 'mytablename'
DESCRIPTION ENABLED
'mytablename', {NAME => 'age', DATA_BLOCK_ENCODING true
=> 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOP
E => '0', VERSIONS => '1', COMPRESSION => 'NONE',
MIN_VERSIONS => '0', TTL => '2147483647', KEEP_DEL
ETED_CELLS => 'false', BLOCKSIZE => '65536', IN_ME
MORY => 'false', BLOCKCACHE => 'true'}, {NAME => '
id', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER =>
'ROW', REPLICATION_SCOPE => '0', VERSIONS => '1',
COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL =
> '2147483647', KEEP_DELETED_CELLS => 'false', BLO
CKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACH
E => 'true'}, {NAME => 'name', DATA_BLOCK_ENCODING
=> 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOP
E => '0', VERSIONS => '1', COMPRESSION => 'NONE',
MIN_VERSIONS => '0', TTL => '2147483647', KEEP_DEL
ETED_CELLS => 'false', BLOCKSIZE => '65536', IN_ME
MORY => 'false', BLOCKCACHE => 'true'}
1 row(s) in 0.0390 seconds
### 注:
VERSION : 修改信息,版本号,备份功能
IN_MEMORY : true为都存内存上,false存HDFS删除一个列族 :
alter
/disable
/enable
1
2
3
4
5
6hbase(main):026:0> alter 'mytablename',{NAME=>'id',METHOD=>'delete'}
Updating all regions with the new schema...
0/1 regions updated.
1/1 regions updated.
Done.
0 row(s) in 2.1860 seconds查看删除后信息
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15hbase(main):027:0> describe 'mytablename'
DESCRIPTION ENABLED
'mytablename', {NAME => 'age', DATA_BLOCK_ENCODING true
=> 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOP
E => '0', VERSIONS => '1', COMPRESSION => 'NONE',
MIN_VERSIONS => '0', TTL => '2147483647', KEEP_DEL
ETED_CELLS => 'false', BLOCKSIZE => '65536', IN_ME
MORY => 'false', BLOCKCACHE => 'true'}, {NAME => '
name', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER
=> 'ROW', REPLICATION_SCOPE => '0', VERSIONS => '1
', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL
=> '2147483647', KEEP_DELETED_CELLS => 'false', B
LOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCA
CHE => 'true'}
1 row(s) in 0.0360 seconds添加列族
1
alter 'mytablename',{NAME=>'flags',VERSIONS=>2,IN_MEMORY=>TRUE}
删除表
1
2
3
4
5
6hbase(main):047:0> drop 'mytablename'
ERROR: Table mytablename is enabled. Disable it first.'
Here is some help for this command:
Drop the named table. Table must first be disabled: e.g. "hbase> drop 't1'"要删除的表必须是
disabled
,所以先设置表disabled
再删除
1 | hbase(main):049:0> disable 'mytablename' |
- 查看结果
1
2
3
4
5hbase(main):051:0> list
TABLE
0 row(s) in 0.0110 seconds
=> [] - 查看HDFS会发现表以文件的形式保存
1
./hadoop fs -ls /hbase/data/default
- 查询表是否存在
1
2
3hbase(main):058:0> exists 'mytablename'
Table mytablename does not exist
0 row(s) in 0.0280 seconds
DML操作
- 插入记录 : put
表名称
,行名称
,列名称:
,值
1
2hbase(main):010:0> put 'mytablename',1,'name','zhangsan'
0 row(s) in 0.0860 seconds - 获取插入记录
1
2
3
4hbase(main):011:0> get 'mytablename',1
COLUMN CELL
name: timestamp=1520671182292, value=zhangsan
1 row(s) in 0.0270 seconds - 修改插入记录
1
2hbase(main):012:0> put 'mytablename',1,'name','lisi'
0 row(s) in 0.0100 seconds - 查看所有数据:
线上禁用
1
2
3
4hbase(main):002:0> scan 'mytablename'
ROW COLUMN+CELL
1 column=name:, timestamp=1520671195585, value=lisi
1 row(s) in 0.0790 seconds - 将数据刷入HDFS
1
2hbase(main):003:0> flush 'mytablename'
0 row(s) in 0.1100 seconds