Hbase shell details

HBase provides users with a very easy to use way, we call it "HBase Shell".
HBase Shell provides most of HBase command, you can easily create user through HBase Shell, delete, and modify the table, you can also add data to the table, listed in the table of related information.
Note: HBase Shell to delete wrong with the "Delete" on the keyboard command, "Backspace" does not work.
After starting HBase, the user may enter the following commands in HBase Shell, commands are as follows:

hadoop@ubuntu:~$ hbase shell
HBase Shell; enter 'help<RETURN>' for list of supported commands.
Type "exit<RETURN>" to leave the HBase Shell
Version 0.94.3, r1408904, Wed Nov 14 19:55:11 UTC 2012

hbase(main):001:0> 

Specific 1.1-1 HBase Shell command shown in the following table:

hbase shell command                             description 
alter Aromatic modified column (column family) mode
count The number of rows in tables
create Create a table
describe For more information related to the display table
delete Delete the value specified object (may be tables, rows, columns corresponding to the value of the other time stamp value may be specified)
deleteall Delete all of the elements specified row value
disable The table is not valid
drop Delete table
enable The table is valid
exists Test table exists
exit Exit hbase shell
get 获取行或单元(cell)的值
incr 增加指定表,行或列的值
list 列出hbase中存在的所有表
put 向指向的表单元添加值
tools 列出hbase所支持的工具
scan 通过对表的扫描来获取对用的值
status 返回hbase集群的状态信息
shutdown 关闭hbase集群(与exit不同)
truncate 重新创建指定表
version 返回hbase版本信息

下面我们将以“一个学生成绩表”的例子来详细介绍常用的 HBase 命令及其使用方法。


这里 grad 对于表来说是一个列,course 对于表来说是一个列族,这个列族由三个列组成 china、math 和 english,当然我们可以根据我们的需要在 course 中建立更多的列族,如computer,physics 等相应的列添加入 course 列族。(备注:列族下面的列也是可以没有名字的。)
1). create 命令
创建一个具有两个列族“grad”和“course”的表“scores”。其中表名、行和列都要用单引号括起来,并以逗号隔开。
hbase(main):012:0> create 'scores', 'name', 'grad', 'course'

2). list 命令
查看当前 HBase 中具有哪些表。
hbase(main):012:0> list

3). describe 命令
查看表“scores”的构造。
hbase(main):012:0> describe 'scores'

4). put 命令
使用 put 命令向表中插入数据,参数分别为表名、行名、列名和值,其中列名前需要列族最为前缀,时间戳由系统自动生成。
格式: put 表名,行名,列名([列族:列名]),值
例子:
a. 加入一行数据,行名称为“xiapi”,列族“grad”的列名为”(空字符串)”,值位 1。
hbase(main):012:0> put 'scores', 'xiapi', 'grad:', '1'
hbase(main):012:0> put 'scores', 'xiapi', 'grad:', '2' --修改操作(update)
b. 给“xiapi”这一行的数据的列族“course”添加一列“<china,97>”。
hbase(main):012:0> put 'scores', 'xiapi',  'course:china', '97'
hbase(main):012:0> put 'scores', 'xiapi',  'course:math', '128'
hbase(main):012:0> put 'scores', 'xiapi',  'course:english', '85'

5). get 命令
a.查看表“scores”中的行“xiapi”的相关数据。
hbase(main):012:0> get 'scores', 'xiapi'
b.查看表“scores”中行“xiapi”列“course :math”的值。
hbase(main):012:0> get 'scores', 'xiapi', 'course :math'
或者
hbase(main):012:0> get 'scores', 'xiapi', {COLUMN=>'course:math'}
hbase(main):012:0> get 'scores', 'xiapi', {COLUMNS=>'course:math'}
备注:COLUMN 和 COLUMNS 是不同的,scan 操作中的 COLUMNS 指定的是表的列族, get操作中的 COLUMN 指定的是特定的列,COLUMNS 的值实质上为“列族:列修饰符”。COLUMN 和 COLUMNS 必须为大写。

6). scan 命令
a. 查看表“scores”中的所有数据。
hbase(main):012:0> scan 'scores'
注意:
scan 命令可以指定 startrow,stoprow 来 scan 多个 row。
例如:
scan 'user_test',{COLUMNS =>'info:username',LIMIT =>10, STARTROW => 'test', STOPROW=>'test2'}
b.查看表“scores”中列族“course”的所有数据。
hbase(main):012:0> scan  'scores', {COLUMN => 'grad'}
hbase(main):012:0> scan  'scores', {COLUMN=>'course:math'}
hbase(main):012:0> scan  'scores', {COLUMNS => 'course'}
hbase(main):012:0> scan  'scores', {COLUMNS => 'course'}

7). count 命令
hbase(main):068:0> count 'scores'

8). exists 命令
hbase(main):071:0> exists 'scores'

9). incr 命令(赋值)

10). delete 命令
删除表“scores”中行为“xiaoxue”, 列族“course”中的“math”。
hbase(main):012:0>  delete 'scores', 'xiapi', 'course:math'

11). truncate 命令
hbase(main):012:0>  truncate 'scores'

12). disbale、drop 命令
通过“disable”和“drop”命令删除“scores”表。
hbase(main):012:0>  disable 'scores' --enable 'scores' 
hbase(main):012:0>  drop 'scores'

13).  status命令
hbase(main):072:0> status

14).  version命令
hbase(main):073:0> version

另外,在 shell 中,常量不需要用引号引起来,但二进制的值需要双引号引起来,而其他值则用单引号引起来。HBase Shell 的常量可以通过在 shell 中输入“Object.constants”。

转载于:https://www.cnblogs.com/diandianquanquan/p/11043458.html

Guess you like

Origin blog.csdn.net/weixin_33774615/article/details/93350797