需要提前安装好hadoop,mysql
1.下载hive软件
Index of /apache/hive/hive-3.1.3 (tsinghua.edu.cn)
2.解压缩
tar -zxvf ./apache-hive-3.1.3-bin.tar.gz -C /export/software/
cd /export/sofware
mv apache-hive-3.1.3-bin/ c
3.配置环境变量
vim /etc/profile
export HIVE_HOME=/export/software/hive3.1.3
export PATH=$PATH:$HIVE_HOME/bin
export HADOOP_HOME=/export/software/hadoop
souce /etc/profile
4.修改配置文件
- cd /export/software/hive3.1.3/conf
- mv hive-default.xml.template hive-default.xml
然后,使用vim编辑器新建一个配置文件hive-site.xml,命令如下:
- vim 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?useSSL=false&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>root</value> <description>username to use against metastore database</description> </property> <property> <name>javax.jdo.option.ConnectionPassword</name> <value>Fuhong119@</value> <description>password to use against metastore database</description> </property> <property> <name>hive.metastore.schema.verification</name> <value>false</value> <description> Enforce metastore schema version consistency. True: Verify that version information stored in is compatible with one from Hive jars. Also disable automatic schema migration attempt. Users are required to manually migrate schema after Hive upgrade which ensures proper metastore schema migration. (Default); False: Warn if the version information stored in metastore doesn't match with one from in Hive jars. </description> </property> <property> <name>datanucleus.schema.autoCreateAll</name> <value>true</value> </property> <property> <name>hive.conf.validation</name> <value>false</value> <description>Enables type checking for registered Hive configurations</description> </property> </configuration>
-
遇到问题
Exception in thread “main“ java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkAr
删除hive中低版本的guava-19.0.jar包,将hadoop中的/export/software/hadoop-3.2.4/share/hadoop/common/lib/guava-27.0-jre.jar复制到hive的lib目录下即可
-
java.lang.RuntimeException: Unable to instantiate org.apache.hadoop.hive.ql.metadata.SessionHiveMetaStoreClient
-
将mysql-connector-java-5.1.37.jar放入到hive-3.1.2/lib
-
Hive-site.xml 数据库连接要加useSSL=false
-
启动
./hive --service metastore &
-
执行hive命令
./hive
create table test(id int);
insert into test values(1);
select * from test;