Mysql docker容器不断重启

dldeef67  于 12个月前  发布在  Mysql
关注(0)|答案(6)|浏览(235)

集装箱一直在重启我试过了

  • docker-compose down -v
  • 停靠程序卷rm

集装箱之前工作正常

2021-03-27 13:16:08+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.23-1debian10 started.

2021-03-27 13:16:08+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'

2021-03-27 13:16:08+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.23-1debian10 started.

2021-03-27 13:16:08+00:00 [ERROR] [Entrypoint]: MYSQL_USER="root", MYSQL_USER and MYSQL_PASSWORD are for configuring a regular user and cannot be used for the root user

Remove MYSQL_USER="root" and use one of the following to control the root user password:

- MYSQL_ROOT_PASSWORD

- MYSQL_ALLOW_EMPTY_PASSWORD

- MYSQL_RANDOM_ROOT_PASSWORD

字符串

Docker-compose.yml

mysql:
    image: mysql:8.0
    ports:
      - 3306:3306
    expose:
      - "3306"
    cap_add:
      - SYS_NICE # CAP_SYS_NICE
    volumes:
      - ./cache/mysql:/var/lib/mysql
      - ./conf-mysql.cnf:/etc/mysql/conf.d/mysql.cnf
    environment:
      - MYSQL_ROOT_PASSWORD=root
      - MYSQL_PASSWORD=root
      - MYSQL_USER=root
      - MYSQL_DATABASE=mydb
    restart: unless-stopped

9vw9lbht

9vw9lbht1#

只需删除MYSQL_USER,它就可以正常工作,因为root用户会自动创建。

  • PS.这似乎是一个新的docker版本的问题,因为这以前工作,而不是抛出错误。*
5q4ezhmt

5q4ezhmt2#

用户root是保留的,并且在mysql启动时已经被创建。
MYSQL_USER必须是不同的名称,而不是root

xt0899hw

xt0899hw3#

我遇到了同样的问题,这就是我如何解决它。
转到docker-compose.yml文件并进行以下更改:

  • 从“MYSQL_USER:root”到“MYSQL_ROOT_USER:root”,然后删除前一个。
  • 将“MYSQL_PASSWORD:YourPasseord”更改为“MYSQL_ROOT_PASSWORD:YourPasseord”,然后删除前一个。

示例:这是我的配置...
数据库服务器:

image: mysql:8.0
       container_name: mysql
       restart: always
       environment:
         MYSQL_DATABASE: DB_epraca
         MYSQL_ROOT_USER: root
         MYSQL_ROOT_PASSWORD: Password
         MYSQL_ROOT_HOST: localhost

字符串

cgvd09ve

cgvd09ve4#

最近官方mysql docker的更改导致了这个问题。更多细节可以查看this PR on github
为了快速解决这个问题,您应该删除MYSQL_USER=root,您的docker-compose.yaml文件应该看起来像这样

mysql:
    image: mysql:8.0
    ports:
      - 3306:3306
    expose:
      - "3306"
    cap_add:
      - SYS_NICE # CAP_SYS_NICE
    volumes:
      - ./cache/mysql:/var/lib/mysql
      - ./conf-mysql.cnf:/etc/mysql/conf.d/mysql.cnf
    environment:
      - MYSQL_ROOT_PASSWORD=root
      - MYSQL_DATABASE=mydb
    restart: unless-stopped

字符串

bybem2ql

bybem2ql5#

仅更新.env文件:

DB_USERNAME=sail
DB_PASSWORD=password

字符串

jljoyd4f

jljoyd4f6#

remove MYSQL_USER=root as root user is created by default and when you use MYSQL_USER=root it tries to create a new normal user with name root which cause conflict. do follow the image in this way:

mysql:
    image: mysql:latest
    environment:
      MYSQL_DATABASE: "paradise"
      MYSQL_USER: "paradise"
      MYSQL_PASSWORD: "bajbciu2dbwc"
      MYSQL_ROOT_PASSWORD: "bajbciu2dbwc"
    ports:
      - "6033:3306"
    volumes:
      - mysql_data:/var/lib/mysql  # Map MySQL data directory into the container
    env_file:
      - .env
    restart: on-failure:5
    healthcheck:
      interval: 5s
      timeout: 5s
      retries: 5

字符串
设置MYSQL_ROOT_PASSWORD:"password_of_your_choice"将为root用户设置密码,设置MYSQL_USER: "paradise" , MYSQL_PASSWORD: "bajbciu2dbwc"将为您创建一个新用户。

相关问题