文章详情

短信预约-IT技能 免费直播动态提醒

请输入下面的图形验证码

提交验证

短信预约提醒成功

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

2023-01-28 06:01

关注

一、安装环境 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无法启动内容请搜索编程网以前的文章或继续浏览下面的相关文章希望大家以后多多支持编程网!

阅读原文内容投诉

免责声明:

① 本站未注明“稿件来源”的信息均来自网络整理。其文字、图片和音视频稿件的所属权归原作者所有。本站收集整理出于非商业性的教育和科研之目的,并不意味着本站赞同其观点或证实其内容的真实性。仅作为临时的测试数据,供内部测试之用。本站并未授权任何人以任何方式主动获取本站任何信息。

② 本站未注明“稿件来源”的临时测试数据将在测试完成后最终做删除处理。有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341

软考中级精品资料免费领

  • 历年真题答案解析
  • 备考技巧名师总结
  • 高频考点精准押题
  • 2024年上半年信息系统项目管理师第二批次真题及答案解析(完整版)

    难度     813人已做
    查看
  • 【考后总结】2024年5月26日信息系统项目管理师第2批次考情分析

    难度     354人已做
    查看
  • 【考后总结】2024年5月25日信息系统项目管理师第1批次考情分析

    难度     318人已做
    查看
  • 2024年上半年软考高项第一、二批次真题考点汇总(完整版)

    难度     435人已做
    查看
  • 2024年上半年系统架构设计师考试综合知识真题

    难度     224人已做
    查看

相关文章

发现更多好内容

猜你喜欢

AI推送时光机
位置:首页-资讯-数据库
咦!没有更多了?去看看其它编程学习网 内容吧
首页课程
资料下载
问答资讯