Hadoop学习笔记(十五)---Hbase shell命令的使用

1.启动hbase, 进入hbase文件夹下面的bin文件夹,然后执行命令:

hbase shell
[root@hadoop0 bin]# hbase shell
HBase Shell; enter 'help<RETURN>' for list of supported commands.
Type "exit" to leave the HBase Shell
Version 0.98.12.1-hadoop1, rb00ec5da604d64a0bdc7d92452b1e0559f0f5d73, Sun May 17 12:22:29 PDT 2015

hbase(main):001:0> 

2。创建表:

create 'users','user_id', 'address', 'info'

表users,三个列簇:user_id, address, info

3.查看所有表:list

hbase(main):003:0> list
TABLE                                                                                                                                                                       
users                                                                                                                                                                       
1 row(s) in 0.0400 seconds

4.查看表结构:describe 'users'

hbase(main):004:0> describe 'users'
Table users is ENABLED                                                                                                                                                      
users                                                                                                                                                                       
COLUMN FAMILIES DESCRIPTION                                                                                                                                                 
{NAME => 'address', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', VERSIONS => '1', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => 'FORE
VER', KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'}                                                                      
{NAME => 'info', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', VERSIONS => '1', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => 'FOREVER
', KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'}                                                                         
{NAME => 'user_id', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'ROW', REPLICATION_SCOPE => '0', VERSIONS => '1', COMPRESSION => 'NONE', MIN_VERSIONS => '0', TTL => 'FORE
VER', KEEP_DELETED_CELLS => 'FALSE', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACHE => 'true'}                                                                      
3 row(s) in 0.1000 seconds

5.删除表:

表不能直接删除,需要先进行disable操作:

如果直接删除会报下面的错误:

hbase(main):007:0> drop 'user_tmp'

ERROR: Table user_tmp 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'

应该先disable:

hbase(main):008:0> disable 'user_tmp'
0 row(s) in 1.4120 seconds
hbase(main):010:0> drop 'user_tmp'
0 row(s) in 0.2320 seconds

6.查看表是否存在:

hbase(main):013:0> exists 'users'
Table users does exist                                                                                                                                                      
0 row(s) in 0.0330 seconds

7.查看是否禁止:

hbase(main):016:0> is_enabled 'users'
true                                                                                                                                                                        
0 row(s) in 0.0410 seconds
hbase(main):002:0> is_disabled 'users'
false                                                                                                                                                                       
0 row(s) in 0.0270 seconds

7.插入数据:

hbase(main):001:0> put 'users', 'xiaoming','info:company','baidu'

8.查看表中的数据:

scan 'users'

9.获得小明的信息:

hbase(main):003:0> get 'users','xiaoming'
COLUMN                                       CELL                                                                                                                           
 info:age                                    timestamp=1433712506712, value=22                                                                                              
 info:company                                timestamp=1433712630400, value=baidu                                                                                           
2 row(s) in 0.0560 seconds

只查看年龄:

hbase(main):004:0> get 'users','xiaoming','info:age'
COLUMN                                       CELL                                                                                                                           
 info:age                                    timestamp=1433712506712, value=22                                                                                              
1 row(s) in 0.0280 seconds

10.更新记录:

hbase(main):007:0> put 'users','xiaoming','info:age','24'
0 row(s) in 0.0140 seconds

现在查看年龄就是最新的年龄:

hbase(main):009:0> get 'users','xiaoming','info:age'
COLUMN                                       CELL                                                                                                                           
 info:age                                    timestamp=1433713054227, value=24                                                                                              
1 row(s) in 0.0140 seconds

怎么查看历史记录呢?:

查看上一个数据:

hbase(main):011:0> get 'users','xiaoming',{COLUMN=>'info:age',VERSIONS=>2}

显示时间戳数据:

hbase(main):016:1> get 'users','xiaoming',{COLUMN=>'info:age',TIMESTAMP=>1433713054227}

删除数据:

delete 'users','xiaoming','info:age'

你可能感兴趣的:(Hadoop学习笔记(十五)---Hbase shell命令的使用)