ads:
关注以下公众号查看更多文章
hive目前最新版本为3.1.2,下载地址:https://mirrors.tuna.tsinghua.edu.cn/apache/hive/hive-3.1.2/apache-hive-3.1.2-bin.tar.gz
hadoop安装教程参考链接:hadoop3.2.1集群搭建
hadoop高可用配置,参考链接:hadoop 3.2.1 hdfs高可用集群搭建
在hadoop项目下执行以下几条命令:
bin/hdfs dfs -mkdir /tmp
bin/hdfs dfs -mkdir -p /user/hive/warehouse
bin/hdfs dfs -chmod g+w /tmp
bin/hdfs dfs -chmod g+w /user/hive/warehouse
conf/hive-env.sh
HADOOP_HOME=/home/software/hadoop-3.2.1
export HIVE_CONF_DIR=/home/software/hive-3.1.2/conf
HIVE_AUX_JARS_PATH
hive-log4j.properties: hive.log.dir
hive-site.xml
<configuration>
<property>
<name>hive.metastore.uris</name>
<value>thrift://mustafa-PC:9083</value>
</property>
<property>
<name>hive.metastore.warehouse.dir</name>
<value>/user/hive/warehouse</value>
</property>
<property>
<name>hive.exec.compress.intermediate</name>
<value>true</value>
</property>
<property>
<name>hive.fetch.task.conversion</name>
<value>more</value>
</property>
<property>
<name>hive.auto.convert.sortmerge.join</name>
<value>true</value>
</property>
<property>
<name>hive.auto.convert.join</name>
<value>true</value>
</property>
<property>
<name>javax.jdo.option.ConnectionURL</name>
<value>jdbc:mysql://172.17.0.3:3221/hive</value>
</property>
<property>
<name>javax.jdo.option.ConnectionDriverName</name>
<value>com.mysql.jdbc.Driver</value>
</property>
<property>
<name>javax.jdo.option.ConnectionUserName</name>
<value>hive</value>
</property>
<property>
<name>javax.jdo.option.ConnectionPassword</name>
<value>hive</value>
</property>
<property>
<name>hive.cli.print.header</name>
<value>true</value>
</property>
<property>
<name>hive.cli.print.current.db</name>
<value>true</value>
</property>
</configuration>
另外,需要在lib目录中放入mysql驱动:mysql-connector-java-5.1.42-bin.jar
初始化mysql数据库:
schematool -dbType mysql -initSchema
启动metastore
bin/hive --service metastore &
bin/hive进入hive命令行,执行语句:
create database if not exists hadoop14;
use hadoop14;
create table student (
num int, name string
)
row format delimited fields terminated by '\t'
;
load data local inpath 'student.txt' into table student;
select * from student;
踩坑之路:
Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;Ljava/lang/Object;)V
这是因为hive内依赖的guava.jar和hadoop内的版本不一致造成的。 检验方法:
- 查看hadoop安装目录下share/hadoop/common/lib内guava.jar版本
- 查看hive安装目录下lib内guava.jar的版本 如果两者不一致,删除版本低的,并拷贝高版本的 问题解决!
修改mysql中hive库里的表的某些字段字符集设置,避免在hive中设置的中文注释有乱码(很重要!!)
使用hive用户登录mysql服务的命令行,执行如下命令
#修改hive元数据表中注解相关字段为utf8:
alter table COLUMNS_V2 modify column COMMENT varchar(256) character set utf8;
alter table TABLE_PARAMS modify column PARAM_VALUE varchar(4000) character set utf8;
alter table PARTITION_PARAMS modify column PARAM_VALUE?varchar(4000) character set utf8 ;
alter table PARTITION_KEYS modify column PKEY_COMMENT varchar(4000) character set utf8;
alter table INDEX_PARAMS modify column PARAM_VALUE varchar(4000) character set utf8;