hbase相关操作
•发布于   •作者 心的方向  •321 次浏览  •来自 后端

    访问hbase,以及操作hbase,命令不用使用分号hbase shell 进入hbaselist 查看表hbase shell -dhbase(main):024:0> scan '.META.'
=============小例子===================================================
1. 创建一个表memberhbase(main):025:0> create 'member','m_id','address','info'2.list #查看所有表
3.查看表描述hbase(main):028:0> describe 'member'4. scan浏览表中数据scan 'member'5.删除一个列族m_id:先将表disable(如果表中之前有数据的话,会把数据清空)hbase(main):030:0> disable 'member'hbase(main):033:0> is_enabled 'member'
hbase(main):034:0> alter 'member',{NAME=>'m_id',METHOD=>'delete'}
最后enable,否则不能进行其他操作hbase(main):038:0> enable 'member'
6.插入几条记录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' 
scan 'member'

7.获取数据获取一个id的所有数据hbase(main):001:0>get 'member','scutshuxue'获取一个id,一个列族的所有数据hbase(main):002:0>get 'member','scutshuxue','info'获取一个id,一个列族中一个列的所有数据hbase(main):002:0>get 'member','scutshuxue','info:age' 通过timestamp来获取两个版本的数据hbase(main):010:0>get 'member','scutshuxue',{COLUMN=>'info:age',TIMESTAMP=>1321586238965}
8.  更新一条记录将scutshuxue的年龄改成99hbase(main):004:0>put 'member','scutshuxue','info:age' ,'99'10.查询表中有多少行:hbase(main):019:0>count 'member'  11.删除整行hbase(main):001:0>deleteall 'member','xiaofeng'12.删除id为xiaofeng的值的‘info:age’字段hbase(main):016:0>delete 'member','temp','info:age'13.给‘xiaofeng’这个id增加'info:Go'字段,并使用counter实现递增hbase(main):041:0> incr 'member','xiaofeng','info:go'连续执行incr以上,COUNTER VALUE 的值会递增,通过get_counter
获取当前count的值hbase(main):069:0>get_counter 'member','xiaofeng','info:age' hbase(main):058:0>get 'member','xiaofeng','info:go'  
获取当前count的值hbase(main):069:0>get_counter 'member','xiaofeng','info:age' 
=============================相关删除=========================1.删除一个列族:先将表disable(如果表中之前有数据的话,会把数据清空)hbase(main):030:0> disable 'member'hbase(main):033:0> is_enabled 'member'
hbase(main):034:0> alter 'member',{NAME=>'m_id',METHOD=>'delete'}
最后enable,否则不能进行其他操作hbase(main):038:0> enable 'member'2.删除整行hbase(main):001:0>deleteall 'scores','xiaofeng'3.将整张表清空:hbase(main):035:0>truncate 'scores'hbase是先将掉disable掉,然后drop掉后重建表来实现truncate的功能4.drop一个表(先disable,在drop)hbase(main):029:0>disable 'scores'hbase(main):029:0>drop 'scores'=====================基本操作===========================================1.查询表是否存在hbase(main):021:0>exists 'scores'2.判断表是否enablehbase(main):034:0>is_enabled 'scores'                                                                                       3.判断表是否disablehbase(main):032:0>is_disabled 'scores'4.列出所有的表hbase(main):028:0>list5.创建表memberhbase(main):025:0> create 'member','m_id','address','info'6.查看表描述hbase(main):028:0> describe 'member'=================查询操作================================================1.scan '表名' #查看所有数据2.get是根据主键查看一列get '表名','主键'[,'列簇名'][,'列簇名:列名']=============================================================过滤查询表的内容1.FirstKeyOnlyFilter() 得到每一行的列族info的第一个列hbase(main):002:0> scan 'student',{COLUMNS=>'info',FILTER=>"(FirstKeyOnlyFilter())"}2.查看列簇是info,LIMIT是显示的行数,STARTROW是开始行对应的是主键hbase(main):008:0> scan 'student',{COLUMNS=>['info'],LIMIT=>4,STARTROW=>'200977100710'}
3.查看列簇是info,namehbase(main):007:0> scan 'student',{COLUMNS=>['info','name'],LIMIT=>4,STARTROW=>'200977100710'}
scan 'person', {COLUMNS => ['info', 'data'], FILTER => "(QualifierFilter(=,'substring:a'))"}


HBase表重命名
hbase shell> disable 'tableName'hbase shell> snapshot 'tableName', 'tableSnapshot'hbase shell> clone_snapshot 'tableSnapshot', 'newTableName'hbase shell> delete_snapshot 'tableSnapshot'hbase shell> drop 'tableName'
disable 'stra_opr:zh_test'snapshot 'stra_opr:zh_test', 'tableSnapshot'clone_snapshot 'tableSnapshot', 'stra_opr:zh_test1'delete_snapshot 'tableSnapshot'drop 'stra_opr:zh_test'

