Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker mysql ERROR 1396 (HY000): Operation CREATE USER failed for 'root'@'%'

Tags:

docker

mysql

I am trying to set up two containers one running Python, and the other mysql. This is my docker-compose.yml file:

version: '3' services:     python:         restart: always         build: ./budget/dockerfiles/python/         ports:             - "5000:5000"         links:             - db         depends_on:             - db         volumes:             - ./budget/:/app:z         entrypoint:             - python             - -u             - /app/run.py      db:         build: ./budget/dockerfiles/mysql/         environment:             MYSQL_ROOT_PASSWORD: password             MYSQL_DATABASE: database-name             MYSQL_USER: root             MYSQL_PASSWORD: password         volumes:             - ./Dump.sql:/db/Dump.sql:z             - ./Dump_Test.sql:/db/Dump_Test.sql:z             - ./big_fc.sql:/db/big_fc.sql:z         ports:             - "3306:3306" 

However, when I run docker-compose up -d --build, the containers are built, but the mysql container crashes. In the log, it says:

ERROR 1396 (HY000): Operation CREATE USER failed for 'root'@'%'  

I wanted to try what this post suggests, but I cannot even enter the container since it is crashed. Can somebody tell me what I can do?

like image 955
lmiguelvargasf Avatar asked Jul 13 '17 16:07

lmiguelvargasf


People also ask

What is error code 1396 in MySQL?

MySQL error code 1396 is often related to website restore, migration, etc. In such scenarios, this error occurs when we try to create an already existing user in MySQL. Similarly, we often see this error even if we delete the already existing user too.

How do I run a MySQL database in a Docker container?

Here are the steps you can follow to install the Dockerhub MySQL Container: Step 1: Pull the Docker Image for MySQL. Step 2: Deploy and Start the MySQL Container. Step 3: Connect with the Docker MySQL Container.

How do I create a docker image in MySQL?

Running a MySQL Docker image would look like this: Install Docker engine on the physical host. Download a MySQL image from public (Docker Hub) or private repository, or build your own MySQL image. Run the MySQL container based on the image, which is similar to starting the MySQL service.


1 Answers

According to this github issue, the problem is setting MYSQL_USER to root. It will fail to create the second user 'root'@'%' since it will already exist in the users table.

Therefore, this can be solved by only setting MYSQL_ROOT_PASSWORD, MYSQL_DATABASE, and MYSQL_PASSWORD in the docker-compose.yml file.

like image 50
lmiguelvargasf Avatar answered Sep 17 '22 13:09

lmiguelvargasf