开发者

docker部署MySQL时无法启动问题的解决方法

目录
  • 一、安装环境 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 MWBcetNAas 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-servephpr/conf:/etc/mysql/conf.d:rw

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

mysqlandroidd开发者_NewSQL: Can't create/write to file '/var/lib/mysql/is_writable' (OS errno 13 - Permission dMWBcetNAenied)
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 unusaandroidble. 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某个权限不足的用户

总结

到此这篇关于docker部署MySQL时无法启动问题解决的文章就介绍到这了,更多相关docker部署MySQL无法启动内容请搜索我们以前的文章或继续浏览下面的相关文章希望大家以后多多支持我们!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新数据库

数据库排行榜