disable 'stra_opr:RM_USER_INFO_0427'snapshot 'stra_opr:RM_USER_INFO_0427','USERTESTSnapshot'clone_snapshot 'USERTESTSnapshot','stra_opr:RM_USER_INFO_0427_clone'delete_snapshot 'USERTESTSnapshot'


disablesnapshotclone_snapshotdelete_snapshot drop 





hbase 导入导出hbase org.apache.hadoop.hbase.mapreduce.Export 'table1' /home/fred/table1hbase org.apache.hadoop.hbase.mapreduce.Import 'table1' /home/fred/table1



hbase org.apache.hadoop.hbase.mapreduce.Import ' ' 














1392368783980 1392380169184












1392368783980 1392380169184
1392383705316 1392383705316













1395978233636 1395987769587






hbase org.apache.hadoop.hbase.mapreduce.Import 'stra_opr:RM_CUSTGROUP_20170304001518999100016_DETAIL_INFO' /user/stra_opr/custgroupfilebak/20170503/RM_CUSTGROUP_20170304001518999100016_DETAIL_INFO
hbase org.apache.hadoop.hbase.mapreduce.Export 'stra_opr:RM_CHANNELTASK_INFO' /user/stra_opr/selfexport/RM_CHANNELTASK_INFO
hbase org.apache.hadoop.hbase.mapreduce.Import 'stra_opr:RM_HEXSTRINGTEST' /user/stra_opr/selfexport/RM_CHANNELTASK_INFO
scan 'stra_opr:RM_USER_INFO',{LIMIT => 1}


Conflicting modification on 2017年5月23日 上午7:19:38:


访问hbase,以及操作hbase,命令不用使用分号hbase shell 进入hbase

list 查看表hbase shell -d

hbase(main):024:0> scan '.META.'

=============小例子===================================================

1. 创建一个表memberhbase(main):025:0> create 'member','m_id','address','info'

2.list #查看所有表

3.查看表描述hbase(main):028:0> describe 'member'

4. scan浏览表中数据scan 'member'

5.删除一个列族m_id:先将表disable(如果表中之前有数据的话,会把数据清空)hbase(main):030:0> disable 'member'

hbase(main):033:0> is_enabled 'member'

hbase(main):034:0> alter 'member',{NAME=>'m_id',METHOD=>'delete'}

最后enable,否则不能进行其他操作hbase(main):038:0> enable 'member'

6.插入几条记录

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' 

scan 'member'

7.获取数据获取一个id的所有数据hbase(main):001:0>get 'member','scutshuxue'

获取一个id,一个列族的所有数据hbase(main):002:0>get 'member','scutshuxue','info'

获取一个id,一个列族中一个列的所有数据hbase(main):002:0>get 'member','scutshuxue','info:age' 

通过timestamp来获取两个版本的数据hbase(main):010:0>get 'member','scutshuxue',{COLUMN=>'info:age',TIMESTAMP=>1321586238965}

8.  更新一条记录

将scutshuxue的年龄改成99hbase(main):004:0>put 'member','scutshuxue','info:age' ,'99'

10.查询表中有多少行:hbase(main):019:0>count 'member'  

11.删除整行hbase(main):001:0>deleteall 'member','xiaofeng'

12.删除id为xiaofeng的值的‘info:age’字段hbase(main):016:0>delete 'member','temp','info:age'

13.给‘xiaofeng’这个id增加'info:Go'字段,并使用counter实现递增hbase(main):041:0> incr 'member','xiaofeng','info:go'连续执行incr以上,COUNTER VALUE 的值会递增,通过get_counter

获取当前count的值hbase(main):069:0>get_counter 'member','xiaofeng','info:age' 

hbase(main):058:0>get 'member','xiaofeng','info:go'  

获取当前count的值hbase(main):069:0>get_counter 'member','xiaofeng','info:age' 

=============================相关删除=========================

1.删除一个列族:先将表disable(如果表中之前有数据的话,会把数据清空)hbase(main):030:0> disable 'member'

hbase(main):033:0> is_enabled 'member'

hbase(main):034:0> alter 'member',{NAME=>'m_id',METHOD=>'delete'}

最后enable,否则不能进行其他操作hbase(main):038:0> enable 'member'

2.删除整行hbase(main):001:0>deleteall 'scores','xiaofeng'

3.将整张表清空:hbase(main):035:0>truncate 'scores'hbase是先将掉disable掉,然后drop掉后重建表来实现truncate的功能

4.drop一个表(先disable,在drop)hbase(main):029:0>disable 'scores'hbase(main):029:0>drop 'scores'=====================基本操作===========================================

1.查询表是否存在hbase(main):021:0>exists 'scores'

2.判断表是否enablehbase(main):034:0>is_enabled 'scores'                                                                                       3.判断表是否disablehbase(main):032:0>is_disabled 'scores'

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

