Hbase常用Shell命令

status 查看系统状态

hbase(main):010:0> status
1 active master, 0 backup masters, 4 servers, 0 dead, 6.5000 average load

version 查看版本号

hbase(main):011:0> version
1.2.0-cdh5.7.2, rUnknown, Fri Jul 22 12:20:40 PDT 2016

table_help 查看提示信息

hbase(main):012:0> table_help
Help for table-reference commands.

You can either create a table via 'create' and then manipulate the table via commands like 'put', 'get', etc.
See the standard help information for how to use each of these commands.

However, as of 0.96, you can also get a reference to a table, on which you can invoke commands.
For instance, you can get create a table and keep around a reference to it via:

   hbase> t = create 't', 'cf'

Or, if you have already created the table, you can get a reference to it:

   hbase> t = get_table 't'

You can do things like call 'put' on the table:

  hbase> t.put 'r', 'cf:q', 'v'

which puts a row 'r' with column family 'cf', qualifier 'q' and value 'v' into table t.

To read the data out, you can scan the table:

  hbase> t.scan

which will read all the rows in table 't'.

Essentially, any command that takes a table name can also be done via table reference.
Other commands include things like: get, delete, deleteall,
get_all_columns, get_counter, count, incr. These functions, along with
the standard JRuby object methods are also available via tab completion.

For more information on how to use each of these commands, you can also just type:

   hbase> t.help 'scan'

which will output more information on how to use that command.

You can also do general admin actions directly on a table; things like enable, disable,
flush and drop just by typing:

   hbase> t.enable
   hbase> t.flush
   hbase> t.disable
   hbase> t.drop

Note that after dropping a table, your reference to it becomes useless and further usage
is undefined (and not recommended).

表的管理

create 创建表

hbase(main):014:0> create 'xt','xcf'
0 row(s) in 2.5340 seconds

=> Hbase::Table - xt
hbase(main):015:0>

list 查看表

hbase(main):015:0> list
TABLE
...
xt
17 row(s) in 0.0200 seconds

=> [..."xt"]
hbase(main):016:0>

describe 表的描述

