无法从其他容器访问mysql容器

7rtdyuoh  于 2021-06-21  发布在  Mysql
关注(0)|答案(0)|浏览(272)

我使用docker compose运行mysql和api服务器。一旦api服务器在上面,就使用connecttomysql,但我总是被拒绝访问。我已经添加了sql来授予权限,但它仍然不起作用。请有人帮帮我。
错误

2018-05-03T05:48:45.868146Z 2 [Note] Access denied for user 'mysql'@'172.18.0.3' (using password: YES)

这是我的 Docker

version: "3.6"
services:
  mysql:
    build:
      context: ..
      dockerfile: docker/Dockerfile-mysql
    image: test_mysql:ci-label
    container_name: test-mysql-ci-label
    labels:
      - "CI-TEST=ci-label"
    networks:
      - ci-network
    ports:
      - "3306:3306"

  license:
    build:
      context: ..
      dockerfile: docker/Dockerfile
    image: test_license:ci-label
    container_name: test-license-ci-label
    environment:
      - NODE_ENV=dockertest
      - PORT=9502
    labels:
      - "CI-TEST=ci-label"
    networks:
      - ci-network
    ports:
      - "9502:9502"
    depends_on:
      - mysql
    privileged: true

networks:
  ci-network:
    labels:
      - "CI-TEST=ci-label"
    name: ci-network

这是我的dockerfile mysql

FROM mysql:5.7
LABEL CI-TEST="ci-label"
ENV MYSQL_ALLOW_EMPTY_PASSWORD=yes
    MYSQL_USER=mysql \
    MYSQL_PASSWORD=test
COPY init.sql docker-entrypoint-initdb.d/01.sql

这里是init.sql

-- Create database.
CREATE SCHEMA IF NOT EXISTS `license` DEFAULT CHARACTER SET utf8 COLLATE utf8_general_ci;
-- Create new user.
GRANT ALL PRIVILEGES ON license.* TO 'mysql'@'%' IDENTIFIED BY 'test';
GRANT ALL PRIVILEGES ON license.* TO 'mysql'@'localhost' IDENTIFIED BY 'test';
FLUSH PRIVILEGES;

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题