HBase基本操作

使用HBase shell进入HBase命令行,之后在hbase命令提示符下:

1.help查看所有支持的命令
 
2.直接输入命令,可以查看该命令的使用方法,如
 
   hbase(main):018:0>create
 
3 .创建表:create ‘wxy:test’, 'cf' (wxy为表空间,test为表名,cf为列族的名称)
          create ‘wxy:test’, {NAME=>'cf', VERSION=>3}, {NAME=>'cf2'},
 
4.查看所有的表:list
 
5.查看表结构: descibe ‘wxy:test’
 
6.增加/删除一个列族:disable 'wxy:test'
               alter 'wxy:test','cf2'
               enable 'wxy:test'
 
               disable 'wxy:test'
                alter 'wxy:test',{NAME=>'cf2',METHOD=>'delete'}
                enable 'wxy:test'
7.修改表的结构:
  • 对列族的修改跟创建时类似(参看alter的帮助:Column families work in a similar way as the 'create' command)   
         alter 'wxy:test',{NAME => 'cf',VERSIONS => 2}   #--对列族cf增加对历史版本的支持
         alter 'wxy:test',{NAME => 'f1', VERSIONS => 5}  #--创建新的列族f1
         alter 'wxy:test, {}NAME => 'f1', METHOD => 'delete' } #--删除列族f1
 
8.查看一个表是否存在: exists ‘wxy:test’
 
9.查看表是否可以修改:is_enabled 'wxy:test'
 
10.删除某张表: disable 'wxy:test'
               drop 'wxy:test'
               enable 'wxy:test'
 
11.向表中插入/更新数据:put  'wxy:test','rk1','cf:name','zhangsan'  #--列可以事先不存在,直接put即可,update数据也                                                                   #是put,只要行健和列相同即可
                      put  'wxy:test','rk1','cf:sex','female'
                      put  'wxy:test','rk1','cf:name','zhangsan2' #-更新数据
                      put  'wxy:test','rk1','cf:name','zhangsan3' #-更新数据
                      put  'wxy:test','rk1','cf:name','zhangsan4' #-更新数据
12.删除表中数据:delete 'wxy:test','rk1'
                delete 'wxy:test','rk1','cf'
 
13.get获取数据:(通过rowkey访问)
                    get 'wxy:test','rk1'
                get 'wxy:test','rk1','cf'
                get 'wxy:test','rk1','cf','cf2'
                 get 'wxy:test','rk1','cf:name'
 
14.scan获取表的数据(可以不通过rowkey访问):
                      scan 'wxy:test'
                      scan  'wxy:test',{LIMIT=>3}
                     scan  'wxy:test',{STARTROW=>'rk1',LIMIT=>3}
                       scan  'wxy:test',{COLUMNS=>'cf:name'}
 
默认情况下用scan获取只能获取最新数据,如果想看历史数据,需要打开RAW属性{RAW=>TRUE}
                    scan 'wxy:test',{RAW=>true,VERSIONS=>3}
 
15.统计表的行数: count  'wxy:test'
 
16.清空表:truncate  'wxy:test'                          
                           
posted on 2018-01-19 21:58  yanzibuaa  阅读(284)  评论(0编辑  收藏  举报