大數據之Hadoop學習(八)HBase Shell數據庫表創建


根據以下關係型數據庫表,使用HBase Shell設計並創建適宜的HBase數據表
在這裏插入圖片描述

一、啓動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

在這裏插入圖片描述

二、創建表

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'

在這裏插入圖片描述

②、新增學號爲2015002的學生信息過後表的數據

get 'StudentAdmin','2015002'

在這裏插入圖片描述

③、學生信息全都新增過後表的數據

get 'StudentAdmin','2015003'

在這裏插入圖片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章