hbase之shell操作(DDL)

一、简介

Group name: ddl

Commands: alter, alter_async, alter_status, create, describe, disable, disable_all, drop, drop_all, enable, enable_all, exists, get_table, is_disabled, is_enabled, list, locate_region, show_filters

二、创建表

1、语法1

      craete "namespace:表名","family column","family column"

      create "bdtest:test1","info1","info2"

2、语法2

      {表的一些属性 必须包含列族}

   create "namespace:表名",{NAME => “”,VERSIONS => 3,TTL =>},{NAME => ""}

      常用的属性:VERSIONS => 1  指定数据版本, TTL => 2592000  指定数据存储周期

create "bdtest:test2",{NAME => "info1"},{NAME => "info2",VERSIONS => 3}

三、删除表

      先禁用表,在删除表

drop "namespace:表名"

disable "bdtest:test1"

drop "bdtest:test1"

      drop_all

hbase> drop_all 'namespace:.*|t.*'

删除指定的所有表

四、修改表

1、修改属性信息

      alter 'namespace:表名', '列族', {NAME => '列族', IN_MEMORY => true}, {NAME => '列族', VERSIONS => 5}

      alter "bdtest:test1",{NAME => "info1",VERSIONS => 3}

      其中不在花括号中的列族,可以省略,如果要添加一个默认状态下的列族可以使用。

2、添加列族

      alter "bdtest:test1",{NAME => "info3",VERSIONS => 3}

      修改表的时候,列族不存在,事实上就是添加

      alter "bdtest:test1","info4",{NAME => "info5",VERSIONS => 3}

3、删除列族

hbase> alter 'namespace:表名', NAME => '列族', METHOD => 'delete'

      hbase> alter 'namespace:表名', 'delete' => '列族'

      METHOD 用于指定对当前列族的操作

      alter "bdtest:test1",NAME => "info5",METHOD => 'delete'

      alter "bdtest:test1",'delete' => "info4"

      注意: 表中至少有一个列族,如果表中只剩一个列族,不允许删除

五、查看表列表

list

hbase> list  查看所有的表列表

hbase> list 'abc.*'  查看所有的指定字符开头的表default下的

hbase> list 'ns:abc.*'  查看指定的namespace下的所有的指定字符开头的表列表

      list 'bdtest:t.*'

hbase> list 'ns:.*' 查看指定namespace下的所有表列表

      list "bdtest:.*"

六、查看表的详细信息

      help 'describe'

hbase> describe 't1'  查看default下的表的描述信息

hbase> describe 'ns1:t1' 查看指定namespace下的所有表描述信息的

简写:

hbase> desc 't1'

hbase> desc 'ns1:t1'

      建表过程中,没有指定版本信息,默认1个。默认存储周期,永久存储 ttl=> forever

七、查看表状态

1、两种状态

      启用:enable 可以执行操作的

      禁用:disable 不可以执行操作

2、查看表是否禁用

      is_disabled "namespace:表名"

      is_disabled "bdtest:test1"

      禁用true 启用 false

3、查看表是否启用

      is_enabled "namespace:表名"

      is_enabled "bdtest:test1"

      启用 true 禁用 false

4、注意

      默认建表的时候,是启用状态

八、禁用表和启用表

      disable "namespace:表名"

enable“namespace:表名”

disable "test1"

is_disabled "test1"

enable "test1"

is_disabled "test1"

disable_all "namespace:.*|t.*"  禁用指定的所有表

enable_all  "namespace:.*|t.*"  启用指定的所有表

disable_all "bdtest:.*"

is_disabled "bdtest:test1"

enable_all "bdtest:.*"

is_disabled "bdtest:test1"

猜你喜欢

转载自www.cnblogs.com/zhangxiaofan/p/10995094.html