docker部署MySQL时无法启动问题的解决方法
一、安装环境 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某个权限不足的用户
总结
到此这篇关于docker部署MySQL时无法启动问题解决的文章就介绍到这了,更多相关docker部署MySQL无法启动内容请搜索脚本之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持脚本之家!
相关文章
docker没有错误日志,镜像服务却启动不成功的问题以及排查方式
这篇文章主要介绍了docker没有错误日志,镜像服务却启动不成功的问题以及排查方式,具有很好的参考价值,希望对大家有所帮助,如有错误或未考虑完全的地方,望不吝赐教2024-05-05打包docker镜像推送到远程服务器并部署到k8s的方法步骤
本文主要介绍了打包docker镜像推送到远程服务器并部署到k8s的方法步骤,文中通过示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下2021-11-11Docker的安装方法及运行Docker Swarm模式的使用
本文给大家简单介绍docker的安装以及1.12版本的swarm模式的使用,包括docker的安装和配置,对docker swarm简单使用感兴趣的朋友一起看看吧2016-11-11Docker启动PostgreSQL时创建多个数据库的解决方案
这篇文章主要介绍了Docker启动PostgreSQL时创建多个数据库的解决方案,重点给大家介绍如何把shell/sql脚本放入/docker-entrypoint-initdb.d/目录中,让容器启动的时候自动执行创建2021-06-06低版本Docker升级高版本Docker的详细教程及成功避坑
如果我们使用docker来管理容器,那么保持docker引擎的更新将会是十分重要的,下面这篇文章主要给大家介绍了关于低版本Docker升级高版本Docker的详细教程及成功避坑,文中通过图文介绍的非常详细,需要的朋友可以参考下2023-05-05
最新评论