环境
hadoop3.1.2
centOS 7
mysql 5.1.32
安装
-
下载并解压到/home/hadoop,避免没有权限创建metastore_db文件
-
配置hive环境变量
-
修改配置文件 进入hive/conf
mv hive-default.xml.template hive-default.xml
vi hive-site.xml
hive-site.xml内容如下
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://localhost:3306/hive?createDatabaseIfNotExist=true</value>
<description>JDBC connect string for a JDBC metastore</description>
</property>
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.jdbc.Driver</value>
<description>Driver class name for a JDBC metastore</description>
</property>
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>hive</value>
<description>username to use against metastore database</description>
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>hive</value>
<description>password to use against metastore database</description>
</property>
</configuration>
mysql的地址localhost根据具体安装ip修改
- 配置mysql环境 进入mysql终端,执行以下命令
create database hive;
grant all on *.* to hive@localhost identified by 'hive';
flush privileges;
在hive的lib文件下加入mysql-connector-java-5.1.32.jar驱动,否则启动hive会提示找不到驱动
- 初始化当前 Hive 版本的 Metastore 架构
schematool -dbType mysql -initSchema
问题
- Failed to get schema version when starting Hive Metastore Service
grant all privileges on *.* to hive@'172.18.0.103' identified by 'hive';
- org.apache.hadoop.hive.metastore.HiveMetaException: Schema initialization FAILED! Metastore state would be inconsistent !!
具体原因:hive Cannot execute statement: impossible to write to binary log ....
第一步:
set global binlog_format='MIXED';
第二步:
删除mysql的hive数据库下所有表
hive应用
在hadoop用户目录下创建input测试数据
进入hive
创建表 加载原始数据
在docs表基础上创建word_count表来存储统计结果,从打印信息可以看出,hive是将hiveQL转化为mapreduce的job任务, 此外新版hive可能不再支持mapreduce,而是改为使用spark,tez等计算框架
查看生产的word_count表,并显示统计结果