HBase常见操作问题
工具:xshell(连接虚拟机)
进入hbase操作命令界面(操作一般不用”;”结尾,输入完直接回车即可):
1、进入hbase:hbase shell
2、查看表信息:
语法:describe ‘表名’
例子:describe ‘ns_sopdm:tb_gds_att’
3、查询
(1)查询前几条
语法:scan '表名',{LIMIT=>条数}
例子:scan 'ns_sopdm:tb_gds_att',{LIMIT=>1}
scan 'ns_sopdm:tb_gds_att', {COLUMNS=>'gds:jys'}
scan 'ns_sopdm:tb_gds_att', {COLUMNS=>'gds:jys', LIMIT=>1}
注意:
停止查询快捷键(直接退出当前的hbase):ctrl+z
主键模糊查询
scan 'ns_sopdm:tb_gds_att', {FILTER=>org.apache.hadoop.hbase.filter.PrefixFilter.new(org.apache.hadoop.hbase.util.Bytes.toBytes('L4R0102003_20180823'))}
限制:起始行:R9000308_20180823_
截止行:R9000308_20180823_20180823a
列簇:gds
列限定符
scan 'ns_sopdm:tb_gds_att', {COLUMNS => ['att', 'gds'], LIMIT => 10, STARTROW =>' R9000308_20180823_'}
scan 'ns_sopdm:tb_gds_att',STARTROW=>'L4R0102003_20180823_',STOPROW=>'L4R0102003_20180823a',COLUMNS=>['gds', 'att:01231_09']
scan 'ns_sopdm:tb_gds_att',STARTROW=>'L4R1901001_20170328_',STOPROW=>'L4R1901001_20170404a',COLUMNS=>['gds','att:007885_02']
scan 'ns_sopdm:tb_gds_att',STARTROW=>'00L4R1901001_20170403_',STOPROW=>'00L4R1901001_20170404a',COLUMNS=>['gds','att:007885_02']
4.删除
(1)删除表
用drop命令可以删除表。在删除一个表之前必须先将其禁用。
hbase(main):018:0> disable 'emp'
hbase(main):019:0> drop 'emp'
使用exists 命令验证表是否被删除。
hbase(main):020:0> exists 'emp'
Table emp does not exist
Hadoop官网参考文档:http://hadoop.apache.org/docs/r1.0.4/cn/hdfs_shell.html
Hadoop命令:
(1)下载hdfs文件:
hadoop fs -get /user/trunk/test.txt (复制到本地当前目录下)
hadoop fs -get /user/trunk/test.txt(hdfs目录) /root(linux的root目录) (复制到本地当前目录下)
例子(下载到桌面):
hadoop fs -get hdfs://SuningHadoop2/hbase/coprocessor/idas-coprocessor-jar-0.0.8.jar ~
(2)查看是否已下载成功:
ll | grep idas-coprocessor-jar-0.0.8.jar
(3)上传文件到hdfs:
hadoop fs -put test.txt(linux文件目录)/user/trunk(hdfs目录)