一、前提
-安装好 hadoop集群
-安装好 mysql
二、配置
-配置环境变量
-配置bin下hive-config.sh
export JAVA_HOME=/usr/local/spark/jdk1.8.0_73
export HADOOP_HOME=/usr/local/spark/hadoop-2.6.0
export HIVE_HOME=/usr/local/spark/apache-hive-1.2.1-bin
-配置 conf 下的 hive-site.xml
<configuration>
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://master:3306/hive?createDatabaseInfoNotExist=true</value>
</property>
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.jdbc.Driver</value>
</property>
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>root</value>
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>123456</value>
</property>
<property>
<name>hive.metastore.warehouse.dir</name>
<value>/user/hive/warehouse</value>
</property>
</configuration>
注:
1.mysql中需要提前建数据库 hive 不然会报错
2.安装过程可能会报以下错
[ERROR] Terminal initialization failed; falling back to unsupported
java.lang.IncompatibleClassChangeError: Found class jline.Terminal, but interface was expected
原因:
hadoop目录下存在老版本jline:
/hadoop-2.6.0/share/hadoop/yarn/lib:
-rw-r--r-- 1 root root 87325 Mar 10 18:10 jline-0.9.94.jar
解决:
cp /hive/apache-hive-1.1.0-bin/lib/jline-2.12.jar /hadoop-2.5.2/share/hadoop/yarn/lib
三、操作
运行 hive进行shell模式
建表
create table employee(id int, name String, salary double, country String) Row Format delimited fields terminated by '\|' lines terminated by '\n';
导入数据
load data local inpath "/usr/local/spark/apache-hive-1.2.1-bin/examples/files/employee_part.txt" into table employee;
overwrite 模式导入数据
load data local inpath "/usr/local/spark/apache-hive-1.2.1-bin/examples/files/employee_part.txt" overwrite into table employee;
查询表
select * from employee;
进入 hdfs查看数据
http://work1:50070/explorer.html#/user/hive/warehouse