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>

本文转自博客园xingoo的博客,原文链接:Hbase常用Shell命令,如需转载请自行联系原博主。

时间: 2024-10-27 11:42:53

Hbase常用Shell命令的相关文章

Linux常用shell命令

本文章记录我在linux系统下常用或有用的系统级命令,包括软硬件查看.修改命令,有CPU.内存.硬盘.网络.系统管理等命令.但本文不打算介绍生僻命令,也不介绍各个linux发行版下的特有命令,且以后会持续更新. 说明,我是在一个Centos 6.4 64位的虚拟机系统进行测试.本文介绍的命令都会在此Centos下运行验证(也有部分命令会在我的suse/ubuntu系统里测试的,会做特明说明),但运行结果就不再列出了. 硬件篇 CPU相关 lscpu                   #查看的是

常用shell命令的参数

1. ls: 类似于dos下的dir命令 ls最常用的参数有三个: -a -l -F. ls –a Linux上的文件以.开头的文件被系统视为隐藏文件,仅用ls命令是看不到他们的,而用ls -a除了显示一般文件名外,连隐藏文件也会显示出来. ls –l 该参数显示更详细的文件信息. ls –F 使用这个参数表示在文件的后面多添加表示文件类型的符号,例如*表示可执行,/表示目录,@表示连结文件,这都是因为使用了-F这个参数.但是现在基本上所有的Linux发行版本的ls都已经内建了-F参数,也就是说

linux中常用 shell 命令组合 整理

//把20140321_files.txt文件中每行路径中文件的内容 action 改为 action_begin, sed -i "s/action/action_begin/g" `cat 20140321_files.txt` //把 20140321_files.txt 中的文件内容  tags  替换为 tags.php sed -i "s/tags/tags.php/g" `ls 20140321_files.txt` //遍历循环20140321_fi

android技巧:如何在android程序中执行adb shell命令

package net.gimite.nativeexe; import java.io.BufferedReader; import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.net.HttpURLConnection; import java.net.MalformedURLExc

HBase shell 命令介绍

HBase shell是HBase的一套命令行工具,类似传统数据中的sql概念,可以使用shell命令来查询HBase中数据的详细情况.安装完HBase之后,如果配置了HBase的环境变量,只要在shell中执行hbase shell就可以进入命令行界面,HBase的搭建可以参考我的上一篇文章:hbase分布式集群搭建 HBase介绍 HBase简介 HBase的名字的来源于Hadoop database,即hadoop数据库,不同于一般的关系数据库,它是一个适合于非结构化数据存储的数据库,而且

Linux系统Shell命令常用功能使用详解

  Linux系统中Shell不仅仅是一个命令,而且是其他命令的解释器.可以调试其他命令,从而完成编译.那么Linux系统中Shell命令应该怎么使用呢? 其实作为命令语言互动式地解释和执行用户输入的命令只是Shell功能的一个方面,Shell还可以用来进行程序设计,它提供了定义变量和参数的手段以及丰富的程序控制结构.使用Shell编程类似于DOS中的批处理文件,称为Shell script,又叫Shell程序或Shell命令文件. Shell基本语法 像高级程序设计语言一样,Shell也提供说

34个Android常用adb shell命令汇总

调试Android程序有时需要adb shell 命令,adb全称Android Debug Bridge ,就是起到调试桥的作用.通过adb我们可以在Eclipse中通过DDMS来调试Android程序,说白了就是debug工具.adb通过监听Socket TCP 5554等端口让IDE和Qemu通讯.默认情况下当我们运行Eclipse时adb进程就会自动运行.adb是一个C/S模式的程序,由三个部分组成:a client,a server and a daemon.其中client和serv

linux shell命令常用技巧

Linux系统提供了两个对Shell编程非常有用的特殊文件,/dev/null和/dev/tty.其中/dev/null将会丢掉所有写入它的数据,换句换说,当程序将数据写入到此文件时,会认为它已经成功完成写入数据的操作,但实际上什么事都没有做.如果你需要的是命令的退出状态,而非它的输出,此功能会非常有用,见如下Shell代码:  代码如下 复制代码     /> vi test_dev_null.sh         #!/bin/bash     if grep hello TestFile

shell 命令行中操作HBase数据库实例详解_Linux

 shell 命令行中操作HBase数据库 Shell控制 进入到shell命令行界面,执行hbase命令,并附加shell关键字:  [grid@hdnode3 ~]$ hbase shell HBase Shell; enter ¨help¨ for list of supported commands. Type "exit" to leave the HBase Shell Version 0.90.5, r1212209, Fri Dec 9 05:40:36 UTC 201