目录
大数据平台架构实战(一)hadoop搭建
大数据平台架构实战(二)IntelliJ IDEA搭建hadoop
为什么需要Hive
Hive简介
安装步骤
下载
GettingStarted - Apache Hive - Apache Software Foundation
官网讲的有点啰嗦,把好多的安装版本都罗列在一起了。
这里我们先安装derby版的hive
下载的时候,要看清楚版本之间的约束,还是官网:Downloads
我们选择2.3.9,由于前面我们用hadoop是2.10.2。进入archive里面下载对应的版本Index of /hive
安装
解压:
tar -xzvf hive-x.y.z.tar.gz
设定环境变量,vim ~/.bash_profile
export HIVE_HOME=/Users/xxxx/opt/apache-hive-2.3.9-bin
export PATH=$PATH:$HIVE_HOME/bin
如果不设定环境变量,需要在hive-env.sh里面指定好对应的地址。(别忘了source ~/.bash_profile)
修改hive配置文件
cp hive-default.xml.template hive-site.xml
<?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
<configuration>
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:derby:;databaseName=metastore_db;create=true</value>
</property>
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>org.apache.derby.jdbc.EmbeddedDriver</value>
</property>
<property>
<name>hive.metastore.local</name>
<value>true</value>
</property>
<property>
<name>hive.metastore.warehouse.dir</name>
<value>/hive/warehouse</value>
</property>
</configuration>
修改env文件, vim hive-env.sh
export HIVE_CONF_DIR=$HIVE_HOME/conf
初始化shcema
bin/schematool -initSchema -dbType derby --verbose
启动hive
hive
hive基本命令
show databases;
show tables;
create database abc;
create table t_user(id string,name string,age int);
desc t_user;
insert into t_user values('1001','zhangsan',20);
show create table t_user;
desc database abc;
select current_database();
遇到问题
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/Users/xxx/opt/apache-hive-2.3.9-bin/lib/log4j-slf4j-impl-2.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/Users/xxxx/opt/hadoop-2.10.1/share/hadoop/common/lib/slf4j-log4j12-1.7.25.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory]
里面写的很清晰,多个绑定,删除一个就行了
lib mv log4j-slf4j-impl-2.6.2.jar log4j-slf4j-impl-2.6.2.jar.bak
Error: FUNCTION 'NUCLEUS_ASCII' already exists. (state=X0Y68,code=30000)
这是没有进行schema初始化之前,运行过hive命令,自动产生了db文件,删除后,按照步骤来就行,先init shcema,再启动hive
mv metastore_db metastore_db.tmp