hbase shell命令

1. hbase 基本命令

  • hbase shell # 进入hbase

  • help # 进入hbase后台,查看帮助信息

  • status # 查看hbase集群状态

  • version # 查看数据库版本

  • list # 查看数据库中所有的表

  • describe 'tablename' # 查看表的详细信息

2. 其他命令

2.1创建表StudentAndCourse,列簇为student、course1,course2、course3

create "StudentAndCourse", "student", "course1", "course2", "course3"
​
运行结果:
hbase:002:0> create "StudentAndCourse", "student", "course1", "course2", "course3"
Created table StudentAndCourse
Took 1.1680 seconds                                                                                                                                                                                                             
=> Hbase::Table - StudentAndCourse

查看表:

hbase:004:0> describe "StudentAndCourse"
Table StudentAndCourse is ENABLED
StudentAndCourse, {TABLE_ATTRIBUTES => {METADATA => {'hbase.store.file-tracker.impl' => 'DEFAULT'}}}
COLUMN FAMILIES DESCRIPTION
{NAME => 'course1', BLOOMFILTER => 'ROW', IN_MEMORY => 'false', VERSIONS => '1', KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', COMPRESSION => 'NONE', TTL => 'FOREVER', MIN_VERSIONS => '0', BLOCKCACHE => 'true
', BLOCKSIZE => '65536 B (64KB)', REPLICATION_SCOPE => '0'}
{NAME => 'course2', BLOOMFILTER => 'ROW', IN_MEMORY => 'false', VERSIONS => '1', KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', COMPRESSION => 'NONE', TTL => 'FOREVER', MIN_VERSIONS => '0', BLOCKCACHE => 'true
', BLOCKSIZE => '65536 B (64KB)', REPLICATION_SCOPE => '0'}
{NAME => 'course3', BLOOMFILTER => 'ROW', IN_MEMORY => 'false', VERSIONS => '1', KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', COMPRESSION => 'NONE', TTL => 'FOREVER', MIN_VERSIONS => '0', BLOCKCACHE => 'true
', BLOCKSIZE => '65536 B (64KB)', REPLICATION_SCOPE => '0'} 
{NAME => 'student', BLOOMFILTER => 'ROW', IN_MEMORY => 'false', VERSIONS => '1', KEEP_DELETED_CELLS => 'FALSE', DATA_BLOCK_ENCODING => 'NONE', COMPRESSION => 'NONE', TTL => 'FOREVER', MIN_VERSIONS => '0', BLOCKCACHE => 'true
', BLOCKSIZE => '65536 B (64KB)', REPLICATION_SCOPE => '0'}
4 row(s)
Quota is disabled
Took 0.0958 seconds
​
​
说明:
Table StudentAndCourse is ENABLED # 表状态,表是激活的(可用的)
​
TABLE_ATTRIBUTES => {METADATA => {'hbase.store.file-tracker.impl' => 'DEFAULT'}} # 使用默认的命名空间default,注意是小写,因为hbase默认有两个命名空间,一个是内置的hbase命名空间,存放hbase内置表,另一个是default命名空间,用户默认使用的命名空间。
​
COLUMN FAMILIES DESCRIPTION # 列簇描述,如上有四个列簇,course1、course2、course3、student(NAME => 列簇名)

2.2 插入数据

新增学生信息
put 'StudentAndCourse' ,'2023003','student:S_Name','Lisi'
put 'StudentAndCourse' ,'2023003','student:S_Sex','male'
put 'StudentAndCourse' ,'2023003','student:S_Age','24'
put 'StudentAndCourse' ,'2023003','course1:C_No','123001'
put 'StudentAndCourse' ,'2023003','course1:C_Name','Math'
put 'StudentAndCourse' ,'2023003','course1:C_Credit','2.0'
put 'StudentAndCourse' ,'2023003','course1:Score','98'
put 'StudentAndCourse' ,'2023003','course2:C_No','123002'
put 'StudentAndCourse' ,'2023003','course2:C_Name','Computer Science'
put 'StudentAndCourse' ,'2023003','course2:C_Credit','5.0'
put 'StudentAndCourse' ,'2023003','course2:Score','95'
...
...

2.3 浏览数据

scan
​
2023003                                                  column=course2:C_No, timestamp=2023-06-06T11:31:37.375, value=123002                                                                                                  
 2023003                                                  column=course2:Score, timestamp=2023-06-06T11:31:38.057, value=95                                                                                                     
 2023003                                                  column=student:S_Age, timestamp=2023-06-06T11:31:37.310, value=24                                                                                                     
 2023003                                                  column=student:S_Name, timestamp=2023-06-06T11:31:37.279, value=Lisi                                                                                                  
 2023003                                                  column=student:S_Sex, timestamp=2023-06-06T11:31:37.298, value=male 

2.4 查看有哪些表

list
​
hbase:051:0> list
TABLE        
​
StudentAndCourse   
1 row(s)
Took 0.0167 seconds
=> ["StudentAndCourse"]
​
说明:默认为default命名空间

2.5 查看命名空间列表

list_namespace
​
hbase:049:0> list_namespace
NAMESPACE         
default        
hbase     
2 row(s)
​
第一个不是命名空间名称,是列名称-命名空间

2.6 查看命名空间下有哪些表

list_namespace_tables 'default'
TABLE                                                                                                                                          
StudentAndCourse 
1 row(s)

2.7 创建命名空间

create_namespace 'commerce'
  • 删除命名空间

drop_namespace 'commerce'
  • 使用创建的命名空间创建表

create 'commerce.province_city_info', 'provinceInfo', 'cityInfo'

2.8 删除表

删除表之前先停止表,
第一步:
disable 'commerce.province_city_info'
第二步:
drop 'commerce.province_city_info'

2.9 判断表是否存在

exists 'commerce.province_city_info'

2.10 新增列簇

alter 'commerce.province_city_info','otherInfo'

2.11 删除列簇

alter 'commerce.province_city_info','otherInfo',{NAME=>'otherInfo',METHOD=>'delete'}

2.12 设置列簇记录三个版本

alter 'commerce.province_city_info',{NAME=>'provinceInfo',VERSIONS=>3}

2.13 设置浏览列簇/cell

scan 'StudentAndCourse',{COLUMN=>'student'}
scan 'StudentAndCourse',{COLUMN=>'student:S_Name'}

2.14 删除指定列簇下的列

delete 'StudentAndCourse','2023003','student:S_Age'

2.15 删除指定的rowkey

deleteall 'StudentAndCourse', '2015001'
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值