下面我们看看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.查询hbase版本

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常用操作的更多相关文章

  1. Hbase常用操作记录

    Hbase常用操作记录 Hbase 创建表 查看表结构 修改表结构 删除表 创建表 语法:create <table>, {NAME => <family>, VERSI ...

  2. Hbase常用操作(增删改查)

    Hbase常用操作(增删改查) [日期:2014-01-03] 来源:Linux社区  作者:net19880504 [字体:大 中 小]     运行Eclipse,创建一个新的Java工程“HBa ...

  3. HBase常用操作之namespace

    1.介绍 在HBase中,namespace命名空间指对一组表的逻辑分组,类似RDBMS中的database,方便对表在业务上划分.Apache HBase从0.98.0, 0.95.2两个版本开始支 ...

  4. HBase常用操作-HBaseUtil

    package com.zhen.hbase; import java.io.IOException; import java.util.ArrayList; import java.util.Col ...

  5. HBASE常用操作增删改查

    http://javacrazyer.iteye.com/blog/1186881 http://www.cnblogs.com/invban/p/5667701.html

  6. Hbase到Solr同步常用操作

    Hbase到Solr同步常用操作 1. 整体流程 2. 常用操作 Hbase常用操作 Solr常用操作 hbase-index常用操作 3. 其他资料 Lily HBase Indexer使用整理 h ...

  7. HBase Shell操作

    Hbase 是一个分布式的.面向列的开源数据库,其实现是建立在google 的bigTable 理论之上,并基于hadoop HDFS文件系统.     Hbase不同于一般的关系型数据库(RDBMS ...

  8. HBase常用操作命令

    HBase常用操作命令 1.进入HBase脚本客户端 #hbase shell #进入HBase脚本客户端 > whoami    #查看当前登录用户 > status           ...

  9. HBase伪分布式安装(HDFS)+ZooKeeper安装+HBase数据操作+HBase架构体系

    HBase1.2.2伪分布式安装(HDFS)+ZooKeeper-3.4.8安装配置+HBase表和数据操作+HBase的架构体系+单例安装,记录了在Ubuntu下对HBase1.2.2的实践操作,H ...

随机推荐

  1. 简化的nginx多进程模型demo

    //version 1:以下代码仅演示nginx多进程模型[test@vm c]$ cat mynginx.c#include <stdio.h> #include <string. ...

  2. Android模拟器genymotion安装与eclipse 插件安装

    推荐一款Android模拟器"Genymotion",有点速度快,占用资源少,可整合eclipse.闲话少谈,看安装步骤. 1.下载地址:https://www.genymotio ...

  3. android.os.NetworkOnMainThreadException 在4.0之后谷歌强制要求连接网络不能在主线程进行访问

    谷歌在4.0系统以后就禁止在主线程中进行网络访问了,原因是: 主线程是负责UI的响应,如果在主线程进行网络访问,超过5秒的话就会引发强制关闭, 所以这种耗时的操作不能放在主线程里.放在子线程里,而子线 ...

  4. 初窥struts2(二)OGNL表达式

    Struts2总结 Struts2完整的处理流程: 1  客户端发送请求,交给struts2控制器(StrutsPrepareAndExecuteFilter). 2  Filter控制器进行请求过滤 ...

  5. Web分析日志

    http://www.docin.com/p-649515490.html http://wenku.baidu.com/link?url=kB-83fbl1Zc3Y6U2BYLj-lKMWShe8Z ...

  6. Android Broadcaset 简介

    在Android中,Broadcast是一种广泛运用的在应用程序之间传输信息的机制.而BroadcastReceiver是对发送出来的Broadcast进行过滤接收并响应的一类组件.可以使用Broad ...

  7. 话说python

    前几年就职于一个大的软件公司时,开发过程中,有一个流程化的步骤要做,就是要由一个excel文档导出生成一堆sql语句.当时使用一个高手写的代码,只不过有限几行代码(应该不到100行),就完美实现此功能 ...

  8. 男装电商Bonobos融资5500万美元,计划IPO,全靠体验店战略 - 国外 - 快鲤鱼

    男装电商Bonobos融资5500万美元,计划IPO,全靠体验店战略 - 国外 - 快鲤鱼 男装电商Bonobos融资5500万美元,计划IPO,全靠体验店战略

  9. W3C词汇和术语表

    以A字母开头的词汇 英文 中文 abstract module 抽象模组 access 访问.存取 access control 存取控制 access control information 存取控 ...

  10. win7安装ruby on rails

    开发机:win7 旗舰版 - 64位 1,安装ruby,下载rubyinstaller-2.0.0-p451.exe 下载地址:http://rubyinstaller.org/downloads/ ...