Bootstrap

hive metastore使用mysql作为backend db遇到的问题

文章目录

问题

hms使用mysql作为Backend metadata database, 但是启动爆如下错误.

Underlying cause: com.mysql.cj.jdbc.exceptions.CommunicationsException : Communications link failure

The 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:latest
    ports:
      - "9083:9083"
    environment:
      SERVICE_NAME: metastore
      DB_DRIVER: mysql
      SERVICE_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=abcd
    volumes:
      - warehouse:/opt/hive/data/warehouse
    links:
      - metadb
    depends_on:
      - metadb

  metadb:
    image: mysql:8.0
    container_name: metadb
    ports: 
      - "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才能启动成功.

;