HBase-hbase shell操作

发布时间 2023-10-17 18:45:15作者: 业余砖家

hbase shell操作

一、DDL操作

1.开启hbase shell

hbase shell

 

2.查看hbase状态

Status

 

3.查看hbase版本

Version

 

4.创建命名空间

create_namespace '命名空间名'

 

5.显示所有命名空间

list_namespace

 

6.删除命名空间

在删除一个命名空间时,该命名空间不能包含任何的表,否则会报错

drop_namespace '命名空间名'

 

7.创建表

#创建默认命名空间的表

create '表名称', '列族名称1','列族名称2','列族名称N'

#创建带有命名空间的表

create '命名空间:表名称', '列族名称1','列族名称2','列族名称N'

 

8.列出所有表

list

 

9.获得表的描述

describe '表名'

10.删除列族

#删除table 表的 列族名称1 列族

alter 'table',{NAME=>'列族名称1',METHOD=>'delete'}

 

#删除多个列族

alter 'table', {NAME => '列族名称1', METHOD => 'delete'},{NAME => '列族名称2', METHOD => 'delete'}

11.删除表

#先把表下线

disable '表名'

#drop

drop '表名'

 

二、DML操作

1.添加数据

# 语法:put <table>,<rowkey>,<family:column>,<value>,[<timestamp>]

#如果不写timestamp,则系统默认

put 'table','id01', 'c_f1:name','111'

 

2.获取数据

#get: 获取表中一行数据,不能扫描全表

# 语法:get <table>,<rowkey>,[<family:column>,....]

get 'table','id01'

 

3.更新数据

#语法:重新putput时会覆盖原来的数据

put 'table','id01', 'c_f1:name','222'

 

4.scan扫描

# 语法:scan <table> ,{COLUMNS => [ <family:column>,.... ], LIMIT => num}

#扫描全表,大表操作不可取

scan 'table'

#获取表中前两行

scan 'table', {LIMIT => 2}

#扫描表中指定列族数据

scan 'table', {COLUMNS => 'c_f1'}

#扫描表中执行列族中列的数据

scan 'table', {COLUMNS => 'c_f2:cert_no'}

#扫描表中值=222 的数据

scan 'table', FILTER=>"ValueFilter(=,'name:222')"

# 筛选行,按照rowkey的范围[STARTROW,STOPROW)

scan 'table', {STARTROW =>'id01' , STOPROW => 'id03'}

 

5.删除行中某列数据

# 语法:delete <table>, <rowkey>, <family:column>

# 必须指定列名

# 会删除执行列的所有版本数据

delete 'table', 'id04', 'c_f2:name'

 

6.删除整行

# 语法:deleteall <table>, <rowkey>

deleteall 'table', 'id05'

 

7.清空表数据

# 语法: truncate <table>

truncate 'table'

 

8.查询表中有多少行

# 语法:count <table>, {INTERVAL => intervalNum, CACHE => cacheNum}

# INTERVAL设置多少行显示一次及对应的rowkey,默认1000

# CACHE每次去取的缓存区大小,默认是10,调整该参数可提高查询速度

#查询表中数据行数

count 'table'

#按照2行显示一次,查询

count 'table', {INTERVAL => 2}

三、其他

echo "describe 'test'" | ./hbase shell -n > /home/test/desc_table.txt  2>&1