ERROR: mysqld failed while attempting to check config [How to Solve]

Problem Description:

the reason for the pit I encountered in learning docker is that the MySQL image used in the video is 5.7, and I use more than 8.0 (8.0.16) </ font>

Error code


Cause analysis:

Start from the third step, analyze step by step, and directly look at the solutions

1. Pull image

I pulled more than 8.0, so I encountered this pit

docker pull mysql:8.0.16

2. View mirror

docker images

3. Run container

docker run -p 3306:3306 --name mysql \
-v /mydata/mysql/log:/var/log/mysql \
-v /mydata/mysql/data:/var/lib/mysql \
-v /mydata/mysql/conf:/etc/mysql \
-e MYSQL_ROOT_PASSWORD=root -d mysql:8.0.16

After running, you can see the container ID, but it is empty when viewed with docker PS

4. View container

docker ps

5. View all containers

docker ps -a

6. View log analysis

docker logs 容器id

7. Cause

The configuration location of MySQL is wrong when running the container. The configuration location of MySQL 5.7 is/etc/MySQL. The configuration location above MySQL 8.0 is/etc/MySQL/conf.d. just modify the configuration location according to the MySQL version


Solution:

1. Delete container

docker rm Container id or NAME

2. Modify the configuration of the run container

The conf configuration is modified as shown in the figure below

/mydata/mysql/conf:/etc/mysql
					||
					||
					||
					\/
/mydata/mysql/conf:/etc/mysql/conf.d

3. Rerun

Summary:

Mysql8.0 and above configuration

docker run -p 3306:3306 --name mysql \
-v /mydata/mysql/log:/var/log/mysql \
-v /mydata/mysql/data:/var/lib/mysql \
-v /mydata/mysql/conf:/etc/mysql/conf.d \
-e MYSQL_ROOT_PASSWORD=root -d mysql:8.0.16

Mysql5.7 configuration

docker run -p 3306:3306 --name mysql \
-v /mydata/mysql/log:/var/log/mysql \
-v /mydata/mysql/data:/var/lib/mysql \
-v /mydata/mysql/conf:/etc/mysql \
-e MYSQL_ROOT_PASSWORD=root -d mysql:5.7

Read More: