`
longzhun
  • 浏览: 371770 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Hbase总结(一)-hbase命令

 
阅读更多

下面我们看看HBase Shell的一些基本操作命令,我列出了几个常用的HBase Shell命令,如下:

名称

命令表达式

创建表

create '表名称', '列名称1','列名称2','列名称N'

添加记录      

put '表名称', '行名称', '列名称:', '值'

查看记录

get '表名称', '行名称'

查看表中的记录总数

count  '表名称'

删除记录

delete  '表名' ,'行名称' , '列名称'

删除一张表

先要屏蔽该表,才能对该表进行删除,第一步 disable '表名称' 第二步  drop '表名称'

查看所有记录

scan "表名称"  

查看某个表某个列中所有数据

scan "表名称" , ['列名称:']

更新记录 

就是重写一遍进行覆盖

 

下面是一些常见命令的说明,在hbaseshell中输入help的帮助信息,在本文中,我们先介绍前3个,后面2个,将在下一篇博文中介绍。

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

  

一、一般操作

1.查询服务器状态

hbase(main):024:0>status

3 servers, 0 dead,1.0000 average load

 

2.查询hive版本

 

hbase(main):025:0>version

0.90.4, r1150278,Sun Jul 24 15:53:29 PDT 2011

 

二、DDL操作

 

1.创建一个表

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

0 row(s) in 1.2210seconds

 

2.获得表的描述

hbase(main):012:0>list

TABLE                                                                                                                                                       

member                                                                                                                                                      

1 row(s) in 0.0160seconds

hbase(main):006:0>describe 'member'

DESCRIPTION                                                                                          ENABLED                                               

 {NAME => 'member', FAMILIES => [{NAME=> 'address', BLOOMFILTER => 'NONE', REPLICATION_SCOPE => '0', true                                                 

  VERSIONS => '3', COMPRESSION => 'NONE',TTL => '2147483647', BLOCKSIZE => '65536', IN_MEMORY => 'fa                                                       

 lse', BLOCKCACHE => 'true'}, {NAME =>'info', BLOOMFILTER => 'NONE', REPLICATION_SCOPE => '0', VERSI                                                       

 ONS => '3', COMPRESSION => 'NONE', TTL=> '2147483647', BLOCKSIZE => '65536', IN_MEMORY => 'false',                                                        

 BLOCKCACHE => 'true'}]}                                                                                                                                    

1 row(s) in 0.0230seconds

 

3.删除一个列族,alter,disable,enable

我们之前建了3个列族,但是发现member_id这个列族是多余的,因为他就是主键,所以我们要将其删除。

hbase(main):003:0>alter 'member',{NAME=>'member_id',METHOD=>'delete'}

 

ERROR: Table memberis enabled. Disable it first before altering.

 

报错,删除列族的时候必须先将表给disable掉。

hbase(main):004:0>disable 'member'                                  

0 row(s) in 2.0390seconds

hbase(main):005:0>alter'member',{NAME=>'member_id',METHOD=>'delete'}

0 row(s) in 0.0560seconds

hbase(main):006:0>describe 'member'

DESCRIPTION                                                                                          ENABLED                                               

 {NAME => 'member', FAMILIES => [{NAME=> 'address', BLOOMFILTER => 'NONE', REPLICATION_SCOPE => '0',false                                                 

  VERSIONS => '3', COMPRESSION => 'NONE',TTL => '2147483647', BLOCKSIZE => '65536', IN_MEMORY => 'fa                                                       

 lse', BLOCKCACHE => 'true'}, {NAME =>'info', BLOOMFILTER => 'NONE', REPLICATION_SCOPE => '0', VERSI                                                       

 ONS => '3', COMPRESSION => 'NONE', TTL=> '2147483647', BLOCKSIZE => '65536', IN_MEMORY => 'false',                                                        

 BLOCKCACHE => 'true'}]}                                                                                                                                    

1 row(s) in 0.0230seconds

该列族已经删除,我们继续将表enable

hbase(main):008:0> enable 'member'  

0 row(s) in 2.0420seconds

 

4.列出所有的表

hbase(main):028:0>list

TABLE                                                                                                                                                       

member                                                                                                                                                      

temp_table                                                                                                                                                  

2 row(s) in 0.0150seconds

 

 

5.drop一个表

hbase(main):029:0>disable 'temp_table'

0 row(s) in 2.0590seconds

 

hbase(main):030:0>drop 'temp_table'

0 row(s) in 1.1070seconds

 

 

6.查询表是否存在

hbase(main):021:0>exists 'member'

Table member doesexist                                                                                                                                     

0 row(s) in 0.1610seconds

 

7.判断表是否enable

hbase(main):034:0>is_enabled 'member'

true                                                                                                                                                        

0 row(s) in 0.0110seconds

 

8.判断表是否disable

hbase(main):032:0>is_disabled 'member'

false                                                                                                                                                       

0 row(s) in 0.0110seconds

 

 

 

三、DML操作

 

 

1.插入几条记录

put'member','scutshuxue','info:age','24'

put'member','scutshuxue','info:birthday','1987-06-17'

put'member','scutshuxue','info:company','alibaba'

put'member','scutshuxue','address:contry','china'

put'member','scutshuxue','address:province','zhejiang'

put'member','scutshuxue','address:city','hangzhou'

 

 

put'member','xiaofeng','info:birthday','1987-4-17'

put'member','xiaofeng','info:favorite','movie' 

put'member','xiaofeng','info:company','alibaba'

put'member','xiaofeng','address:contry','china'

put'member','xiaofeng','address:province','guangdong'

put'member','xiaofeng','address:city','jieyang'

put'member','xiaofeng','address:town','xianqiao'

 

 

 

2.获取一条数据

获取一个id的所有数据

hbase(main):001:0>get 'member','scutshuxue'

COLUMN                                   CELL                                                                                                               

 address:city                           timestamp=1321586240244, value=hangzhou                                                                            

 address:contry                         timestamp=1321586239126, value=china                                                                               

 address:province                       timestamp=1321586239197, value=zhejiang                                                                            

 info:age                               timestamp=1321586238965, value=24                                                                                  

 info:birthday                          timestamp=1321586239015, value=1987-06-17                                                                          

 info:company                           timestamp=1321586239071, value=alibaba                                                                             

6 row(s) in 0.4720seconds

 

获取一个id,一个列族的所有数据

hbase(main):002:0>get 'member','scutshuxue','info'

COLUMN                                   CELL                                                                                                               

 info:age                               timestamp=1321586238965, value=24                                                                                  

 info:birthday                          timestamp=1321586239015, value=1987-06-17                                                                          

 info:company                           timestamp=1321586239071, value=alibaba                                                                             

3 row(s) in 0.0210seconds

 

获取一个id,一个列族中一个列的所有数据

hbase(main):002:0>get 'member','scutshuxue','info:age' 

COLUMN                                   CELL                                                                                                               

 info:age                               timestamp=1321586238965, value=24                                                                                  

1 row(s) in 0.0320seconds

 

 

6.更新一条记录

将scutshuxue的年龄改成99

hbase(main):004:0>put 'member','scutshuxue','info:age' ,'99'

0 row(s) in 0.0210seconds

 

hbase(main):005:0>get 'member','scutshuxue','info:age' 

COLUMN                                   CELL                                                                                                               

 info:age                               timestamp=1321586571843, value=99                                                                                  

1 row(s) in 0.0180seconds

 

 

3.通过timestamp来获取两个版本的数据

hbase(main):010:0>get 'member','scutshuxue',{COLUMN=>'info:age',TIMESTAMP=>1321586238965}

COLUMN                                   CELL                                                                                                               

 info:age                               timestamp=1321586238965, value=24                                                                                  

1 row(s) in 0.0140seconds

 

hbase(main):011:0>get 'member','scutshuxue',{COLUMN=>'info:age',TIMESTAMP=>1321586571843}

COLUMN                                   CELL                                                                                                               

 info:age                               timestamp=1321586571843, value=99                                                                                  

1 row(s) in 0.0180seconds

 

 

4.全表扫描:

hbase(main):013:0>scan 'member'

ROW                                     COLUMN+CELL                                                                                                        

 scutshuxue                             column=address:city, timestamp=1321586240244, value=hangzhou                                                       

 scutshuxue                             column=address:contry, timestamp=1321586239126, value=china                                                        

 scutshuxue                             column=address:province, timestamp=1321586239197, value=zhejiang                                                   

 scutshuxue                              column=info:age,timestamp=1321586571843, value=99                                                                 

 scutshuxue                             column=info:birthday, timestamp=1321586239015, value=1987-06-17                                                    

 scutshuxue                             column=info:company, timestamp=1321586239071, value=alibaba                                                        

 temp                                   column=info:age, timestamp=1321589609775, value=59                                                                 

 xiaofeng                               column=address:city, timestamp=1321586248400, value=jieyang                                                        

 xiaofeng                               column=address:contry, timestamp=1321586248316, value=china                                                        

 xiaofeng                               column=address:province, timestamp=1321586248355, value=guangdong                                                  

 xiaofeng                               column=address:town, timestamp=1321586249564, value=xianqiao                                                       

 xiaofeng                               column=info:birthday, timestamp=1321586248202, value=1987-4-17                                                     

 xiaofeng                               column=info:company, timestamp=1321586248277, value=alibaba                                                        

 xiaofeng                               column=info:favorite, timestamp=1321586248241, value=movie                                                         

3 row(s) in 0.0570seconds

 

5.删除id为temp的值的‘info:age’字段

hbase(main):016:0>delete 'member','temp','info:age'

0 row(s) in 0.0150seconds

hbase(main):018:0>get 'member','temp'

COLUMN                                   CELL                                                                                                               

0 row(s) in 0.0150seconds

 

 

6.删除整行

 

hbase(main):001:0>deleteall 'member','xiaofeng'

0 row(s) in 0.3990seconds

 

7.查询表中有多少行:

hbase(main):019:0>count 'member'                                        

2 row(s) in 0.0160seconds

 

8.给‘xiaofeng’这个id增加'info:age'字段,并使用counter实现递增

hbase(main):057:0*incr 'member','xiaofeng','info:age'                    

COUNTER VALUE = 1

 

hbase(main):058:0>get 'member','xiaofeng','info:age' 

COLUMN                                   CELL                                                                                                               

 info:age                               timestamp=1321590997648, value=\x00\x00\x00\x00\x00\x00\x00\x01                                                    

1 row(s) in 0.0140seconds

 

hbase(main):059:0>incr 'member','xiaofeng','info:age'

COUNTER VALUE = 2

 

hbase(main):060:0>get 'member','xiaofeng','info:age' 

COLUMN                                   CELL                                                                                                               

 info:age                               timestamp=1321591025110, value=\x00\x00\x00\x00\x00\x00\x00\x02                                                    

1 row(s) in 0.0160seconds

 

获取当前count的值

hbase(main):069:0>get_counter 'member','xiaofeng','info:age' 

COUNTER VALUE = 2

  

9.将整张表清空:

hbase(main):035:0>truncate 'member'

Truncating 'member'table (it may take a while):

 - Disabling table...

 - Dropping table...

 - Creating table...

0 row(s) in 4.3430seconds

可以看出,hbase是先将掉disable掉,然后drop掉后重建表来实现truncate的功能的。

分享到:
评论

相关推荐

    hbase的hbase-1.2.0-cdh5.14.2.tar.gz资源包

    HBase是Apache Hadoop生态系统中的一个分布式、高性能、版本化、列族式数据库,它提供了对大规模数据集的实时访问。HBase设计用于处理PB级的数据,并且可以在数千台服务器上扩展。`hbase-1.2.0-cdh5.14.2.tar.gz` 是...

    hbase-1.2.1-bin.tar.gz.zip

    HBase,全称为Hadoop Distributed File System上的基础结构(HBase on Hadoop Distributed File System),是一种分布式的、面向列的开源数据库,它构建在Apache Hadoop文件系统(HDFS)之上,提供高可靠性、高性能...

    hbase-2.4.17-bin 安装包

    总结来说,HBase-2.4.17-bin安装包提供了一个强大且高效的NoSQL数据库,适合大数据场景下的实时读写操作。通过理解并掌握上述概念、安装步骤及操作方法,用户可以有效地利用HBase处理海量数据。

    hbase-1.3.1-bin.tar.gz.7z

    总结来说,安装和配置HBase 1.3.1在Linux的CentOS 6.8系统上,需要正确设置环境变量、依赖项,以及正确配置HBase与Hadoop的集成。这不仅涉及基本的安装步骤,还包括对Hadoop环境的理解和HBase的高级配置,使得大数据...

    hbase-1.4.10-bin.tar.gz

    解压完成后,将HBase的bin目录添加到系统的PATH环境变量中,以便于执行HBase命令: ```bash export PATH=$PATH:/path/to/hbase-1.4.10/bin ``` 配置HBase需要修改`conf/hbase-site.xml`文件。创建一个新文件或根据...

    hbase hbck2修复工具hbase-operator-tools-1.0.0.1.0.0.0-618-bin.tar.gz

    hbase hbck2修复工具hbase-operator-tools-1.0.0.1.0.0.0-618-bin.tar.gz,hbase1版本的hbck已经不支持修复命令,hbase2.1版本需要用这个新版的工具

    hbase-1.2.6-bin.tar.gz

    2. 解压HBase:使用tar命令解压"hbase-1.2.6-bin.tar.gz"到指定目录。 3. 配置环境变量:修改系统环境变量,添加HBase的bin目录到PATH。 4. 修改配置文件:如hbase-site.xml,设置HBase的主节点地址、ZooKeeper地址...

    hbase-1.1.5-bin.tar

    2. **环境配置**:解压`hbase-1.1.5-bin.tar`后,你需要将HBase的bin目录添加到系统的PATH环境变量中,以便在命令行中直接运行HBase命令。 3. **配置文件**:HBase的主要配置文件是`conf/hbase-site.xml`。在这里,...

    hbase2.x-hbck2 jar包及测试命令

    - `hbase hbck2 -details`: 这个命令将执行一个全面的检查,显示每个Region的状态、存储文件、 RegionServer上的位置等详细信息。 2. **修复不一致性**: - `hbase hbck2 -fixAssignments`: 如果发现Region未正确...

    hbase-1.6.0-bin.tar.gz

    7. **HBase Shell增强**:HBase Shell是管理系统的重要工具,1.6.0版本增强了Shell命令的功能,添加了更多实用操作,如批量修改表属性、检查Region状态等。 8. **与其他组件的集成**:HBase 1.6.0可以很好地与...

    hbase-0.94.16-security.tar.gz

    安装HBase 0.94.16-security,首先需要解压下载的".tar.gz"文件,通常在命令行中使用"tar -zxvf hbase-0.94.16-security.tar.gz"命令。解压后,将HBase的配置文件如"conf/hbase-site.xml"进行适当修改,设置Hadoop的...

    hbase-2.1.1-bin.tar.gz

    - 启动HBase,执行`start-hbase.sh`,检查`jps`命令确认HMaster和HRegionServer是否正常启动。 5. **使用HBase** - 使用HBase shell,一个交互式的命令行工具,执行增删改查操作。 - 通过Java API或者HBase的...

    apache-phoenix-4.8.1-HBase-1.2-bin.tar.gz

    Apache Phoenix 是一个开源的SQL-on-HBase框架,它允许用户通过标准的JDBC接口与HBase进行交互,极大地简化了对大数据存储系统的SQL查询。在标题"apache-phoenix-4.8.1-HBase-1.2-bin.tar.gz"中,我们可以看到这是...

    hbase-0.98.6-cdh5.3.6.zip

    11. **Shell命令**:HBase提供了一个命令行接口(Shell),用户可以通过Shell执行各种管理和操作命令,如创建表、插入数据、查询数据等。 12. **监控与管理**:CDH 5.3.6提供了Web UI界面,用户可以直观地监控HBase...

    hbase-hbck2-1.2.0-SNAPSHOT.jar

    HBCK是HBase1.x中的命令,到了HBase2.x中,HBCK命令不适用,且它的写功能(-fix)已删除; HBCK2已经被剥离出HBase成为了一个单独的项目,如果你想要使用这个工具,需要根据自己HBase的版本,编译源码。其GitHub地址...

    hbase-2.2.4-bin-for-hadoop3.tar.gz

    4. 启动HBase:完成配置后,启动HBase的Master和RegionServer进程,可以使用`start-hbase.sh`命令。 5. 测试运行:通过HBase Shell或者应用程序进行简单的CRUD操作,验证HBase是否正常运行。 需要注意的是,Hadoop...

    hbase-1.2.7-bin.tar.gz

    总结来说,“hbase-1.2.7-bin.tar.gz”是一个完整的HBase发行版,它提供了在分布式环境下存储和管理大规模结构化数据的能力。通过理解其核心概念和工作原理,以及掌握安装和使用方法,我们可以有效地利用HBase处理...

    hbase_0.98.13-hadoop2-bin.tar.gz

    总结,HBase 0.98.13-hadoop2是大数据环境下的一款强大工具,适合处理大规模、实时的数据。通过理解其原理、正确安装配置,并结合Hadoop进行实践,你可以掌握这一重要的数据存储技术,为你的项目或研究提供有力支撑...

    hbase-1.4.6-bin.tar.gz

    4. 启动HBase,使用bin/start-hbase.sh命令。 5. 使用hbase shell或HBase API进行数据操作。 HBase的使用不仅限于Java,还支持多种编程语言的客户端,如Python、PHP、Ruby等,方便开发者根据项目需求选择合适的方式...

    hbase-1.0.2-bin

    HBase是Apache软件基金会的一个开源分布式数据库,它是基于Google的Bigtable设计模型构建的,专为处理海量数据而设计。在Linux环境中,安装HBase 1.0.2通常包括以下几个步骤: 1. **下载与解压**:首先,你需要从...

Global site tag (gtag.js) - Google Analytics