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

Hbase shell

阅读更多

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

 

名称

命令表达式

创建表

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

添加记录      

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

查看记录

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

查看表中的记录总数

count  '表名称'

删除记录

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

删除一张表

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

查看所有记录

scan "表名称"  

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

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

更新记录 

就是重写一遍进行覆盖

 

一、一般操作

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

  create 'mytable', {NAME => 'colfam1', VERSIONS => 5,
MIN_VERSIONS => '1'}

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

 hbase(main):150:0> scan 'mytable',{VERSIONS=>4}
ROW                      COLUMN+CELL                                                       
 yu                      column=colfam1:name, timestamp=1405997953034, value=yuqian1       
 yu                      column=colfam1:name, timestamp=1405997945522, value=yuqian        
1 row(s) in 0.0140 seconds

 hbase(main):157:0> scan 'mytable', {COLUMN => 'colfam1:name', VERSIONS => 2}
ROW                      COLUMN+CELL                                                       
 yu                      column=colfam1:name, timestamp=1405997953034, value=yuqian1       
 yu                      column=colfam1:name, timestamp=1405997945522, value=yuqian        
1 row(s) in 0.0170 seconds

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的功能的。

 

10.查看meta表

scan 'hbase:meta'

 

分享到:
评论

相关推荐

    hbase shell操作指南

    HBase shell是一个命令行工具,它允许用户以交互的方式运行HBase的命令,如建表、插入数据、数据查询等操作。 1. 进入HBase Shell 要进入HBase Shell,首先需要确认HBase服务已经启动。然后切换到HBase的安装目录,...

    hbase-shell批量命令执行脚本的方法

    批量执行hbase shell 命令 #!/bin/bash source /etc/profile exec $HBASE_HOME/bin/hbase shell <<EOF truncate 'tracker_total_apk_fact_zyt' major_compact('t_abc') disable 't_abc' drop 't_abc' create...

    hbase shell常用命令汇总

    ### HBase Shell 常用命令详解 #### 一、HBase Shell 概述 HBase Shell 是一个基于命令行的工具,用于与HBase进行交互。它提供了一系列丰富的命令来执行基本的数据管理任务,例如创建表、插入数据、查询数据等。...

    nosql实验四-HBaseShell API操作.docx

    HBase Shell API 操作详解 HBase 是一个基于分布式文件系统的 NoSQL 数据库,提供了丰富的 API 来进行数据操作。在本实验中,我们将使用 HBase Shell API 来实现基本的数据操作,包括创建表、查看所有表、插入数据...

    hbase shell

    ### HBase Shell 命令详解 #### 一、概述 HBase Shell 是一个命令行工具,用于与 HBase 数据库进行交互。它提供了一系列的命令来管理表、执行数据定义语言 (DDL) 和数据操纵语言 (DML) 操作等。通过 HBase Shell,...

    HBase Shell命令大全_monday的博客-CSDN博客_hbase shell.html

    HBase Shell命令大全_monday的博客-CSDN博客_hbase shell.html

    hbase shell使用文档

    这是本人使用hbase shell的部分经验总结,一般的shell使用全部包括了。 版本,压缩,region等需求,以及使用普通shell使用hbase shell

    hbase shell常用命令

    ### HBase Shell 常用命令详解 #### 一、概述 HBase 是一个分布式的、面向列的开源数据库,其设计受到了 Google 的 Bigtable 的启发。它非常适合于非结构化数据存储,提供了高可靠性、高性能、面向列、可伸缩等特点...

    hbase的shell操作

    根据提供的文件信息,本文将详细介绍HBase的Shell操作及其应用场景,包括如何创建表、插入数据、查询数据等关键操作。 ### HBase Shell简介 HBase Shell是HBase提供的一种交互式命令行工具,用于执行HBase操作。它...

    Hbase shell常用命令.docx

    在HBase这个分布式列式数据库中,Shell是一个用于与HBase交互的命令行工具,它提供了丰富的命令来执行各种操作。以下是对HBase Shell中一些常用命令的详细说明: 1. **创建表**: `create '表名称', '列族名称 1',...

    实验手册_HbaseShell.docx

    HBase Shell 实验手册 HBase Shell 是 Hadoop 家族中的一员,它是一个基于 HBase 的 Shell 交互式命令行工具,提供了便捷的方式来管理和操作 HBase 数据库。本实验手册旨在指导用户掌握 HBase Shell 的使用,了解 ...

    HDFS_HBaseShell的常用命令

    HDFS_HBaseShell的常用命令 HDFS(Hadoop Distributed File System)是一种分布式文件系统,主要用于存储和管理大规模数据。HBase 是一个基于HDFS的NoSQL数据库,用于存储和管理大规模结构化和半结构化数据。HBase ...

    Hadoop技术-HBaseShell常用命令.pptx

    HBase Shell常用命令 HBase Shell是Hadoop技术中的一个重要组件,用于管理和操作HBase数据库。以下是HBase Shell的常用命令,分为一般操作、数据定义语言(DDL)操作和数据操作语言(DML)操作三大类。 一般操作 ...

    hbase shell命令详解

    HBase Shell是HBase提供的一个交互式命令行工具,用于管理和操作HBase数据库。在这里,我们将深入探讨HBase Shell的各种命令。 1. **创建表(create)**: 使用`create '表名', '列族'`命令来创建表,如`create '...

    Hbase shell及常用命令

    HBase shell及常用命令 HBase Shell是HBase数据库的命令行工具,用户可以使用HBase Shell与HBase进行交互。HBase Shell是一个封装了Java客户端API的JRuby应用软件,在HBase的HMaster主机上通过命令行输入hbase ...

    hbase_shell操作命令

    在HBase中,HBase Shell是一个交互式的命令行工具,用于管理和操作HBase数据库。它提供了多种命令,帮助用户执行常见的数据库操作,如创建、读取、更新和删除数据。以下是一些重要的HBase Shell操作命令及其详细说明...

    hbase_shell操作命令汇总

    在HBase中,HBase Shell是用于管理与操作HBase数据库的一个交互式命令行工具。以下是一些HBase Shell的基本操作命令的详细说明: 1. **创建表** (`create`): 使用`create`命令创建一个新的HBase表。例如: ``` ...

    hbase基本概念和hbase shell常用命令用法

    HBase Shell是HBase提供的交互式命令行工具,用于操作HBase表。以下是一些常用的HBase Shell命令: 1. **create**:创建表,如`create 'testTable', 'cf'` 创建一个名为testTable的表,包含一个列族cf。 2. **put*...

    Hbase 的shell基本操作

    下面是基于标题“Hbase的shell基本操作”和描述“hadoop集群环境下hbase的shell基本操作命令”,结合给定的部分内容,所生成的详细知识点: 1. 进入HBase命令行: 通过命令`hbase shell`可以进入HBase的命令行界面...

Global site tag (gtag.js) - Google Analytics