大数据之Hadoop学习(八)HBase Shell数据库表创建

HBase Shell数据库表创建

    • 一、启动Hadoop和HBase
        • 1.启动Hadoop
        • 2.启动HBase
        • 3.进入shell
    • 二、创建表
    • 三、插入数据
        • ①新增学号为2015001的学生的所有信息
        • ②、新增学号为2015002的学生的所有信息
        • ③、新增学号为2015003的学生的所有信息
    • 四、查看表的数据
        • ①、新增学号2015001的学生信息过后表的数据
        • ②、新增学号为2015002的学生信息过后表的数据
        • ③、学生信息全都新增过后表的数据

根据以下关系型数据库表,使用HBase Shell设计并创建适宜的HBase数据表
大数据之Hadoop学习(八)HBase Shell数据库表创建_第1张图片

一、启动Hadoop和HBase

1.启动Hadoop

cd /usr/local/hadoop/
./sbin/start-dfs.sh

在这里插入图片描述

2.启动HBase

cd /usr/local/hbase/
bin/start-hbase.sh

在这里插入图片描述

3.进入shell

./bin/hbase shell

大数据之Hadoop学习(八)HBase Shell数据库表创建_第2张图片

二、创建表

create 'StudentAdmin','student','course1','course2','course3'

在这里插入图片描述

三、插入数据

学号作为RowKey即行键,因此插入数据时不必在插入学生编号,同时课程建了三个列族,用于存储同一行键下的不同课程

①新增学号为2015001的学生的所有信息

put 'StudentAdmin','2015001','student:S_Name','Zhangsan'
put 'StudentAdmin','2015001','student:S_Age','23'
put 'StudentAdmin','2015001','student:S_Sex','male'
put 'StudentAdmin','2015001','course1:C_No','123001'
put 'StudentAdmin','2015001','course1:C_Name','Math'
put 'StudentAdmin','2015001','course1:C_Credit','2.0'
put 'StudentAdmin','2015001','course1:Score','86'
put 'StudentAdmin','2015001','course3:C_No','123003'
put 'StudentAdmin','2015001','course3:C_Name','English'
put 'StudentAdmin','2015001','course3:C_Credit','3.0'
put 'StudentAdmin','2015001','course3:Score','69'

②、新增学号为2015002的学生的所有信息

put 'StudentAdmin','2015002','student:S_Name','Mary'
put 'StudentAdmin','2015002','student:S_Age','22'
put 'StudentAdmin','2015002','student:S_Sex','female'
put 'StudentAdmin','2015002','course2:C_No','123002'
put 'StudentAdmin','2015002','course2:C_Name','Computer Science'
put 'StudentAdmin','2015002','course2:C_Credit','5.0'
put 'StudentAdmin','2015002','course2:Score','77'
put 'StudentAdmin','2015002','course3:C_No','123003'
put 'StudentAdmin','2015002','course3:C_Name','English'
put 'StudentAdmin','2015002','course3:C_Credit','3.0'
put 'StudentAdmin','2015002','course3:Score','99'

③、新增学号为2015003的学生的所有信息

put 'StudentAdmin','2015003','student:S_Name','Lisi'
put 'StudentAdmin','2015003','student:S_Age','24'
put 'StudentAdmin','2015003','student:S_Sex','male'
put 'StudentAdmin','2015003','course1:C_No','123001'
put 'StudentAdmin','2015003','course1:C_Name','Math'
put 'StudentAdmin','2015003','course1:C_Credit','2.0'
put 'StudentAdmin','2015003','course1:Score','98'
put 'StudentAdmin','2015003','course2:C_No','123002'
put 'StudentAdmin','2015003','course2:C_Name','Computer Science'
put 'StudentAdmin','2015003','course2:C_Credit','5.0'
put 'StudentAdmin','2015003','course2:Score','95'

四、查看表的数据

①、新增学号2015001的学生信息过后表的数据

get 'StudentAdmin','2015001'

大数据之Hadoop学习(八)HBase Shell数据库表创建_第3张图片

②、新增学号为2015002的学生信息过后表的数据

get 'StudentAdmin','2015002'

大数据之Hadoop学习(八)HBase Shell数据库表创建_第4张图片

③、学生信息全都新增过后表的数据

get 'StudentAdmin','2015003'

大数据之Hadoop学习(八)HBase Shell数据库表创建_第5张图片

你可能感兴趣的:(大数据之Hadoop学习)