hbase(main):017:0> describe 'xt'
Table xt is ENABLED
xt
COLUMN FAMILIES DESCRIPTION
{NAME => 'xcf', 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.0500 seconds

disable 表的禁用

hbase(main):038:0> disable 'xt'
0 row(s) in 8.7530 seconds

drop 表的删除

hbase(main):039:0> drop 'xt'
0 row(s) in 2.3130 seconds

exsits 判断是否存在

hbase(main):040:0> exists 'xt'
Table xt does not exist
0 row(s) in 0.0110 seconds

数据操作

put 增加和修改数据

向指定的列族中插入数据

hbase(main):019:0> put 'xt','1','xcf:col_name1','col_value1'
0 row(s) in 0.0080 seconds

hbase(main):020:0> put 'xt','1','xcf:col_name2','col_value2'
0 row(s) in 0.0050 seconds

get 查询数据

hbase(main):021:0> get 'xt','1'
COLUMN                              CELL
 xcf:col_name1                      timestamp=1496997489039, value=col_value1
 xcf:col_name2                      timestamp=1496997502916, value=col_value2
2 row(s) in 0.0110 seconds

hbase(main):022:0> get 'xt','1',{COLUMN => 'xcf:col_name1'}
COLUMN                              CELL
 xcf:col_name1                      timestamp=1496997489039, value=col_value1
1 row(s) in 0.0520 seconds

hbase(main):023:0>

delete 删除数据

hbase(main):023:0> delete 'xt','1','xcf:col_name1'
0 row(s) in 0.0280 seconds

hbase(main):024:0> get 'xt','1'
COLUMN                              CELL
 xcf:col_name2                      timestamp=1496997502916, value=col_value2
1 row(s) in 0.0030 seconds

hbase(main):026:0> deleteall 'xt','1'
0 row(s) in 0.0030 seconds

hbase(main):028:0> get 'xt','1'
COLUMN                              CELL
0 row(s) in 0.0070 seconds

scan 扫描全部数据

hbase(main):029:0> put 'xt','1','xcf:col1','123'
0 row(s) in 0.0230 seconds

hbase(main):030:0> put 'xt','2','xcf:col1','123'
0 row(s) in 0.0040 seconds

hbase(main):031:0> put 'xt','3','xcf:col1','123'
0 row(s) in 0.0040 seconds

hbase(main):032:0> put 'xt','4','xcf:col1','123'
0 row(s) in 0.0040 seconds

hbase(main):033:0> scan 'xt'
ROW                                 COLUMN+CELL
 1                                  column=xcf:col1, timestamp=1496998219258, value=123
 2                                  column=xcf:col1, timestamp=1496998223993, value=123
 3                                  column=xcf:col1, timestamp=1496998227824, value=123
 4                                  column=xcf:col1, timestamp=1496998230678, value=123
4 row(s) in 0.0140 seconds

count 统计表个数

hbase(main):034:0> count 'xt'
4 row(s) in 0.0170 seconds

=> 4

truncate 清空表数据

hbase(main):035:0> truncate 'xt'
Truncating 'xt' table (it may take a while):
 - Disabling table...
 - Truncating table...
0 row(s) in 104.8850 seconds

hbase(main):036:0> count 'xt'
0 row(s) in 23.6480 seconds

=> 0
hbase(main):037:0>

本文参与腾讯云自媒体分享计划,欢迎正在阅读的你也加入,一起分享。

发表于

我来说两句

0 条评论
登录 后参与评论

相关文章

来自专栏杨建荣的学习笔记

sed+awk模拟简单sql查询(26天)

经常需要用sqlplus去查询一些数据字典类型的数据,这些数据量不大,而且需要环境之间都是一样的,所以就想使用离线查询的方式,把那些数据以平面文件的形式存放,...

371120
来自专栏乐沙弥的世界

ORA-01658 错误

最近重新装个了Oracle 11g,在对分区表导入导出时碰到了ORA-01658错误的问题,因为刚刚才装的新系统,一导出就碰到了下面的问题,

9820
来自专栏积累沉淀

15分钟熟悉HBase Shell命令

下面我们看看HBase Shell的一些基本操作命令,我列出了几个常用的HBase Shell命令,如下: 名称 命令表达式 创建表 ...

77380
来自专栏大数据智能实战

HBase时间老化的测试

最近想着测试一下HBase存储上的时间老化问题。 Hbase本身还是提供这种功能的,总体上还是非常不错的。 首先建立一个测试表。create 'ttt','f'...

24580
来自专栏杨建荣的学习笔记

探究AWR 第一篇

statspack相比awr算是比较通用,而且免费,可以在标准版,企业版中使用,awr是新企业版本中才有的,算是statspack的一个升级版,而且代码不公开。...

36270
来自专栏杨建荣的学习笔记

海量数据迁移之外部表加载(100天)

本地有一个小的环境,今天照例登上sqlplus,突然发现报了如下的错误。一看原来归档满了。我记得前几天做一个批量操作临时把temp文件resize了很大,限于本...

34380
来自专栏乐沙弥的世界

ORA-02019 错误处理

       ORA-02019 错误提示是未找到远程数据库的连接说明,通常发生在本地数据库无法连接到远程数据库。引发该问题的原因很多,比如网络连接,连接方式(...

13010
来自专栏杨建荣的学习笔记

一个MySQL死锁问题的复现

很久之前有一个同事问我一个关于死锁的问题,一直在拖这个事情,总算找了空来看看。 这个环境的事务隔离级别是RR,仔细看了下问题描述和背景,发现还真不是一...

45590
来自专栏杨建荣的学习笔记

归档问题导致的数据库无法启动 (80天)

本地有一个小的环境,今天照例登上sqlplus,突然发现报了如下的错误。一看原来归档满了。我记得前几天做一个批量操作临时把temp文件resize了很大,限于本...

341100
来自专栏岑玉海

hadoop 1.1.2和 hive 0.10 和hbase 0.94.9整合

  今天弄了一下hive0.10和hbase0.94.9整合,需要设置的并不多,但是也遇到了一些问题。   1.复制jar包   拷贝hbase-0.94.9....

35650

扫码关注云+社区

领取腾讯云代金券