H B A S E 基 本 操 作

了解:

-创建表:						create '表名称', '列名称1','列名称2','列名称N'
-添加记录:					put '表名称', '行名称', '列名称:', '值'
-查看记录:					get '表名称', '行名称'
-查看表中的记录总数:			count  '表名称'
-删除记录:					delete  '表名' ,'行名称' , '列名称'
-删除一张表:					先要屏蔽该表,才能对该表进行删除,第一步 disable '表名称' 第二步 drop '表名称'
-查看所有记录:				scan "表名称"  
-查看某个表某个列中所有数据:	scan "表名称" , ['列名称:']

1.namespace 命名空间 相当于库一个概念 库

查看命名空间的帮助:
help 'namespace'
创建一个命名空间;
create_namespace 'data'
描述查看:
describe_namespace ''data'
查看当前habse有哪些命名空间:
list_namespace
查看命名空间的表:
list_namespace_tables ''data'

2.create创建表: 至少包含一个列族

help 'create'

创建带版本的表
create 'ns1:t1', {NAME => 'f1', VERSIONS => 5}
创建两个列族的表
create 'hadoop3_1709:stu','info','other'

在hadoop3_1708命名空间下创建一个表stu表:
create 'hadoop3_1709:stu','stu_info','stu_other'
或者
create 'stu','stu_info','stu_other'

查看创建的表:
list_namespace_tables 'hadoop3_1709'

查看表描述
describe "hadoop3_1709:stu"

3. put添加数据:

help 'put'
	 
stu表列族对应列名称:
info
	name
	sex
other
	address


put 'hadoop3_1709:stu','20171122','info:name','laozhang'
put 'hadoop3_1709:stu','20171122','info:sex','男'
put 'hadoop3_1709:stu','20171122','other:addr','fangshan'


put 'hadoop3_1709:stu','20171020','info:name','laozhang'
put 'hadoop3_1709:stu','20171020','info:sex','nan'
put 'hadoop3_1709:stu','20171020','other:address','fangshan'

scan 'hadoop3_1709:stu'

put 'hadoop3_1709:stu','20171020laowang','info:name','laowang'
put 'hadoop3_1709:stu','20171020laowang','info:sex','nan'
put 'hadoop3_1709:stu','20171020laowang','other:address','fangshan'

put 'hadoop3_1709:stu','20171020laosong','info:name','laosong'
put 'hadoop3_1709:stu','20171020laosong','info:sex','nan'
put 'hadoop3_1709:stu','20171020laosong','other:address','fangshan'

put 'hadoop3_1709:stu','20171020laoliu','info:name','laoliu'
put 'hadoop3_1709:stu','20171020laoliu','info:sex','nv'
put 'hadoop3_1709:stu','20171020laoliu','other:address','liangxiang'

put 'hadoop3_1709:stu','20171021laofu','info:name','laofu'
put 'hadoop3_1709:stu','20171021laofu','info:sex','nv'
put 'hadoop3_1709:stu','20171021laofu','other:address','liangxiang'

put 'hadoop3_1709:stu','20171021laoda','info:name','laoda'
put 'hadoop3_1709:stu','20171021laoda','info:sex','nan'
put 'hadoop3_1709:stu','20171021laoda','other:address','beicai'


添加数据:
put 'hadoop3_1709:stu','rk2017092710001','stu_info:name','zhangyanpeng'
put 'hadoop3_1709:stu','rk2017092710001','stu_info:sex','nan'
put 'hadoop3_1709:stu','rk2017092710001','stu_other:address','beijing-fangshan'

put 'hadoop3_1709:stu','rk2017092710009','stu_info:name','xiaowu'
put 'hadoop3_1709:stu','rk2017092710009','stu_info:sex','nan'
put 'hadoop3_1709:stu','rk2017092710009','stu_other:address','beijing-erzhi'

put 'hadoop3_1709:stu','rk2017092710089','stu_info:name','ziaozhang'
put 'hadoop3_1709:stu','rk2017092710089','stu_info:sex','nv'
put 'hadoop3_1709:stu','rk2017092710089','stu_other:address','beijing-daxing'

