MySQL container always restarting. I use docker desktop in Windows 10
Logs
2024-05-14 02:31:01+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.30-1.el8 started.
2024-05-14 02:31:02+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2024-05-14 02:31:02+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.30-1.el8 started.
2024-05-14 02:31:02+00:00 [Note] [Entrypoint]: Initializing database files
2024-05-14T02:31:02.917093Z 0 [Warning] [MY-011068] [Server] The syntax '--skip-host-cache' is deprecated and will be removed in a future release. Please use SET GLOBAL host_cache_size=0 instead.
2024-05-14T02:31:02.917272Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.30) initializing of server in progress as process 80
2024-05-14T02:31:02.919694Z 0 [ERROR] [MY-010457] [Server] --initialize specified but the data directory has files in it. Aborting.
2024-05-14T02:31:02.919703Z 0 [ERROR] [MY-013236] [Server] The designated data directory /var/lib/mysql/ is unusable. You can remove all files that the server added to it.
2024-05-14T02:31:02.919794Z 0 [ERROR] [MY-010119] [Server] Aborting
2024-05-14T02:31:02.919991Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.30) MySQL Community Server - GPL.
docker-compose.yml
db:
container_name: db-klv
image: mysql:8.0.30
restart: always
volumes:
- .db-data:/var/lib/mysql
- ./docker/mysql-config/my.cnf:/etc/mysql/my.cnf
- .db-data-priv:/var/lib/mysql-priv
- ./docker/mysql-init-scripts/init-user-db.sql:/docker-entrypoint-initdb.d/init-user-db.sql
environment:
MYSQL_DATABASE: root
MYSQL_ROOT_PASSWORD: Std@12345678
MYSQL_USER: UKlv
MYSQL_PASSWORD: UKlv@2024
networks:
- klv-net
I have tried remove container, remove image, but not work
2
Answers
The error message indicates that the problem lies with the files in
.db-data
on the host. Delete or move that directory.Alternatively, launch the MySQL daemon without the
--initialize
option.The problem seems to be caused by a conflict with the data directory. According to your provided logs, MySQL is trying to initialize a new database in a directory that already contains files, which is not allowed:
Delete the
.db-data' directory in your host, to ensure that the volume mounted to
/var/lib/mysql` is completely empty. Make sure that Docker is not using the volume when you try to delete the files.