2 安装
2.1 参考
2.1.1 下载
2.1.1.1 https://mirrors.tuna.tsinghua.edu.cn/apache/hive/stable-2/
2.1.2 安装指导
2.1.2.1 https://cwiki.apache.org/confluence/display/Hive/GettingStarted
2.1.3 依赖
2.1.3.1 https://cwiki.apache.org/confluence/display/Hive/GettingStarted#GettingStarted-Requirements
2.2 步骤
2.2.1 默认derby元数据库
2.2.1.1 参考
2.2.1.1.1 http://blog.csdn.net/s646575997/article/details/51366179
2.2.1.1.2 http://www.cnblogs.com/machong/p/5633346.html
2.2.2 安装MySQL
2.2.2.1 参考
2.2.2.1.1 https://support.rackspace.com/how-to/installing-mysql-server-on-ubuntu/
2.2.3 解压HIVE、配置环境变量HIVE_HOME/PATH
2.2.4 配置hive-site.xml
2.2.4.1 元数据使用MySQL存储
2.2.4.2 javax.jdo.option.ConnectionURL
2.2.4.2.1 jdbc:mysql://10.20.0.11:3306/db_hive?createDatabaseIfNotExist=true &useUnicode=true&characterEncoding=utf8
2.2.4.3 javax.jdo.option.ConnectionDriverName
2.2.4.3.1 com.mysql.jdbc.Driver
2.2.4.4 javax.jdo.option.ConnectionUserName
2.2.4.4.1 hive
2.2.4.5 javax.jdo.option.ConnectionPassword
2.2.4.5.1 Hive@123
2.2.4.6 修改临时目录
2.2.4.6.1 hive.querylog.location、hive.server2.logging.operation.log.location hive.exec.local.scratchdir、hive.downloaded.resources.dir
2.2.4.6.2 参考
2.2.4.6.2.1 http://blog.csdn.net/jdplus/article/details/46493553
2.2.5 修改HIVE日志路径
2.2.5.1 hive-log4j2.properties、hive-exec-log4j2.properties、llap-cli-log4j2.properties
2.2.6 MySQL驱动
2.2.6.1 下载
2.2.6.1.1 http://mvnrepository.com/artifact/mysql/mysql-connector-java
2.2.6.1.2 驱动向下兼容(eg: 5.1.38)
2.2.6.2 拷贝MySQL驱动到HIVE的lib目录
2.2.7 元数据库初始化
2.2.7.1 schematool -initSchema -dbType mysql
2.2.8 启动hive
2.3 使用
2.3.1 查询/创建库、表等;不支持INSERT等。因为HDFS本身就不应该支持随机写入功能。HIVE是为了实现OLAP。
2.3.2 数据表与HDFS数据关联
2.3.2.1 建表之后数据导入
2.3.2.2 建表时指定文件目录
2.3.3 建表
2.3.3.1 语法
2.3.3.1.1 CREATE TABLE page_view(viewTime INT, userid BIGINT,page_url STRING,referrer_url STRING,ip STRING COMMENT 'IP Address of the User') COMMENT 'This is the page view table' PARTITIONED BY(dt STRING, country STRING) ROW FORMAT DELIMITED FIELDS TERMINATED BY ' 01' STORED AS SEQUENCEFILE; TEXTFILE
2.3.3.2 示例
2.3.3.2.1 create database db_order; use db_order; //////////////////////////////////////////////////////////////////////////////////////////////////////// create table tbl_order(id int, name string, size string, price double) row format delimited fields terminated by ' '; //////////////////////////////////////////////////////////////////////////////////////////////////////// load data local inpath 'order.txt' into table tbl_order; //////////////////////////////////////////////////////////////////////////////////////////////////////// select * from tbl_order; select count(*) from tbl_order;
推荐:
http://blog.csdn.net/jdplus/article/details/46493553