简体   繁体   中英

Docker create container mysql and can not connect this database

This is my Container Which Is I opened

  db:
    container_name: admin_db
    image: mysql:8.0.27
    environment:
      MYSQL_DATABASE: admin
      MYSQL_USER: root
      MYSQL_PASSWORD: 12345
      MYSQL_ROOT_PASSWORD: 12345
    volumes:
      - .dbdata:/var/lib/mysql
    ports:
      - 33066:3306
    networks:
      - app

When I Run This Code

docker exec -it CONTAINER_ID mysql -uroot -p

It gives Such kind of Error, I entered this password 12345

Enter password: 
ERROR 1045 (28000): Access denied for user 'root'@'localhost' (using password: YES)

You should change the name of MYSQL_USER , this is used to specify a secondary user, if you use this config should work:

 db:
    container_name: admin_db
    image: mysql:8.0.27
    environment:
      MYSQL_DATABASE: admin
      MYSQL_USER: admin_db_user
      MYSQL_PASSWORD: 12345
      MYSQL_ROOT_PASSWORD: 12345
    volumes:
      - .dbdata:/var/lib/mysql
    ports:
      - 33066:3306
    networks:
      - app

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM