HBase Shell 常用命令
发布日期:2021-06-30 17:38:20
浏览次数:3
分类:技术文章
本文共 7948 字,大约阅读时间需要 26 分钟。
HBase常用命令
hbase shell命令 | 描述 |
alter | 修改列族(column family)模式 |
count | 统计表中行的数量 |
create | 创建表 |
describe | 显示表相关的详细信息 |
delete | 删除指定对象的值(可以为表,行,列对应的值,另外也可以指定时间戳的值) |
deleteall | 删除指定行的所有元素值 |
disable | 使表无效 |
drop | 删除表 |
enable | 使表有效 |
exists | 测试表是否存在 |
exit | 退出hbase shell |
get | 获取行或单元(cell)的值 |
incr | 增加指定表,行或列的值 |
list | 列出hbase中存在的所有表 |
put | 向指向的表单元添加值 |
tools | 列出hbase所支持的工具 |
scan | 通过对表的扫描来获取对用的值 |
status | 返回hbase集群的状态信息 |
shutdown | 关闭hbase集群(与exit不同) |
truncate | 重新创建指定表 |
version | 返回hbase版本信息 |
- 进入shell
[hadoop@indb-3-136-hzifc bin]$ echo $HBASE_HOME/data/program/hbase[hadoop@indb-3-136-hzifc bin]$ /data/program/hbase/bin/hbase shellSLF4J: Class path contains multiple SLF4J bindings.SLF4J: Found binding in [jar:file:/data/program/hbase-1.2.0-cdh5.8.3/lib/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]SLF4J: Found binding in [jar:file:/data/program/hadoop-2.6.0-cdh5.8.3/share/hadoop/common/lib/slf4j-log4j12-1.7.5.jar!/org/slf4j/impl/StaticLoggerBinder.class]SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]HBase Shell; enter 'help' for list of supported commands.Type "exit " to leave the HBase ShellVersion 1.2.0-cdh5.8.3, rUnknown, Wed Oct 12 20:33:08 PDT 2016hbase(main):035:0> whoamihadoop (auth:SIMPLE) groups: hadoop
- 表结构
1. 创建表
语法:create <table>, {NAME => <family>, VERSIONS => <VERSIONS>}
hbase(main):002:0> create 'User','info'0 row(s) in 1.5890 seconds=> Hbase::Table - User
3. 查看所有表
hbase(main):003:0> listTABLESYSTEM.CATALOGSYSTEM.FUNCTIONSYSTEM.SEQUENCESYSTEM.STATSTEST.USERUser6 row(s) in 0.0340 seconds=> ["SYSTEM.CATALOG", "SYSTEM.FUNCTION", "SYSTEM.SEQUENCE", "SYSTEM.STATS", "TEST.USER", "User"]
4. 查看表详情
hbase(main):004:0> describe 'User'Table User is ENABLEDUserCOLUMN FAMILIES DESCRIPTION{NAME => 'info', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}1 row(s) in 0.1410 secondshbase(main):025:0> desc 'User'Table User is ENABLEDUserCOLUMN FAMILIES DESCRIPTION{NAME => 'info', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}1 row(s) in 0.0380 seconds
5. 表修改
删除指定的列族
hbase(main):002:0> alter 'User', 'delete' => 'info'Updating all regions with the new schema...1/1 regions updated.Done.0 row(s) in 2.5340 seconds
- 表数据
1. 插入数据
语法:put <table>,<rowkey>,<family:column>,<value>
hbase(main):005:0> put 'User', 'row1', 'info:name', 'xiaoming'0 row(s) in 0.1200 secondshbase(main):006:0> put 'User', 'row2', 'info:age', '18'0 row(s) in 0.0170 secondshbase(main):007:0> put 'User', 'row3', 'info:sex', 'man'0 row(s) in 0.0030 seconds
2. 根据rowKey查询某个记录
语法:get <table>,<rowkey>,[<family:column>,....]
hbase(main):008:0> get 'User', 'row2'COLUMN CELL info:age timestamp=1502368069926, value=181 row(s) in 0.0280 secondshbase(main):028:0> get 'User', 'row3', 'info:sex'COLUMN CELL info:sex timestamp=1502368093636, value=manhbase(main):036:0> get 'User', 'row1', {COLUMN => 'info:name'}COLUMN CELL info:name timestamp=1502368030841, value=xiaoming1 row(s) in 0.0120 seconds
3. 查询所有记录
语法:scan <table>, {COLUMNS => [ <family:column>,.... ], LIMIT => num}
hbase(main):009:0> scan 'User'ROW COLUMN+CELL row1 column=info:name, timestamp=1502368030841, value=xiaoming row2 column=info:age, timestamp=1502368069926, value=18 row3 column=info:sex, timestamp=1502368093636, value=man3 row(s) in 0.0380 seconds
扫描前2条
hbase(main):037:0> scan 'User', {LIMIT => 2}ROW COLUMN+CELL row1 column=info:name, timestamp=1502368030841, value=xiaoming row2 column=info:age, timestamp=1502368069926, value=182 row(s) in 0.0170 seconds
范围查询
hbase(main):011:0> scan 'User', {STARTROW => 'row2'}ROW COLUMN+CELL row2 column=info:age, timestamp=1502368069926, value=18 row3 column=info:sex, timestamp=1502368093636, value=man2 row(s) in 0.0170 secondshbase(main):012:0> scan 'User', {STARTROW => 'row2', ENDROW => 'row2'}ROW COLUMN+CELL row2 column=info:age, timestamp=1502368069926, value=181 row(s) in 0.0110 secondshbase(main):013:0> scan 'User', {STARTROW => 'row2', ENDROW => 'row3'}ROW COLUMN+CELL row2 column=info:age, timestamp=1502368069926, value=181 row(s) in 0.0120 seconds
另外,还可以添加TIMERANGE和FITLER等高级功能
STARTROW,ENDROW必须大写,否则报错;查询结果不包含等于ENDROW的结果集
4. 统计表记录数
语法:count <table>, {INTERVAL => intervalNum, CACHE => cacheNum}
INTERVAL设置多少行显示一次及对应的rowkey,默认1000;CACHE每次去取的缓存区大小,默认是10,调整该参数可提高查询速度
hbase(main):020:0> count 'User'3 row(s) in 0.0360 seconds=> 3
5. 删除
删除列
hbase(main):008:0> delete 'User', 'row1', 'info:age'0 row(s) in 0.0290 seconds
删除所有行
hbase(main):014:0> deleteall 'User', 'row2'0 row(s) in 0.0090 seconds
删除表中所有数据
hbase(main):016:0> truncate 'User'Truncating 'User' table (it may take a while): - Disabling table... - Truncating table...0 row(s) in 3.6610 seconds
- 表管理
1. 禁用表
hbase(main):014:0> disable 'User'0 row(s) in 2.2660 secondshbase(main):015:0> describe 'User'Table User is DISABLEDUserCOLUMN FAMILIES DESCRIPTION{NAME => 'info', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}1 row(s) in 0.0340 secondshbase(main):016:0> scan 'User', {STARTROW => 'row2', ENDROW => 'row3'}ROW COLUMN+CELLERROR: User is disabled.
2. 启用表
hbase(main):017:0> enable 'User'0 row(s) in 1.3470 secondshbase(main):018:0> describe 'User'Table User is ENABLEDUserCOLUMN FAMILIES DESCRIPTION{NAME => 'info', BLOOMFILTER => 'ROW', VERSIONS => '1', IN_MEMORY => 'false', KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', TTL => 'FOREVER', COMPRESSION => 'NONE', MIN_VERSIONS => '0', BLOCKCACHE => 'true', BLOCKSIZE => '65536', REPLICATION_SCOPE => '0'}1 row(s) in 0.0310 secondshbase(main):019:0> scan 'User', {STARTROW => 'row2', ENDROW => 'row3'}ROW COLUMN+CELL row2 column=info:age, timestamp=1502368069926, value=181 row(s) in 0.0280 seconds
3. 测试表是否存在
hbase(main):022:0> exists 'User'Table User does exist0 row(s) in 0.0150 secondshbase(main):023:0> exists 'user'Table user does not exist0 row(s) in 0.0110 secondshbase(main):024:0> exists userNameError: undefined local variable or method `user' for #
4. 删除表
删除前,必须先disable
hbase(main):030:0> drop 'TEST.USER'ERROR: Table TEST.USER is enabled. Disable it first.Here is some help for this command:Drop the named table. Table must first be disabled: hbase> drop 't1' hbase> drop 'ns1:t1'hbase(main):031:0> disable 'TEST.USER'0 row(s) in 2.2640 secondshbase(main):033:0> drop 'TEST.USER'0 row(s) in 1.2490 secondshbase(main):034:0> listTABLESYSTEM.CATALOGSYSTEM.FUNCTIONSYSTEM.SEQUENCESYSTEM.STATSUser5 row(s) in 0.0080 seconds=> ["SYSTEM.CATALOG", "SYSTEM.FUNCTION", "SYSTEM.SEQUENCE", "SYSTEM.STATS", "User"]
- Shell脚本调取
如下所示,EOF Hbase命令 EOF
#!/bin/sh exec /home/hbase shell<
转载地址:https://lemonstone.blog.csdn.net/article/details/82871295 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!
发表评论
最新留言
不错!
[***.144.177.141]2024年04月08日 21时41分06秒
关于作者
喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!
推荐文章
lmdb数据库的读取与转换(二) —— 数据集操作
2019-04-30
Lua语言
2019-04-30
Python __doc__获得模块的文档字符串内容
2019-04-30
Python sys.path和模块搜索路径
2019-04-30
github.io网页无法打开(连接不是私密连接)
2019-04-30
git submodule
2019-04-30
linux中source、sh、bash、./有什么区别
2019-04-30
vscode git
2019-04-30
基于MATLAB的二进制数字调制与解调信号的仿真——2FSK
2019-04-30
基于MATLAB的二进制数字调制与解调信号的仿真——2PSK
2019-04-30
基于MATLAB的模拟调制信号与解调的仿真——AM
2019-04-30
基于MATLAB的模拟调制信号与解调的仿真——DSB
2019-04-30
基于MATLAB的模拟调制信号与解调的仿真——SSB
2019-04-30
pyc文件
2019-04-30
操作系统实验之生产者和消费者程序
2019-04-30
操作系统实验之猴子过桥问题的模拟程序
2019-04-30
POJ - 3067 Japan (树状数组 思维)
2019-04-30
POJ - 2352 Stars (树状数组 入门题)
2019-04-30