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<RETURN>" 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'
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章