目錄
- 一、安裝環境 ubuntu18 + docker
- 二、遇到無法啟動的問題時,查看日志發現的錯誤
- 總結
一、安裝環境 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
二、遇到無法啟動的問題時,查看日志發現的錯誤
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'
解釋: 由于mysql沒有指定root的登錄密碼導致無法啟動,默認mysql配置是不允許空密碼登錄的
原因:上面執行命令的時候寫錯了環境變量, MYSQL_SERVICE_PASSWORD 應該修改成 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
解釋:可能由于不同的mysql版本,/etc/mysql目錄下的結構不一樣
原因: 由于mysql的配置目錄/etc/mysql下有兩個空目錄, 上面的執行命令僅掛載了當前目錄,導致里面的兩個目錄沒有權限掛載到宿主機內, 應該將掛載目錄指定到具體的目錄下: -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)
原因: 啟動時沒有足夠的權限, /var/lib/mysql目錄沒有寫權限, 可能是部署docker時指定了–user xxx某個權限不足的用戶