shell 命令行中操作HBase數(shù)據(jù)庫
Shell控制
進入到shell命令行界面,執(zhí)行hbase命令,并附加shell關(guān)鍵字:
[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>
雖然成功登錄進去了,可是我們也不知道現(xiàn)在能做什么,也不了解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 .................. ..................
幫助信息果然有幫助,通過輸出的信息,我們大致了解能夠做什么??梢钥吹絟base中也是分有ddl/dml這類語句,此外還有與復(fù)制相關(guān)的,與管理相關(guān)的命令等等。
先來試試通用(general)命令,查詢狀態(tài):
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的山寨產(chǎn)品,盡管沒名山寨到名字,但山寨到了精髓,從設(shè)計上來說,它也不需要分庫,甚至不需要分表,所有數(shù)據(jù)放到同一張表中也是可以的,這就是真正的BigTable嘛。
創(chuàng)建表對象:
hbase(main):005:0> create ¨t¨,¨t_id¨,¨t_vl¨ 0 row(s) in 2.3490 seconds
HBase中創(chuàng)建對象的語法比較靈活,前面這個示例是簡寫法,其功能等效于完整寫法,"hbase> create ¨t¨, {NAME => ¨t_id¨}, {NAME => ¨t_vl¨}",第一個參數(shù)用于指定表名,后面跟的所有參數(shù)都是列族的名稱。每個表的列族需要在表創(chuàng)建時定義好(盡管后期也可以修改,但最好一開始就定義好),從這個角度來看,HBase中的對象是結(jié)構(gòu)化的。
查看表對象:
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
新聞熱點
疑難解答
圖片精選