当前位置:首页 > IT技术 > 数据库 > 正文

Docker - 运行 Mysql 容器后报错:[ERROR] --initialize specified but the data directory has files in it. Aborting.
2021-10-18 17:47:09


背景

在本机 mac docker 运行启动 mysql 容器



docker run -d -p 3306:3306 --name mysql1 -v /Users/polo/data/conf:/etc/mysql/conf.d -v /Users/polo/data/mysql:/var/lib/mysql  -e MYSQL_ROOT_PASSWORD=123456 -d mysql:5.7


  

现象

查看容器日志发现报错了,本地 navicat 也连不上

Docker - 运行 Mysql 容器后报错:[ERROR] --initialize specified but the data directory has files in it. Aborting._解决方案

  

根因

通过 -v 挂载的目录已经存在文件了,所以 -v 选本地目录的时候记得选一个空目录/不存在的目录(会自动创建)

 

解决方案

解决问题的参考链接 

将 -v 挂载的本地目录换成一个空目录/不存在的目录即可

 

正常启动 Mysql 容器的日志

Docker - 运行 Mysql 容器后报错:[ERROR] --initialize specified but the data directory has files in it. Aborting._解决方案_02

没有 ERROR 日志

 


本文摘自 :https://blog.51cto.com/u