HBase完全分布模式安装(4)

1.      常用hbase命令

--进入habase

[grid@gc ~]$ hbase-0.90.5/bin/hbase shell

HBase Shell; enter 'help<RETURN>' for list of supported commands.

Type "exit<RETURN>" to leave the HBase Shell

Version 0.90.5, r1212209, Fri Dec  9 05:40:36 UTC 2011

hbase(main):001:0>

--查看数据库状态

hbase(main):002:0> status

2 servers, 0 dead, 1.0000 average load

--查询数据库版本

hbase(main):004:0> version

0.90.5, r1212209, Fri Dec  9 05:40:36 UTC 2011

--帮助命令

hbase(main):003:0> help

HBase Shell, version 0.90.5, r1212209, Fri Dec  9 05:40:36 UTC 2011

Type 'help "COMMAND"', (e.g. 'help "get"' -- the quotes are necessary) for help on a specific command.

Commands are grouped. Type 'help "COMMAND_GROUP"', (e.g. 'help "general"') for help on a command group.

COMMAND GROUPS:

Group name: general

Commands: status, version

Group name: ddl

Commands: alter, create, describe, disable, drop, enable, exists, is_disabled, is_enabled, list

Group name: dml

Commands: count, delete, deleteall, get, get_counter, incr, put, scan, truncate

Group name: tools

Commands: assign, balance_switch, balancer, close_region, compact, flush, major_compact, move, split, unassign, zk_dump

Group name: replication

Commands: add_peer, disable_peer, enable_peer, remove_peer, start_replication, stop_replication

SHELL USAGE:

Quote all names in HBase Shell such as table and column names.  Commas delimit

command parameters.  Type <RETURN> after entering a command to run it.

Dictionaries of configuration used in the creation and alteration of tables are

Ruby Hashes. They look like this:

{'key1' => 'value1', 'key2' => 'value2', ...}

and are opened and closed with curley-braces.  Key/values are delimited by the

'=>' character combination.  Usually keys are predefined constants such as

NAME, VERSIONS, COMPRESSION, etc.  Constants do not need to be quoted.  Type

'Object.constants' to see a (messy) list of all constants in the environment.

If you are using binary keys or values and need to enter them in the shell, use

double-quote'd hexadecimal representation. For example:

hbase> get 't1', "key\x03\x3f\xcd"

hbase> get 't1', "key\003\023\011"

hbase> put 't1', "test\xef\xff", 'f1:', "\x01\x33\x40"

The HBase shell is the (J)Ruby IRB with the above HBase-specific commands added.

For more on the HBase Shell, see

2.      Hbase数据库操作命令

--创建表

resume表逻辑模型:

行键

 

时间戳

 

列族binfo

 

列族edu

 

列族work

 

lichangzai

 

T2

 

binfo:age=’1980-1-1’

         

T3

 

binfo:sex=’man’

         

T5

     

edu:mschool=’rq no.1’

     

T6

     

edu:university=’qhddx’

     

T7

         

work:company1=’12580’

 

changfei

 

T10

 

binfo:age=’1986-2-1’

         

T11

     

edu:university=’bjdx’

     

T12

         

work:company1=’LG’

 

……

 

Tn

         

--创建表

hbase(main):005:0> create 'resume','binfo','edu','work'

0 row(s) in 16.5710 seconds

--列出表

hbase(main):006:0> list

TABLE                                                                                                                                                       

resume                                                                                                                                                     

1 row(s) in 1.6080 seconds

--查看表结构

hbase(main):007:0> describe 'resume'

DESCRIPTION                                                                                          ENABLED                                               

{NAME => 'resume', FAMILIES => [{NAME => 'binfo', BLOOMFILTER => 'NONE', REPLICATION_SCOPE => '0', C true                                                 

OMPRESSION => 'NONE', VERSIONS => '3', TTL => '2147483647', BLOCKSIZE => '65536', IN_MEMORY => 'fals                                                       

e', BLOCKCACHE => 'true'}, {NAME => 'edu', BLOOMFILTER => 'NONE', REPLICATION_SCOPE => '0', COMPRESS                                                       

ION => 'NONE', VERSIONS => '3', TTL => '2147483647', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLO                                                       

CKCACHE => 'true'}, {NAME => 'work', BLOOMFILTER => 'NONE', REPLICATION_SCOPE => '0', COMPRESSION =>                                                       

'NONE', VERSIONS => '3', TTL => '2147483647', BLOCKSIZE => '65536', IN_MEMORY => 'false', BLOCKCACH                                                       

E => 'true'}]}                                                                                                                                             

1 row(s) in 1.8590 seconds

--添加列族

hbase(main):014:0> disable 'resume'                         

0 row(s) in 4.2630 seconds

hbase(main):015:0> alter 'resume',name='f1'

0 row(s) in 4.6990 seconds

--删除列族

hbase(main):017:0> alter 'resume',{NAME=>'f1',METHOD=>'delete'}

0 row(s) in 1.1390 seconds

--或是

hbase(main):021:0> alter 'resume','delete' => 'f1'

0 row(s) in 1.9310 seconds

hbase(main):022:0> enable 'resume'

0 row(s) in 5.9060 seconds

注意:

(1)      ddl命令是区分大小写的,像ddl中的alter,create, drop, enable等都必需用小写。而{}中的属性名都必需用大写。

(2)      alter、drop表之前必需在先禁用(disabel)表,修改完后再启用表(enable)表,否则会报错

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/a08e0009baa31a41b88bb4c3dc9b75a5.html