ICode9

精准搜索请尝试: 精确搜索
首页 > 系统相关> 文章详细

HBASE基础(3):语法(1)shell操作 (1) DDL namespace/表的操作

2021-09-03 23:02:05  阅读:193  来源: 互联网

标签:info shell namespace student DDL hbase main 1001


1 基本操作

1.1 进入HBase客户端命令行

[atguigu@hadoop102 hbase]$ bin/hbase shell

1.2 查看帮助命令

hbase(main):001:0> help

2 namespace的操作

2.1 查看当前Hbase中有哪些namespace

 

hbase(main):002:0> list_namespace

NAMESPACE                                                                                                                                                                                             
default(创建表时未指定命名空间的话默认在default下)                                                                                                
hbase(系统使用的,用来存放系统相关的元数据信息等,勿随便操作)  

 

2.2 创建namespace

hbase(main):010:0>  create_namespace "test"

hbase(main):010:0> create_namespace "test01", {"author"=>"wyh", "create_time"=>"2020-03-10 08:08:08"}

2.3 查看namespace

hbase(main):010:0>  describe_namespace "test01"

2.4 修改namespace的信

hbase(main):010:0> alter_namespace "test01", {METHOD => 'set', 'author' => 'weiyunhui'}

添加或者修改属性:

alter_namespace 'ns1', {METHOD => 'set', 'PROPERTY_NAME' => 'PROPERTY_VALUE'}

删除属性:          

alter_namespace 'ns1', {METHOD => 'unset', NAME => ' PROPERTY_NAME '} 

2.5 删除namespace

hbase(main):010:0> drop_namespace "test01"

注意: 要删除的namespace必须是空的,其下没有表。

 

 

3 表的操作

 

 

3.0.查看当前数据库中有哪些表

 

hbase(main):002:0> list

 

3.1.创建表

 

hbase(main):002:0> create 'student','info'

 

3.2.插入数据到表

 

hbase(main):003:0> put 'student','1001','info:sex','male'

 

hbase(main):004:0> put 'student','1001','info:age','18'

 

hbase(main):005:0> put 'student','1002','info:name','Janna'

 

hbase(main):006:0> put 'student','1002','info:sex','female'

 

hbase(main):007:0> put 'student','1002','info:age','20'

 

3.3.扫描查看表数据

 

hbase(main):008:0> scan 'student'

 

hbase(main):009:0> scan 'student',{STARTROW => '1001', STOPROW  => '1001'}

 

hbase(main):010:0> scan 'student',{STARTROW => '1001'}

 

3.4.查看表结构

 

hbase(main):011:0> describe 'student'

 

3.5.更新指定字段的数据

 

hbase(main):012:0> put 'student','1001','info:name','Nick'

 

hbase(main):013:0> put 'student','1001','info:age','100'

 

3.6.查看“指定行”或“指定列族:列”的数据

 

hbase(main):014:0> get 'student','1001'

 

hbase(main):015:0> get 'student','1001','info:name'

 

3.7.统计表数据行数

 

hbase(main):021:0> count 'student'

 

3.8.删除数据

 

删除某rowkey的全部数据:

 

hbase(main):016:0> deleteall 'student','1001'

 

删除某rowkey的某一列数据:

 

hbase(main):017:0> delete 'student','1002','info:sex'

 

3.9.清空表数据

 

hbase(main):018:0> truncate 'student'

 

提示:清空表的操作顺序为先disable,然后再truncate。

 

3.10.删除表

 

首先需要先让该表为disable状态:

hbase(main):019:0> disable 'student'

然后才能drop这个表:

hbase(main):020:0> drop 'student'

提示:如果直接drop表,会报错:ERROR: Table student is enabled. Disable it first.

3.11.变更表信息

将info列族中的数据存放3个版本:

hbase(main):022:0> alter 'student',{NAME=>'info',VERSIONS=>3}

hbase(main):022:0> get 'student','1001',{COLUMN=>'info:name',VERSIONS=>3}

 

标签:info,shell,namespace,student,DDL,hbase,main,1001
来源: https://www.cnblogs.com/qiu-hua/p/15225301.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有