hbase之 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
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的功能的。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/31383567/viewspace-2145955/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- hbase - [03] 客戶端常用命令(hbase shell)客戶端
- hbase基本概念和hbase shell常用命令用法
- Hbase shell 常用命令1
- Hbase shell 常用命令筆記筆記
- hbase shell常用命令總結
- HBase 系列(五)——HBase常用 Shell 命令
- hbase shell命令
- HBase 常用Shell命令
- Hbase - 常用命令
- Hbase shell的基本操作
- HBASE的SHELL命令操作
- HBase shell 命令介紹
- hbase shell 基本操作命令
- HBase的常用命令
- HBase shell詳細操作指南
- Hbase快速開始——shell操作
- NoSQL之HBaseSQL
- hbase shell - 使用filter進行scanFilter
- Hbase(二)Hbase常用操作
- HBase 教程:什麼是 HBase?
- HBase篇--HBase常用優化優化
- hbase - [04] java訪問hbaseJava
- HBase
- [ 轉載 ] HBASE啟動指令碼/Shell解析指令碼
- shell命令列中操作HBase資料庫命令列資料庫
- HBase篇--HBase操作Api和Java操作Hbase相關ApiAPIJava
- HBase (三)之 API的使用API
- HBase學習之Hbase的邏輯結構和物理結構
- Hbase單機部署 java連線HbaseJava
- Hbase篇--Hbase和MapReduce結合ApiAPI
- HBase框架框架
- Hbase原理
- HBase初探
- HBase篇--搭建HBase完全分散式叢集分散式
- hbase與phoenix整合(使用phoenix操作hbase資料)
- HBase實操:HBase-Spark-Read-Demo 分享Spark
- HBase學習之二: hbase分頁查詢
- Hbase優化優化