文章目录
- 问题
- 解决
问题
hms使用mysql作为Backend metadata database, 但是启动爆如下错误.
Underlying cause: com.mysql.cj.jdbc.exceptions.CommunicationsException : Communications link failureThe last packet sent successfully to the server was 0 milliseconds ago. The driver has not received any packets from the server.
docker 文件
FROM docker.io/apache/hive:4.0.0
COPY ./mysql-connector-java-8.0.25.jar /opt/hive/lib/
COPY ./postgresql-42.7.3.jar /opt/hive/lib/
原生的hive不带pg以及mysql的驱动包,所以这里要自己构建镜像添加这两个包到/opt/hive/lib
目录下.
docker-compose 文件
version: '3'
services:hms:image: custom_hive:latestports:- "9083:9083"environment:SERVICE_NAME: metastoreDB_DRIVER: mysqlSERVICE_OPTS: -Djavax.jdo.option.ConnectionDriverName=com.mysql.cj.jdbc.Driver -Djavax.jdo.option.ConnectionURL=jdbc:mysql://metadb:3306/metastore?createDatabaseIfNotExist=true -Djavax.jdo.option.ConnectionUserName=root -Djavax.jdo.option.ConnectionPassword=abcdvolumes:- warehouse:/opt/hive/data/warehouselinks:- metadbdepends_on:- metadbmetadb:image: mysql:8.0container_name: metadbports: - "3306:3306"environment:- "MYSQL_ROOT_PASSWORD=abcd"volumes:warehouse:networks:default:name: test-net
解决
原因是连接的urljdbc:mysql://metadb:3306/metastore?createDatabaseIfNotExist=true
即便有参数createDatabaseIfNotExist=true
设置为true还是不能自动创建databse
.所以要预先在mysql上面创建好metastore
这个数据库,hms才能启动成功.