通过docker在MYSQL数据库上使用NodeJS后端时的ER_NOT_SUPPORTED_AUTH_MODE

时间:2019-06-14 09:29:29

标签: mysql node.js docker docker-compose dockerfile

我在通过Docker部署应用程序时遇到问题。我有一个NodeJS(快速)支持,一个ReactJS前端和一个MYSQL数据库。每个人都应该获得一个自己的容器来让他们交流。

前端和后端通信可以完美地工作,但是它们无法访问数据库。我收到以下错误:

Unhandled rejection Error: ER_NOT_SUPPORTED_AUTH_MODE: Client does not support authentication protocol requested by server; consider upgrading MySQL client

我遵循以下答案:MySQL 8.0 - Client does not support authentication protocol requested by server; consider upgrading MySQL client,并在docker容器上使用了它。但是错误仍然存​​在。

这是我的docker-compose.yml:

version: '2.1'

services:

#DB
  mysql:
    build: ./database
    environment:
      - MYSQL_ALLOW_EMPTY_PASSWORD=yes
    healthcheck:
      test: "exit 0"
    ports:
      - 3306:3306
    expose:
      - 3306
#API
  api:
    build: ./api
    depends_on:
      mysql:
        condition: service_healthy
    expose:
      - ${APP_SERVER_PORT}
    environment:
      API_HOST: ${API_HOST}
      APP_SERVER_PORT: ${APP_SERVER_PORT}
      MYSQL_HOST: mysql
      MYSQL_PORT: 3306
      MYSQL_USER: root
      MYSQL_PASSWORD: *mypassword*
      MYSQL_DATABASE: cinema
    ports:
      - ${APP_SERVER_PORT}:${APP_SERVER_PORT}
    volumes:
      - ./api:/usr/src/app/cinema_api
    command: npm start
#CLIENT
  client:
    build: ./client
    environment:
      - REACT_APP_PORT=${REACT_APP_PORT}
    expose:
      - ${REACT_APP_PORT}
    ports:
      - ${REACT_APP_PORT}:${REACT_APP_PORT}
    volumes:
      - ./client:/usr/src/app/cinema_client
    links:
      - api
    command: npm start

还有我的数据库Dockerfile:

FROM mysql
COPY init_db.sql /docker-entrypoint-initdb.d/
RUN chmod -R 775 /docker-entrypoint-initdb.d

在init_db.sql中,我有:

CREATE DATABASE IF NOT EXISTS cinema;
GRANT ALL PRIVILEGES on cinema.* TO 'root'@'localhost' 
IDENTIFIED BY *mypassword* WITH GRANT OPTION;

...之后是我的数据库的mysqldump。

0 个答案:

没有答案