集群启动及HBase相关命令
启动集群
/opt/hadoop-2.6.0/sbin/start-all.sh
分别启动三台节点上的zookeeper
./zkServer.sh start
启动hbase
./start-hbase.sh
进入hbase shell
工具
hbase shell
status
查看状态
help
查看帮助
Group name: ddl(对表进行操作的指令)
Commands: alter(修改表的结构), alter_async, alter_status, create(创建表), describe(描述表并把表的详细信息打印出来), disable(禁用表), disable_all, drop(删除表), drop_all, enable(启用表), enable_all, exists, get_table, is_disabled, is_enabled, list(查看用户空间里当前所有的表), show_filters
Group name: dml(对单元格的操作指令)
Commands: append, count, delete(删除一个单元格), deleteall, get(查询), get_counter, incr, put(新增或修改), scan(查询), truncate, truncate_preserve
表的创建和删
创建表
格式1:create ‘ NameSpace : TableName ‘ { NAME=>’liezuName’,VERSONS=>5 }
- NameSpace :命名空间(相当于数据库)
- TableName :表名
- NAME=>’liezuName’:列族的名称
VERSONS=>5:列族中每个单元格的(保留)版本,出现新版本的数据时,自动删除最旧版本
格式2:create ‘ TableName ‘ { NAME=>’f1’ } , { NAME=>’f2’ } , { NAME=>’f2’ }
使用默认的命名空间创建表
- 拥有三个列族:f1,f2,f3
- 简写:
create 'TableName','f1','f2','f3'
添加自定义的命名空间hadoop
(在自定义的名字空间创建新的表,得先添加自定义的命名空间)
create_namespace 'hadoop'
查看当前命名空间
list_namespace
在hadoop
名字空间下创建一个名为student的表 (有stu_info、sel_course两个列族)
create 'hadoop:student','stu_info','sel_course'
在默认的名字空间下创建一个名为student的表
create 'student','stu_info','sel_course'
list查看
(在相同的名字空间不能有同名的表,在不同的名字空间,表可以同名)
disable
将表禁用
disable 'student'
drop删除表
drop 'student'
(在删除表之前要先将表禁用)
数据的增加、删除以及查询
put(增加一个单元格数据)
put 'hadoop:student'(表名) , '1001'(学号) , 'stu_info:name'(列族:列名) , 'Tom'
get(获取一行数据或一行中某个单元格的内容)
get 'hadoop:student' ,'1001'
插入stature列
(身高)180
put 'hadoop:student' , '1001' , 'stu_info:stature', '180'
scan(获取整张表的数据)
scan 'hadoop:student'
继续添加新数据Lily
put 'hadoop:student' , '1002' , 'stu_info:name', 'Lily'
put几行新数据,Tom的英语分数,Lily的数学分数
put 'hadoop:student' , '1001' , 'sel_course:en', '85'
put 'hadoop:student' , '1002' , 'sel_course:ma', '90'
使用scan,取出列族sel_course下所有单元格的值
scan 'hadoop:student' , {COLUMNS=>['sel_course']}
使用scan,取出列族sel_course下所有学生的英语成绩
scan 'hadoop:student' , {COLUMNS=>['sel_course:en']}
添加Lily的身高
put 'hadoop:student' , '1002' , 'stu_info:stature', '165'
使用scan,列出列族sel_course下所有学生的身高
scan 'hadoop:student' , {COLUMNS=>['stu_info:stature']}
随便添加一个数据
put 'hadoop:student' , '1003' , 'stu_info:name', 'abc'
scan全表数据
delete删除数据(删除1003下name单元格的数据)
delete 'hadoop:student' , '1003' , 'stu_info:name'
插入图表中的数据
姓名
put 'hadoop:student' , '1001' , 'stu_info:name' , 'Tom'
put 'hadoop:student' , '1002' , 'stu_info:name' , 'Lily'
put 'hadoop:student' , '1003' , 'stu_info:name' , 'Mary'
put 'hadoop:student' , '1004' , 'stu_info:name' , 'Jack'
put 'hadoop:student' , '1005' , 'stu_info:name' , 'Rob'
put 'hadoop:student' , '1006' , 'stu_info:name' , 'John'
put 'hadoop:student' , '1007' , 'stu_info:name' , 'Alice'
put 'hadoop:student' , '1008' , 'stu_info:name' , 'Kate'
scan 'hadoop:student',{COLUMNS=>['stu_info:name']}
身高
put 'hadoop:student' , '1001' , 'stu_info:stature' , '180'
put 'hadoop:student' , '1002' , 'stu_info:stature' , '165'
put 'hadoop:student' , '1003' , 'stu_info:stature' , '172'
put 'hadoop:student' , '1004' , 'stu_info:stature' , '175'
put 'hadoop:student' , '1005' , 'stu_info:stature' , '177'
put 'hadoop:student' , '1006' , 'stu_info:stature' , '192'
put 'hadoop:student' , '1007' , 'stu_info:stature' , '163'
put 'hadoop:student' , '1008' , 'stu_info:stature' , '168'
scan 'hadoop:student',{COLUMNS=>['stu_info:stature']}
英语成绩
put 'hadoop:student' , '1001' , 'sel_course:en', '85'
put 'hadoop:student' , '1002' , 'sel_course:en', '72'
put 'hadoop:student' , '1003' , 'sel_course:en', '60'
put 'hadoop:student' , '1004' , 'sel_course:en', '95'
put 'hadoop:student' , '1005' , 'sel_course:en', '88'
put 'hadoop:student' , '1006' , 'sel_course:en', '78'
put 'hadoop:student' , '1007' , 'sel_course:en', '81'
put 'hadoop:student' , '1008' , 'sel_course:en', '68'
scan 'hadoop:student',{COLUMNS=>['sel_course:en']}
数学成绩
put 'hadoop:student' , '1001' , 'sel_course:ma', '100'
put 'hadoop:student' , '1002' , 'sel_course:ma', '90'
put 'hadoop:student' , '1003' , 'sel_course:ma', '85'
put 'hadoop:student' , '1004' , 'sel_course:ma', '80'
put 'hadoop:student' , '1005' , 'sel_course:ma', '70'
put 'hadoop:student' , '1006' , 'sel_course:ma', '86'
put 'hadoop:student' , '1007' , 'sel_course:ma', '60'
put 'hadoop:student' , '1008' , 'sel_course:ma', '85'
scan 'hadoop:student',{COLUMNS=>['sel_course:ma']}