实验:熟悉常用的HBase操作
1实验目的
- 理解HBase在Hadoop体系结构中的角色;
- 熟练使用HBase操作常用的Shell命令;
2 实验平台
操作系统:Linux
Hadoop版本:3.1.3
HBase版本:2.2.2
JDK版本:1.8
3 实验内容和要求
1.用Hadoop提供的HBase Shell命令实现以下指定功能:
准备工作:
启动hbash:
./bin/start-hbase.sh
进入shell:
hbase shell
(1)列出HBase所有的表的相关信息,例如表名;
list
(2)在终端打印出指定的表的所有记录数据;
scan 'Student'
(3)向已经创建好的表添加和删除指定的列族或列;
在Student表中添加列number
alter 'Student','NAME'=>'number'
在Student表中删除列number
alter 'Student','NAME'=>'number',METHOD=>'delete'
(4)清空指定的表的所有记录数据;
清空custor表的所有记录数据
truncate ‘custor’
(5)统计表的行数。
统计Student表的行数:
count ‘Student’
2.现有以下关系型数据库中的表和数据,要求将其转换为适合于HBase存储的表并插入数据:
(1)创建Student表:
create 'Student','S_No','S_Name','S_Sex','S_Age'
添加记录数据:
put 'Student','s003','S_No','2015003' put 'Student','s003','S_Name','Lisi' put 'Student','s003','S_Sex','male' put 'Student','s003','S_Age','24' put 'Course','c001','C_No','123001' put 'Course','c001','C_Name','Math' put 'Course','c001','C_Credit','2.0' put 'Course','c002','C_No','123002' put 'Course','c002','C_Name','Computer' put 'Course','c002','C_Credit','5.0' put 'Course','c003','C_No','123003' put 'Course','c003','C_Name','English' put 'Course','c003','C_Credit','3.0'
(2)创建Couse表:
create 'Course','C_No','C_Name','C_Credit'
添加记录数据:
put 'Course','c001','C_No','123001' put 'Course','c001','C_Name','Math' put 'Course','c001','C_Credit','2.0' put 'Course','c002','C_No','123002' put 'Course','c002','C_Name','Computer' put 'Course','c002','C_Credit','5.0' put 'Course','c003','C_No','123003' put 'Course','c003','C_Name','English' put 'Course','c003','C_Credit','3.0'
(3)创建SC表:
create 'SC','SC_Sno','SC_Cno','SC_Score'
添加记录数据:
put 'SC','sc001','SC_Sno','2015001' put 'SC','sc001','SC_Cno','123001' put 'SC','sc001','SC_Score','86' put 'SC','sc002','SC_Sno','2015001' put 'SC','sc002','SC_Cno','123003' put 'SC','sc002','SC_Score','69' put 'SC','sc003','SC_Sno','2015002' put 'SC','sc003','SC_Cno','123002' put 'SC','sc003','SC_Score','77' put 'SC','sc004','SC_Sno','2015002' put 'SC','sc004','SC_Cno','123003' put 'SC','sc004','SC_Score','99' put 'SC','sc005','SC_Sno','2015003' put 'SC','sc005','SC_Cno','123001' put 'SC','sc005','SC_Score','98' put 'SC','sc006','SC_Sno','2015003' put 'SC','sc006','SC_Cno','123002' put 'SC','sc006','SC_Score','95'