HBase常用命令

进入hbase/bin目录,执行./hbase shell  打开shell

 


-- 查看命令的帮助信息

hbase(main):018:0> help 'create'
 Create table; pass table name, a dictionary of specifications per
 column family, and optionally a dictionary of table configuration.
 Dictionaries are described below in the GENERAL NOTES section.
 Examples:

   hbase> create 't1', {NAME => 'f1', VERSIONS => 5}
   hbase> create 't1', {NAME => 'f1'}, {NAME => 'f2'}, {NAME => 'f3'}
   hbase> # The above in shorthand would be the following:
   hbase> create 't1', 'f1', 'f2', 'f3'
   hbase> create 't1', {NAME => 'f1', VERSIONS => 1, TTL => 2592000, BLOCKCACHE => true}
   hbase> create 't1', 'f1', {SPLITS => ['10', '20', '30', '40']}
   hbase> create 't1', 'f1', {SPLITS_FILE => 'splits.txt'}
   hbase> # Optionally pre-split the table into NUMREGIONS, using
   hbase> # SPLITALGO ("HexStringSplit", "UniformSplit" or classname)
   hbase> create 't1', 'f1', {NUMREGIONS => 15, SPLITALGO => 'HexStringSplit'}

 

 

 

-- 创建stu表,有name和contact两个列族

hbase(main):008:0> create 'stu','name','contact'
 0 row(s) in 1.2090 seconds

 


-- 插入数据

hbase(main):009:0> put 'stu','zhang san','name:first','zhang'
 0 row(s) in 0.0930 seconds

 hbase(main):010:0> put 'stu','zhang san','name:last','san'
 0 row(s) in 0.0750 seconds

 hbase(main):011:0> put 'stu','zhang san','contact:tel','13000000000'
 0 row(s) in 0.0790 seconds

 hbase(main):012:0> put 'stu','zhang san','contact:email','z3@gmail.com'
 0 row(s) in 0.0740 seconds

 


-- get查询

hbase(main):013:0> get 'stu','zhang san'
 COLUMN                        CELL                                                                              
  contact:email                timestamp=1355938162012, value=z3@gmail.com                                       
  contact:tel                  timestamp=1355938151070, value=13000000000                                        
  name:first                   timestamp=1355938132910, value=zhang                                              
  name:last                    timestamp=1355938142305, value=san                                                

4 row(s) in 0.1320 seconds

 

-- scan查询
hbase(main):014:0> scan 'stu'
 ROW                           COLUMN+CELL                                                                       
  zhang san                    column=contact:email, timestamp=1355938162012, value=z3@gmail.com                 
  zhang san                    column=contact:tel, timestamp=1355938151070, value=13000000000                    
  zhang san                    column=name:first, timestamp=1355938132910, value=zhang                           
  zhang san                    column=name:last, timestamp=1355938142305, value=san                              

1 row(s) in 0.1160 seconds

 

 


-- list所有表
hbase(main):015:0> list
 TABLE                                                                                                           
 stu                                                                                                             

1 row(s) in 0.2420 seconds

 


-- disable表

hbase(main):016:0> disable 'stu'
 0 row(s) in 2.2600 seconds

 


-- 删除表

hbase(main):017:0> drop 'stu'
 0 row(s) in 1.2360 seconds

 hbase(main):018:0>

---------------------------------------------------------
HBase新建一个case_info表

create 'case_info', {NAME=>'case_id'}, {NAME=>'case_name'} 或 create 'case_info', 'case_id', 'case_name'

查看表结构

describe 'case_info'

当想往case_info表中增加字段时,发现报错了。后来发现修改表结构需要先disable它,改完再enable

disable 'case_info'

alter 'case_info', {NAME=>'case_no'}  或  alter 'case_info', 'case_no'

enable 'case_info'

往表中增加key/value时,先要有一个key,也叫row id

put 'case_info', 'row1', 'case_id', '111'

put 'case_info', 'row1', 'case_name', 'test case 1'

put 'case_info', 'row1', 'case_name:2', 'test case 1 addtional info'

查看表全部内容

scan 'case_info'

内容太多的话,按row id查看

get 'case_info', 'row1'

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值