HBase常用shell命令和实践

  • create 创建表
  1. 指定表名、列族、列族版本号
hbase >> create 't1' , { NAME  => 'f1' , VERSIONS => 5}
  1. 创建表t1,3个列族分别为f1、f2、f3
hbase>> create 't1' , 'f1' , 'f2' , f3'
  1. 指定切分点
hbase>> create 't1' , 'f1' , { SPLITS => [ '10' , '20' , '30' , '40' ]}
  • put向表、行、列指定的单元格添加数据
hbse>> put  't1' ,  'row' , 'f1:1' , 'value'
  • get通过指定表名、行、列、时间戳
  1. 获取表t1,行r1,列c1,时间范围为[ts1,ts2],版本号为4的数据
hbase>>get 't1' , 'r1' , {COLUMN => 'c1' ,TIMERANGE => [ts1,ts2],VERSIONS  =>4 }  
  1. 获取表t1,行r1,列c1和c2的数据
 get 't1'  'r1' , 'c1' , 'c2' 
  • 浏览表相关信息
    浏览表t1,列c1,时间范围为[11111,22222]的数据。
hbase>>scan 't1' ,{COLUMNS => 'c1',TIMERANGE =>[11111,22222]}
  • alter修改列族模式
    1.向表t1添加列族f1
alter 't1' ,NAME => 'f1 '

2.删除表t1中的列族f1

alter 't1' NAME => 'f1' 

3.设置表t1中列族f1最大为128MB

hbase>> alter 't1' , METHOD => 'table_att", MAX_FILESIZE =>'134217728'
  • 统计表中的行数
hbase>>count 't1'
  • 显示表相关信息
hbase>>describe 't1'
  • 使表有效或无效
hbase>>enable 't1'
  • 删除指定单元格的数据
hbase>>delete 't1' ,  'r1' , 'c1' , ts1
  • 删除表
hbase >> drop 't1'
  • 判断表是否存在
hbase>>exists 
  • 退出HBase Shell和关闭HBase集群
 hbase>>exit
 hbase>>shutdown
  • 输出HBase集群状态信息
hbase>>status 'detailed'
  • 实例
    在这里插入图片描述

(0):创建上图表内容

start-dfs.sh //启动hadoop
start-hbase.sh  //启动hbase
hbase shell // 进入shell
//表名为student,属性分别为ID、name、magor、socre,列族为information
create 'student', ‘information'
//行键由系统系统默认属性自动创建
put 'student','201801','information:name','wang'  //行键为201801
put 'student','201801','information:magor','math'  
put 'stduent','201801','information:socre','90'
put 'student','201802','information:name','zhang'  //行键为201802
put 'student','201802','information:magor','math'  
put 'stduent','201802','information:socre','91'

在这里插入图片描述

(1):列出HBase所有表的相关信息

describe 'student'

在这里插入图片描述

(2):在终端打印出指定表的所有记录数据。

scan 'student'

在这里插入图片描述

(3):向已经创建好的表添加和删除指定的列族或列。

alter 'student',NAME =>'sexy'   //添加列族sexy
alter 'student',NAME=>'sexy',METHOD=>'delete'  //删除刚好添加的列族

在这里插入图片描述
(4):清空指定表的所有记录数据。

enable 'student' //使表无效
drop 'student'  //删除该表

在这里插入图片描述
(5):统计表的行数

count 'stduent'

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/Leader_wang/article/details/83142947
今日推荐