Hadoop学习笔记(5)-HBase常用Shell命令

status 查看系统状态
hbase(main):001:0> status
1 active master, 0 backup masters, 1 servers, 0 dead, 2.0000 average load
Took 2.7304 seconds
version 查看版本号
hbase(main):002:0> version
2.2.0, rUnknown, Tue Jun 11 04:30:30 UTC 2019
Took 0.0171 seconds
table_help 查看提示信息
hbase(main):003: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).
Took 0.0479 seconds    
表的管理
创建表
create '表名', '列族1', '列族2', ...
# 或者
create '表名', {NANE => '列族1', VERSION => '版本数'}, {NAME => '列族2'}, ...

ps: 创建一个表,该表名称为Student,包含4个列族S_ID,S_Name,S_Sex和S_Age

hbase(main):004:0> create 'Student','S_ID','S_Name','S_Sex','S_Age'
Created table Student
Took 1.9408 seconds                                                             
=> Hbase::Table - Student
list 查看表
hbase(main):005:0> list
TABLE                                                                        Student                                                                    
1 row(s)
Took 0.0890 seconds                                                             
=> ["Student"]
enable/disable:使表有效或无效
hbase(main):008:0> disable 'Student'
Took 0.0389 seconds                                                             
hbase(main):009:0> enable 'Student'
Took 1.3869 seconds s 
describe 表的描述
hbase(main):010:0> describe 'Student'
Table Student is ENABLED                                               
.......                    
drop 表的删除

删除表首先需要利用disable命令禁用表再删除。

hbase(main):013:0> disable 'Student'
Took 1.2900 seconds                                                             
hbase(main):014:0> drop 'Student'
Took 0.3040 seconds
exists 判断是否存在
hbase(main):012:0> exists 'Student'
Table Student does exist                                                    
Took 0.0433 seconds                                                         
=> true
数据操作
put 增加和修改数据

向表、行、列指定的单元格添加数据,一次只能为一个表的一行数据的一个列添加一个数据

ps: 向表Student中的第1行、第S_ID列,添加数据值为 “111”

hbase(main):003:0> put 'Student','1','S_ID','111'
Took 0.1942 seconds
get 查询数据

通过表名、行、列、时间戳、时间范围和版本号来获得相应单元格的值

hbase(main):005:0> get 'Student','1'
COLUMN                CELL                                                
S_ID:                timestamp=1589004989645, value=111                
1 row(s)
Took 0.0987 seconds
scan 浏览表的相关信息
hbase(main):004:0> scan 'Student'
ROW                   COLUMN+CELL                                           
1                    column=S_ID:, timestamp=1589004989645, value=111        
1 row(s)
Took 0.0917 seconds
delete 删除数据
hbase(main):007:0> delete 'Student','1','S_ID'
Took 0.0804 seconds
count 统计
hbase(main):010:0> count 'Student'
1 row(s)
Took 0.1488 seconds                                                         
=> 1
truncate 清空表数据
hbase(main):011:0> truncate 'Student'
Truncating 'Student' table (it may take a while):
Disabling table...
Truncating table...
Took 3.8872 seconds 
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值