4.查看所有数据:scan

help 'scan'

查看整张表的数据:
scan 'hadoop3_1709:stu'
区别于:scan 'stu'
查看某一个列族的数据:
scan 'hadoop3_1709:stu', {COLUMNS => ['stu_info']}
scan 'hadoop3_1709:stu', {COLUMNS => ['stu_info','stu_other']}

scan 'hadoop3_1709:stu',{COLUMNS =>['info']}
scan 'hadoop3_1709:stu',{COLUMNS =>['info:name']}
scan 'hadoop3_1709:stu',{COLUMNS => ['info:sex','other']}

scan 'hadoop3_1709:stu','info' --error

5.get 查看某个值

help 'get'

get 'hadoop3_1709:stu','20171020laowang'
get 'hadoop3_1709:stu','20171020laowang',{COLUMNS =>['info']}
get 'hadoop3_1709:stu','20171020laowang',{COLUMNS =>['info:name']}
 
get 'hadoop3_1709:stu', 'rk2017092710089', {COLUMN => 'stu_info'}

查看一行的多个列族:
get 'hadoop3_1709:stu', 'rk2017092710089','stu_info','stu_other'

查看某一个单元数据值:
get 'hadoop3_1709:stu', 'rk2017092710089','stu_info:name','stu_other:address'

6. count 统计:

统计表的行数:
count 'hadoop3_1709:stu'

7.delete 删除表: ???历史版本被删除!???

delete 'ns1:t1', 'r1', 'c1', ts1

delete 'hadoop3_1709:stu','20171020laowang','other:address',1507731195828

8.disable 禁用表;

help 'disable'
Start disable of named table:
hbase> disable 't1'
hbase> disable 'ns1:t1'

disable 'hadoop3_1709:stu'

9.drop

help 'drop'
Drop the named table. Table must first be disabled:
hbase> drop 't1'
hbase> drop 'ns1:t1'
删除表:
drop 'hadoop3_1709:stu'

查看表是否启用
is_enabled "hadoop3_1709:stu"

enable "hadoop3_1709:stu"

10.删除命名空间:

drop_namespace 'hadoop3_1709'
如果命名空间有表,会报错

11.查看表结构

describe 'hadoop3_1709:stu'
desc  'hadoop3_1709:stu'

#修改表结构
修改表结构必须先disable
语法:alter 't1', {NAME => 'f1'}, {NAME => 'f2', METHOD => 'delete'}
例如:修改表test1的cf的TTL为180天
disable 'test1'
alter 'test1',{NAME=>'body',TTL=>'15552000'},{NAME=>'meta', TTL=>'15552000'}
enable 'test1'

语法:scan <table>, {COLUMNS => [ <family:column>,.... ], LIMIT => num}
	另外,还可以添加STARTROW、TIMERANGE和FITLER等高级功能
	scan 't1',{LIMIT=>5}

12.删除表中的所有数据

语法: truncate <table>
其具体过程是:disable table -> drop table -> create table
例如:删除表t1的所有数据
hbase(main)> truncate 't1'

13. HBase建表是可以添加列族,

alter 't1', {NAME => 'f1', VERSIONS => 5} 
把表disable 后 alter,然后 enable

## 14.权限管理
1)分配权限
 语法 : grant <user> <permissions> <table> <column family> <column qualifier> 参数后面用逗号分隔
 权限用五个字母表示: "RWXCA".
 READ('R'), WRITE('W'), EXEC('X'), CREATE('C'), ADMIN('A')
 例如,给用户‘test'分配对表t1有读写的权限,
hbase(main)> grant 'test','RW','t1'

2)查看权限
 语法:user_permission <table>
 例如,查看表t1的权限列表
hbase(main)> user_permission 't1'

3)收回权限
	 与分配权限类似,语法:revoke <user> <table> <column family><column qualifier>
	 例如,收回test用户在表t1上的权限
	hbase(main)> revoke 'test','t1'.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值