下载地址
https://mirrors.tuna.tsinghua.edu.cn/apache/hive/hive-2.3.4/
- 下载
apache-hive-2.3.4-bin.tar.gz
解压文件
tar -zxvf apache-hive-2.3.4-bin.tar.gz -C ../module/
安装和配置mariadb
-
安装
yum install mariadb-server mariadb
-
配置
systemctl start mariadb #启动MariaDB
systemctl stop mariadb #停止MariaDB
systemctl restart mariadb #重启MariaDB
systemctl enable mariadb #设置开机启动
- 登录
root
账户(默认无密码)
mysql -u root -p
- 创建新账户用户
hive
CREATE USER 'hive'@'%' IDENTIFIED BY 'hive';
GRANT ALL PRIVILEGES ON *.* TO 'hive'@'%' IDENTIFIED BY 'hive';
FLUSH PRIVILEGES;
开始hive配置
- 配置环境变量
#hive
HIVE_HOME=/opt/module/hive
PATH=$HIVE_HOME/bin:$PATH
PATH=$HIVE_HOME/sbin:$PATH
- 在
conf
目录下新建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&useSSL=false</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>
<property>
<name>datanucleus.autoStartMechanism</name>
<value>SchemaTable</value>
</property>
<property>
<name>datanucleus.schema.autoCreateAll</name>
<value>true</value>
</property>
</configuration>
- 初始化
hive
元数据表
schematool -dbType mysql -initSchema
测试
- 输入
hive
,创建表create table test (id int,name string);
,查看表show tables;
遇到的坑
- MySQL遇到的坑
[heasy@spark001 conf]$ mysql -u hive -p
Enter password:
ERROR 1045 (28000): Access denied for user 'hive'@'localhost' (using password: YES)
可能存在用户名相同,但是权限不同的用户,查看user表,看下创建的用户的Host
字段是不是%
.如果是,可以使用
GRANT ALL PRIVILEGES ON *.* TO 'hive'@'%' IDENTIFIED BY 'hive';
FLUSH PRIVILEGES;
```重新授权试下,然后使用`mysql -uhvie -p`登录测试下,是否可以登录成功。
- hive中遇到的坑
create table test (id int,name string);
FAILED: SemanticException org.apache.hadoop.hive.ql.metadata.HiveException: java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient
这个提示就大概意思是和元数据表没有连通,修改修复mysql中遇到的坑,就可以正常使用了
- hive启动时提示sl4j包冲突
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/opt/module/hive/lib/log4j-slf4j-impl-2.6.2.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/opt/module/hadoop/share/hadoop/common/lib/slf4j-log4j12-1.7.5.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]
原因是hive启动时会从多处进行jar包加载,sl4j这个jar在其他中间已经加载了。先从一出一个jar