The solution to the failure to start when docker deploys MySQL

1. Installation environment ubuntu18 + docker 

docker run -itd --name mysql-server -v /home/docker/share/mysql-server/log/:/var/log:rw -v /home/docker/share/mysql-server/data/:/var/lib/mysql:rw -v /home/docker/share/mysql-server/conf:/etc/mysql:rw -v /etc/localtime:/etc/localtime:ro --restart=always -e MYSQL_ROOT_PASSWORD=123456 mysql

2. When encountering a problem that cannot be started, check the errors found in the log

docker logs --tail -n mysql-server

1、You need to specify one of the following as an environment variable:
    - MYSQL_ROOT_PASSWORD
    - MYSQL_ALLOW_EMPTY_PASSWORD
    - MYSQL_RANDOM_ROOT_PASSWORD

2022-10-24 04:21:40+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.31-1.el8 started.
2022-10-24 04:21:40+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2022-10-24 04:21:40+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.31-1.el8 started.
2022-10-24 04:21:40+00:00 [ERROR] [Entrypoint]: Database is uninitialized and password option is not specified
    You need to specify one of the following as an environment variable:
    - MYSQL_ROOT_PASSWORD
    - MYSQL_ALLOW_EMPTY_PASSWORD
    - MYSQL_RANDOM_ROOT_PASSWORD
2022-10-24 04:21:41+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.31-1.el8 started.
2022-10-24 04:21:41+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'

Explanation: Since mysql does not specify a root login password, it cannot be started. The default mysql configuration does not allow login with an empty password.

Reason: Wrong environment variable was written when executing the above command, MYSQL_SERVICE_PASSWORD should be changed to MYSQL_ROOT_PASSWORD

2、mysqld: Can't read dir of '/etc/mysql/conf.d/' (OS errno 2 - No such file or directory)

2022-10-24 04:17:09+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.31-1.el8 started.
2022-10-24 04:17:09+00:00 [ERROR] [Entrypoint]: mysqld failed while attempting to check config
	command was: mysqld --verbose --help --log-bin-index=/tmp/tmp.4hy30uDmqE
	mysqld: Can't read dir of '/etc/mysql/conf.d/' (OS errno 2 - No such file or directory)
mysqld: [ERROR] Stopped processing the 'includedir' directive in file /etc/my.cnf at line 36.
mysqld: [ERROR] Fatal error in defaults handling. Program aborted!
2022-10-24 04:17:13+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.31-1.el8 started.
2022-10-24 04:17:13+00:00 [ERROR] [Entrypoint]: mysqld failed while attempting to check config

Explanation: The structure in the /etc/mysql directory may be different due to different mysql versions 

Reason: Since there are two empty directories under the mysql configuration directory /etc/mysql, the above execution command only mounts the current directory, resulting in no permission to mount the two directories inside the host machine, and the mount directory should be specified Go to the specific directory: -v /home/docker/share/mysql-server/conf:/etc/mysql/conf.d:rw

3、mysqld: Can't create/write to file '/var/lib/mysql/is_writable' (OS errno 13 - Permission denied)

mysqld: Can't create/write to file '/var/lib/mysql/is_writable' (OS errno 13 - Permission denied)
2022-10-24T06:43:20.411035Z 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.
2022-10-24T06:43:20.411089Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.31) initializing of server in progress as process 40
2022-10-24T06:43:20.412290Z 0 [ERROR] [MY-010460] [Server] --initialize specified but the data directory exists and is not writable. Aborting.
2022-10-24T06:43:20.412294Z 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.
2022-10-24T06:43:20.412593Z 0 [ERROR] [MY-010119] [Server] Aborting
2022-10-24T06:43:20.412668Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.31)  MySQL Community Server - GPL.
2022-10-24 06:43:23+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.31-1.el8 started.
2022-10-24 06:43:24+00:00 [Note] [Entrypoint]: Initializing database files
mysqld: Can't create/write to file '/var/lib/mysql/is_writable' (OS errno 13 - Permission denied)

Reason: Insufficient permissions at startup, /var/lib/mysql directory does not have write permissions, it may be that --user xxx is specified as a user with insufficient permissions when deploying docker

Guess you like

Origin blog.csdn.net/u010336468/article/details/127490048