5.创建表memberhbase(main):025:0> create 'member','m_id','address','info'

6.查看表描述hbase(main):028:0> describe 'member'

=================查询操作================================================1.scan '表名' #查看所有数据

2.get是根据主键查看一列get '表名','主键'[,'列簇名'][,'列簇名:列名']

=============================================================过滤查询表的内容1.FirstKeyOnlyFilter() 得到每一行的列族info的第一个列hbase(main):002:0> scan 'student',{COLUMNS=>'info',FILTER=>"(FirstKeyOnlyFilter())"}

2.查看列簇是info,LIMIT是显示的行数,STARTROW是开始行对应的是主键hbase(main):008:0> scan 'student',{COLUMNS=>['info'],LIMIT=>4,STARTROW=>'200977100710'}


3.查看列簇是info,namehbase(main):007:0> scan 'student',{COLUMNS=>['info','name'],LIMIT=>4,STARTROW=>'200977100710'}
scan 'person', {COLUMNS => ['info', 'data'], FILTER => "(QualifierFilter(=,'substring:a'))"}



hbase shell> disable 'tableName'
hbase shell> snapshot 'tableName', 'tableSnapshot'
hbase shell> clone_snapshot 'tableSnapshot', 'newTableName'
hbase shell> delete_snapshot 'tableSnapshot'hbase shell> drop 'tableName'
disable 'stra_opr:zh_test'snapshot 'stra_opr:zh_test', 'tableSnapshot'clone_snapshot 'tableSnapshot', 'stra_opr:zh_test1'delete_snapshot 'tableSnapshot'drop 'stra_opr:zh_test'

disable 'stra_opr:RM_USER_INFO_0427'snapshot 'stra_opr:RM_USER_INFO_0427','USERTESTSnapshot'clone_snapshot 'USERTESTSnapshot','stra_opr:RM_USER_INFO_0427_clone'delete_snapshot 'USERTESTSnapshot'

disable 'stra_opr:RM_USER_INFO_0427'snapshot 'stra_opr:RM_USER_INFO_0427','USERTESTSnapshot'clone_snapshot 'USERTESTSnapshot','stra_opr:RM_USER_INFO_0427_clone'delete_snapshot 'USERTESTSnapshot'

disable 'stra_opr:20170601test'snapshot 'stra_opr:20170601test','USERTESTSnapshot'clone_snapshot 'USERTESTSnapshot','stra_opr:20170601test_clone'delete_snapshot 'USERTESTSnapshot'

disable 'stra_opr:RM_CUSTGROUP_20170304013909999100020_DETAIL _INFO'drop 'stra_opr:RM_CUSTGROUP_20170304013909999100020_DETAIL _INFO'disable 'stra_opr:RM_CUSTGROUP_20190304013909999100020_DETAIL_INFO'snapshot 'stra_opr:20170601test','USERTESTSnapshot'clone_snapshot 'USERTESTSnapshot','stra_opr:RM_CUSTGROUP_20170304013909999100020_DETAIL_INFO'delete_snapshot 'USERTESTSnapshot'
disable 'stra_opr:RM_CUSTGROUP_20170304013909999100020_LABEL _INFO'drop 'stra_opr:RM_CUSTGROUP_20170304013909999100020_LABEL _INFO'disable 'stra_opr:RM_CUSTGROUP_20190304013909999100020_LABEL_INFO'snapshot 'stra_opr:20170601test','USERTESTSnapshot'clone_snapshot 'USERTESTSnapshot','stra_opr:RM_CUSTGROUP_20170304013909999100020_LABEL_INFO'delete_snapshot 'USERTESTSnapshot'


disablesnapshotclone_snapshotdelete_snapshot drop 





hbase 导入导出hbase org.apache.hadoop.hbase.mapreduce.Export 'table1' /home/fred/table1hbase org.apache.hadoop.hbase.mapreduce.Import 'table1' /home/fred/table1



hbase org.apache.hadoop.hbase.mapreduce.Import ' ' 
























































hbase org.apache.hadoop.hbase.mapreduce.Import 'stra_opr:RM_CUSTGROUP_20170304001518999100016_DETAIL_INFO' /user/stra_opr/custgroupfilebak/20170503/RM_CUSTGROUP_20170304001518999100016_DETAIL_INFO
hbase org.apache.hadoop.hbase.mapreduce.Export 'stra_opr:RM_CHANNELTASK_INFO' /user/stra_opr/selfexport/RM_CHANNELTASK_INFO
hbase org.apache.hadoop.hbase.mapreduce.Import 'stra_opr:RM_HEXSTRINGTEST' /user/stra_opr/selfexport/RM_CHANNELTASK_INFO
scan 'stra_opr:RM_USER_INFO',{LIMIT => 1}


2 回复
jack

 你还在继续写啊

Jencks



回到顶部

©2017 Powered by 三十三行伪代码
皖ICP备17005175号-3