首页 > 网站 > 建站经验 > 正文

shell 命令行中操作HBase数据库实例详解

2019-11-02 16:34:23
字体:
来源:转载
供稿:网友

 shell 命令行中操作HBase数据库

Shell控制

进入到shell命令行界面,执行hbase命令,并附加shell关键字: 

[grid@hdnode3 ~]$ hbase shell HBase Shell; enter ¨help¨ for list of supported commands. Type "exit" to leave the HBase Shell Version 0.90.5, r1212209, Fri Dec 9 05:40:36 UTC 2011  hbase(main):001:0> 

 虽然成功登录进去了,可是我们也不知道现在能做什么,也不了解SHELL下都有哪些命令。这个时候,我们可以选择,去看官方文档中的说明,或者,敲个help上去看看。

  hbase(main):002:0> help .................. .................. 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 .................. ..................

 帮助信息果然有帮助,通过输出的信息,我们大致了解能够做什么。可以看到hbase中也是分有ddl/dml这类语句,此外还有与复制相关的,与管理相关的命令等等。 

先来试试通用(general)命令,查询状态:

 hbase(main):003:0> status 5 servers, 0 dead, 0.4000 average load

查询版本:

  hbase(main):004:0> version 0.90.5, r1212209, Fri Dec 9 05:40:36 UTC 2011

接下来重点项,DDL和DML(想不到HBase也分了DML/DDL语句)。HBase中没有库的概念,做为BigTable的山寨产品,尽管没名山寨到名字,但山寨到了精髓,从设计上来说,它也不需要分库,甚至不需要分表,所有数据放到同一张表中也是可以的,这就是真正的BigTable嘛。 

创建表对象:

  hbase(main):005:0> create ¨t¨,¨t_id¨,¨t_vl¨ 0 row(s) in 2.3490 seconds

 HBase中创建对象的语法比较灵活,前面这个示例是简写法,其功能等效于完整写法,"hbase> create ¨t¨, {NAME => ¨t_id¨}, {NAME => ¨t_vl¨}",第一个参数用于指定表名,后面跟的所有参数都是列族的名称。每个表的列族需要在表创建时定义好(尽管后期也可以修改,但最好一开始就定义好),从这个角度来看,HBase中的对象是结构化的。

 查看表对象:

  hbase(main):006:0> list TABLE                                                                                   t                                                                                     1 row(s) in 0.0080 seconds hbase(main):018:0> describe ¨t¨ DESCRIPTION                                                 ENABLED                           {NAME => ¨t¨, FAMILIES => [{NAME => ¨t_id¨, BLOOMFILTER => ¨NONE¨, REPLICATION_SCOPE => ¨0¨, COMPRESSION => true                              ¨NONE¨, VERSIONS => ¨3¨, TTL => ¨2147483647¨, BLOCKSIZE => ¨65536¨, IN_MEMORY => ¨false¨, BLOCKCACHE => ¨t                               rue¨}, {NAME => ¨t_vl¨, BLOOMFILTER => ¨NONE¨, REPLICATION_SCOPE => ¨0¨, COMPRESSION => ¨NONE¨, VERSIONS =>                                ¨3¨, TTL => ¨2147483647¨, BLOCKSIZE => ¨65536¨, IN_MEMORY => ¨false¨, BLOCKCACHE => ¨true¨}]}                                      1 row(s) in 0.0100 seconds
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表