一、背景:
需求:需要上传Hive连接mysql的驱动,进行Hive元数据初始化
驱动一:Hive连接datagrip的驱动路径+驱动名称:D:\hive-jdbc-3.1.2-standalone.jar
驱动二:Hive连接mysql的驱动+驱动名称:D:\mysql-connector-java-5.1.32.jar
二、现象
上传驱动:错误上传成①的驱动,
然后对Hive的元数据进行初始化,显示如下报错:
[root@node1 lib]# rz
rz waiting to receive.
Starting zmodem transfer. Press Ctrl+C to cancel.
Transferring hive-jdbc-3.1.2-standalone.jar...
100% 70722 KB 23574 KB/sec 00:00:03 0 Errors
[root@node1 lib]# cd /export/server/apache-hive-3.1.2-bin/
[root@node1 apache-hive-3.1.2-bin]# bin/schematool -initSchema -dbType mysql -verbos
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/export/server/apache-hive-3.1.2-bin/lib/log4j-slf4j-impl-2.10.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/export/server/hadoop-3.3.0/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://node1:3306/hive3?createDatabaseIfNotExist=true&useSSL=false&useUnicode=true&characterEncoding=UTF-8
Metastore Connection Driver : com.mysql.jdbc.Driver
Metastore connection User: root
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 ***
三、解决
1.初始化失败了,思路:
①优先判断配置的用户名密码是否正确
②地址写的对不对,驱动写的对不对
2.报错分析:
①hive.metastore元数据 HiveMetaException配置单元元异常 Failed to load driver 未能成功加载驱动
②Underlying cause根本原因 java.lang 语言太长了 ClassNotFoundException类未找到异常 com.mysql.jdbc.Driver (mysql驱动)
3.小结:
①显示驱动未加载成功,但是我们上面上传驱动显示是成功的,所以说明上传没问题,传错了。
②显示mysql的驱动显示异常,就说明Hive连接mysql驱动出现异常,说明在Hive驱动,因为mysql驱动我们没动。
四、拓展:
当我们加载错驱动了,这个时候驱动时可以共存的,但是课程中讲解是只用这一个驱动,所以,想想办法删掉这个驱动吧!
①找到这个驱动的放置的文件夹
[root@node1 lib]# pwd
/export/server/apache-hive-3.1.2-bin/lib
[root@node1 lib]#
②找到错误装上去的驱动,将这个驱动删除
rm -rf hive-jdbc-3.1.2-standalone.jar
③继续加载二的驱动,初始化后显示成功
[root@node1 lib]# rz
rz waiting to receive.
Starting zmodem transfer. Press Ctrl+C to cancel.
Transferring mysql-connector-java-5.1.32.jar...
100% 946 KB 946 KB/sec 00:00:01 0 Errors
[root@node1 lib]# cd /export/server/apache-hive-3.1.2-bin
[root@node1 apache-hive-3.1.2-bin]# bin/schematool -initSchema -dbType mysql -verbos
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/export/server/apache-hive-3.1.2-bin/lib/log4j-slf4j-impl-2.10.0.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/export/server/hadoop-3.3.0/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://node1:3306/hive3?createDatabaseIfNotExist=true&useSSL=false&useUnicode=true&characterEncoding=UTF-8
Metastore Connection Driver : com.mysql.jdbc.Driver
Metastore connection User: root
Starting metastore schema initialization to 3.1.0
Initialization script hive-schema-3.1.0.mysql.sql
Initialization script completed
schemaTool completed