hbase Shell之简单命令说明

[hadoop@master hbase]$ bin/hbase shell

进入shell


hbase(main):001:0> help

******(Shell命令说明)


hbase(main):002:0> status

1 servers, 0 dead, 4.0000 average load (服务器,dead,负荷)


hbase(main):003:0> version

0.94.2, r1395367, Sun Oct  7 19:11:01 UTC 2012 (版本)


hbase(main):001:0> create 'member','member_id','address','info'

0 row(s) in 5.3700 seconds (创建表,成功)


hbase(main):002:0> list
TABLE                                                                                          
htest                                                                                          
member                                                                                         
user                                                                                           
3 row(s) in 0.3400 seconds (查看TABLE信息)


hbase(main):003:0> describe 'member'
DESCRIPTION                                                   ENABLED                          
 {NAME => 'member', FAMILIES => [{NAME => 'address', DATA_BLO true                             
 CK_ENCODING => 'NONE', BLOOMFILTER => 'NONE', REPLICATION_SC                                  
 OPE => '0', VERSIONS => '3', COMPRESSION => 'NONE', MIN_VERS                                  
 IONS => '0', TTL => '2147483647', KEEP_DELETED_CELLS => 'fal                                  
 se', BLOCKSIZE => '65536', IN_MEMORY => 'false', ENCODE_ON_D                                  
 ISK => 'true', BLOCKCACHE => 'true'}, {NAME => 'info', DATA_                                  
 BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'NONE', REPLICATION                                  
 _SCOPE => '0', VERSIONS => '3', COMPRESSION => 'NONE', MIN_V                                  
 ERSIONS => '0', TTL => '2147483647', KEEP_DELETED_CELLS => '                                  
 false', BLOCKSIZE => '65536', IN_MEMORY => 'false', ENCODE_O                                  
 N_DISK => 'true', BLOCKCACHE => 'true'}, {NAME => 'member_id                                  
 ', DATA_BLOCK_ENCODING => 'NONE', BLOOMFILTER => 'NONE', REP                                  
 LICATION_SCOPE => '0', VERSIONS => '3', COMPRESSION => 'NONE                                  
 ', MIN_VERSIONS => '0', TTL => '2147483647', KEEP_DELETED_CE                                  
 LLS => 'false', BLOCKSIZE => '65536', IN_MEMORY => 'false',                                   
 ENCODE_ON_DISK => 'true', BLOCKCACHE => 'true'}]}                                             
1 row(s) in 0.0340 seconds   (查看表)


hbase(main):002:0> alter 'member',{NAME=>'member_id',METHOD=>'delete'}
ERROR: org.apache.hadoop.hbase.TableNotDisabledException: org.apache.hadoop.hbase.TableNotDisabledException: member

(不可直接修改,必须先把表离线,然后修改)


hbase(main):003:0> disable 'member'
0 row(s) in 2.2260 seconds (disable表,先设为不可用)

hbase(main):004:0> alter 'member',{NAME=>'member_id',METHOD=>'delete'}
Updating all regions with the new schema...
1/1 regions updated.
Done.
0 row(s) in 2.5010 seconds  (修改成功)


hbase(main):005:0> enable 'member'
0 row(s) in 2.2380 seconds   (然后启动表)


hbase(main):009:0> disable 'member'
0 row(s) in 2.1470 seconds  (删除表也需要先把表设为不可用)


hbase(main):010:0> drop 'member'
0 row(s) in 1.3690 seconds  (删除成功)


hbase(main):011:0> exists 'member'
Table member does not exist                                                                    
0 row(s) in 0.1170 seconds   (查看是否存在表)


hbase(main):015:0> is_enabled 'member'
true                                                                                           
0 row(s) in 0.0030 seconds   (查看表是否可用)


hbase(main):016:0> is_disabled 'member'
false                                                                                          
0 row(s) in 0.0040 seconds  (查看表是否不可用)


(插入记录)

hbase(main):017:0> put 'member','scutshuxue','info:age','24'

hbase(main):018:0> put 'member','scutshuxue','info:birthday','1987-06-17'

hbase(main):020:0> put 'member','scutshuxue','info:company','alibaba'

hbase(main):025:0> put 'member','scutshuxue','address:province','zhejiang'

