1、 进入Hbase shell
sz280328:cloudera-scm@/home/cloudera-scm>hbase shell
2、 建表,插入一行数据
hbase(main):001:0> create 'hbase_stu', 'stu_info', 'score'
hbase(main):002:0> list
hbase(main):003:0> put 'hbase_stu', '001', 'stu_info:name','tom'
hbase(main):004:0> put 'hbase_stu', '001', 'stu_info:age', 18
hbase(main):005:0> put 'hbase_stu', '001', 'stu_info:gender', 'man'
hbase(main):006:0> put 'hbase_stu', '001', 'score:Chinese', 91
hbase(main):007:0> put 'hbase_stu', '001', 'score:Math', 90
hbase(main):008:0> put 'hbase_stu', '001', 'score:English', 89
hbase(main):009:0> desc 'hbase_stu'
hbase(main):010:0> scan 'hbase_stu'
3、 批量增加数据
hbase(main):011:0> exit
创建文档stu.txt,写入脚本,9行数据
sz280328:cloudera-scm@/var/tmp/aoqi>hbase shell stu.txt
hbase(main):001:0> scan 'hbase_stu'
4、 HIVE新建外部表,查询数据
hive> show databases;
hive> use aq_db;
hive> create external table hh (key STRING,
name STRING,
age INT,
gender STRING,
Chinese INT,
Math INT,
English INT)
stored by 'org.apache.hadoop.hive.hbase.HBaseStorageHandler' with serdeproperties ("hbase.columns.mapping"=":key,stu_info:name,stu_info:age,stu_info:gender,score:Chinese,score:Math,score:English") tblproperties("hbase.table.name"="hbase_stu");
hive> desc hh;
hive> select * from hh;
hive> describe extended hh; 查看表的详细信息
5、 HIVE操作表
hive> select count(*) from hh;
hive> select name from hh where age<18;