Apache Hive环境搭建错误:com.mysql.jdbc.Driver was not found in the CLASSPATH

Apache Hive环境搭建错误:com.mysql.jdbc.Driver was not found in the CLASSPATH

错误场景详情

1
2
3
4
5
6
7
8
9
10
11
12
13
$ $HIVE_HOME/bin/schematool -dbType mysql -initSchema
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/usr/local/Cellar/hive/3.1.2/libexec/lib/log4j-slf4j-impl-2.10.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/usr/local/Cellar/hadoop/3.2.1/libexec/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]
Metastore connection URL: jdbc:mysql://localhost:3306/hive?characterEncoding=UTF-8
Metastore Connection Driver : com.mysql.jdbc.Driver
Metastore connection User: hadoop
org.apache.hadoop.hive.metastore.HiveMetaException: Failed to load driver
Underlying cause: java.lang.ClassNotFoundException : com.mysql.jdbc.Driver
Use --verbose for detailed stacktrace.
*** schemaTool failed ***

错误原因

在配置hive-site.xml文件时配置了mysql驱动,而hive/lib目录下没有mysql驱动包。

解决方案

官网下载mysql驱动下载地址 (https://dev.mysql.com/downloads/connector/j/)
把下载好的压缩包(mysql-connector-java-8.0.18.zip)进行解压
unzip mysql-connector-java-8.0.18.zip
复制到hive/lib下
cp mysql-connector-java-8.0.18/mysql-connector-java-8.0.18.jar hive/lib