hbase快速入门--shell 交互


HBase提供了丰富的访问接口。
• HBase Shell
• Java clietn API
• Jython、Groovy DSL、Scala
• REST
• Thrift(Ruby、Python、Perl、C++…)
• MapReduce
• Hive/Pig



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



3.列出所有的表
hbase(main):028:0>list
TABLE                                                                                       

                                                              
member                                                                                      

                                                              
temp_table                                                                                  

                                                              
2 row(s) in 0.0150seconds


4.查询表是否存在
hbase(main):021:0>exists 'member'
Table member doesexist                                                                      

                                                             
0 row(s) in 0.1610seconds

5.判断表是否enable
hbase(main):034:0>is_enabled 'member'
true                                                                                        

                                                              
0 row(s) in 0.0110seconds

6.判断表是否disable
hbase(main):032:0>is_disabled 'member'
false                                                                                       

                                                              
0 row(s) in 0.0110seconds

7.查询表中有多少行:
hbase(main):019:0>count 'member'                                       
2 row(s) in 0.0160seconds



8.获取当前count的值
hbase(main):069:0>get_counter 'member','xiaofeng','info:age'
COUNTER VALUE = 2





创建表
> create 'blog','article','author'
知识点回顾:Column Family是schema的一部分,而Column不是。这里的article和author是Column Family。

增加记录
>put 'blog','1','article:title,' Head First HBase '
>put 'blog','1','article:content','HBase is the Hadoop database. Use it when you need random, realtime read/write access to your Big Data.'
> put 'blog','1','article:tags','Hadoop,HBase,NoSQL'
> put 'blog','1','author:name','hujinjun'
> put 'blog','1','author:nickname',’一叶渡江’
知识点回顾:Column完全动态扩展,每行可以有不同的Columns。



根据RowKey查询
> get 'blog','1'
知识点回顾:HTable按RowKey字典序(1,10,100,11,2)自动排序,每行包含任意数量
的Columns,
Columns ColumnKey(article:content,article:tags,article:title,author:name,
author:nickname)自动排序


更新练习
查询下更新前的值:
> get ‘blog’,’1’,’author:nickname’
更新nickname为’yedu’:
> put ‘blog’,’1’,’ahthor:nickname’,’yedu’
查询更新后的结果:
> get ‘blog’,’1’,’author:nickname’
知识点回顾:查询默认返回最近的值。
查询nickname的多个(本示例为2个)版本值
> get 'blog','1',{COLUMN => 'author:nickname',VERSIONS => 2}
知识点回顾:每个Column可以有任意数量的Values,按Timestamp倒序自动排序。
如何只查询到以前的旧版本呢,需要借助Timestamp
>get 'blog','1',{COLUMN => 'author:nickname', TIMESTAMP => 1317180070811}
知识点回顾:TabelName+RowKey+Column+Timestamp=>Value


删除记录
delete只能删除一个column
>delete 'blog','1','author:nickname'
删除RowKey的所有column用deleteall
>deleteall ‘blog’,’1’


删除表
练习完毕,把练习表删了吧,删除之前需要先disable
>disable ‘blog’
>drop ‘blog’




你可能感兴趣的:(hadoop,shell,NoSQL,hbase)