hive的安装模式有2种,一种是使用自带的derby数据库,另一种是使用mysql作为元数据库。derby方式一般没人用,因为它是单用户模式。
安装前准备
(1)保证 hadoop 正常运行
(2)保证 mysql 正常运行
CentOS7 hadoop安装教程:
CentOS7 mysql 安装教程:https://www.cnblogs.com/caoxb/p/9405323.html
hive安装步骤
1.下载
$ cd /usr/local
2.解压
$ tar -zxvf apache-hive-2.3.5-bin.tar.gz
3.修改配置文件
主要有两个配置文件要进行修改:hive-default.xml 和 hive-site.xml 。在hive安装的conf目录下,没有这两个配置文件,只有一个"hive-default.xml.template",所以我们要复制一个"hive-default.xml.template",命名为hive-default.xml,及新建一个文件hive-site.xml。
$ cd apache-hive-2.3.5-bin/conf
$ cp hive-default.xml.template hive-default.xml
$ vim hive-site.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?> <?xml-stylesheet type="text/xsl" href="configuration.xsl"?> <configuration> <!-- ########################### hive的 JDBC连接 ############################ --> <!-- mysql 连接用户名 --> <property> <name>javax.jdo.option.ConnectionUserName</name> <value>caoxiaobo</value> </property> <!-- mysql 连接密码 --> <property> <name>javax.jdo.option.ConnectionPassword</name> <value>Caoxiaobo0917!</value> </property> <!-- mysql 连接URL 如果hive和mysql在同一服务器上,使用localhost --> <property> <name>javax.jdo.option.ConnectionURL</name> <value>jdbc:mysql://localhost:3306/myhive</value> </property> <!-- mysql 连接驱动 --> <property> <name>javax.jdo.option.ConnectionDriverName</name> <value>com.mysql.jdbc.Driver</value> </property> </configuration>
备注:hive-default.xml用于保留默认配置,hive-site.xml用于个性化配置,可覆盖默认配置
4.添加驱动包
将mysql的驱动包放在hive安装的lib目录下
如果不添加驱动包的话,下执行初始化的时候会抛出 Underlying cause: java.lang.ClassNotFoundException : com.mysql.jdbc.Driver 异常。
我这里是在阿里云maven库下载的

上传jar包到hive的安装目录
$ scp -r /c/Users/96492/Desktop/mysql-connector-java-5.1.6.jar root@192.168.38.41:/usr/local/apache-hive-2.3.5-bin/lib
5.初始化元数据库
hive 1.0版本不需要初始化元数据库。
$ ./schematool -dbType mysql -initSchema
$ ./schematool -dbType mysql -initSchema .... SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation. SLF4J: Actual binding is of type [org.apache.logging.slf4j.Log4jLoggerFactory] Metastore connection URL: jdbc:mysql://localhost:3306/myhive Metastore Connection Driver : com.mysql.jdbc.Driver Metastore connection User: caoxiaobo Starting metastore schema initialization to 2.3.0 Initialization script hive-schema-2.3.0.mysql.sql Initialization script completed schemaTool completed
6.启动hive
在hive安装的bin目录下直接全用./hive命令就可以启动。
$ ./hive
7.测试
hive> create database test; # 创建test数据库 OK Time taken: 0.069 seconds hive> use test; # 进入test数据库 OK Time taken: 0.068 seconds hive> create table tt(id int); # 创建表 tt OK Time taken: 1.886 seconds hive> show tables; # 查看test库中所有的表 OK tt Time taken: 0.093 seconds, Fetched: 1 row(s)