hbase(main):026:0> put 'member','scutshuxue','address:city','hangzhou'

hbase(main):027:0> put 'member','xiaofeng','info:birthday','1987-4-17'

hbase(main):028:0> put 'member','xiaofeng','info:company','alibaba'

hbase(main):029:0> put 'member','xiaofeng','address:contry','china'

hbase(main):030:0> put 'member','xiaofeng','address:province','guangdong'

hbase(main):031:0> put 'member','xiaofeng','address:city','jieyang'

hbase(main):032:0> put 'member','xiaofeng','address:town','xianqiao'


(查询记录:行键查询)

hbase(main):001:0> get 'member','scutshuxue'
COLUMN                   CELL                                                                  
 address:city            timestamp=1365791240949, value=hangzhou                               
 address:province        timestamp=1365791217245, value=zhejiang                               
 info:age                timestamp=1365790872766, value=24                                     
 info:birthday           timestamp=1365790910608, value=1987-06-17                             
 info:company            timestamp=1365790948776, value=alibaba                                
5 row(s) in 2.8340 seconds


(查询记录:行键、一个列簇的所有信息)

hbase(main):002:0> get 'member','scutshuxue','info'
COLUMN                   CELL                                                                  
 info:age                timestamp=1365790872766, value=24                                     
 info:birthday           timestamp=1365790910608, value=1987-06-17                             
 info:company            timestamp=1365790948776, value=alibaba                                
3 row(s) in 0.0220 seconds


(查询记录:行键、列簇的某列信息)

hbase(main):003:0> get 'member','scutshuxue','info:age'
COLUMN                   CELL                                                                  
 info:age                timestamp=1365790872766, value=24                                     
1 row(s) in 0.0130 seconds


(更新一条记录)

hbase(main):004:0> put 'member','scutshuxue','info:age','99'
0 row(s) in 0.0940 seconds

hbase(main):005:0> get'member','scutshuxue','info:age'
COLUMN                   CELL                                                                  
 info:age                timestamp=1365792994491, value=99                                     
1 row(s) in 0.0170 seconds


(通过时间戳查询记录)

hbase(main):008:0> get'member','scutshuxue',{COLUMN=>'info:age',TIMESTAMP=>1365792994491}
COLUMN                   CELL                                                                  
 info:age                timestamp=1365792994491, value=99                                     
1 row(s) in 0.0110 seconds


(全表扫描)

hbase(main):009:0> scan 'member'
ROW                      COLUMN+CELL                                                           
 scutshuxue              column=address:city, timestamp=1365791240949, value=hangzhou          
 scutshuxue              column=address:province, timestamp=1365791217245, value=zhejiang      
 scutshuxue              column=info:age, timestamp=1365792994491, value=99                    
 scutshuxue              column=info:birthday, timestamp=1365790910608, value=1987-06-17       
 scutshuxue              column=info:company, timestamp=1365790948776, value=alibaba           
 xiaofeng                column=address:city, timestamp=1365791360361, value=jieyang           
 xiaofeng                column=address:contry, timestamp=1365791327027, value=china           
 xiaofeng                column=address:province, timestamp=1365791339666, value=guangdong     
 xiaofeng                column=address:town, timestamp=1365791380287, value=xianqiao          
 xiaofeng                column=info:birthday, timestamp=1365791274037, value=1987-4-17        
 xiaofeng                column=info:company, timestamp=1365791292933, value=alibaba           
2 row(s) in 0.1540 seconds


(删除制定行键的字段)
hbase(main):010:0> delete 'member','temp','info:age'
0 row(s) in 0.0500 seconds

hbase(main):011:0> get'member','temp'
COLUMN                   CELL                                                                  
0 row(s) in 0.0050 seconds


(删除整行)

hbase(main):013:0> deleteall'member','xiaofeng'
0 row(s) in 0.0070 seconds


(查询行)

hbase(main):014:0> count'member'
1 row(s) in 0.0670 seconds


(清空表)

hbase(main):015:0> truncate'member'
Truncating 'member' table (it may take a while):
 - Disabling table...
 - Dropping table...
 - Creating table...
0 row(s) in 3.8280 seconds


Hbase API

《Hbase权威指南》第3-5章

http://hbase.apache.org/apidocs/index.html

你可能感兴趣的:(hadoop,shell,hbase,云计算)