docker msyql8 启动时 Exited (1) 的问题

问题产生

第一次使用docker创建mysql的时候,拉取的为最新镜像 8.0.27,我并不知道5.7和8.0的mysql使用是有区别的。
区别在于8.0的版本如果设置了文件挂载,那么需要指定 /var/lib/mysql-files的外部目录,如果没有指定,将会产生如下错误:
docker logs 容器id 查看错误日志
2022-03-23 07:20:02+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.27-1debian10 started.
2022-03-23 07:20:02+00:00 [Note] [Entrypoint]: Switching to dedicated user ‘mysql’
2022-03-23 07:20:02+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.27-1debian10 started.
2022-03-23 07:20:02+00:00 [Note] [Entrypoint]: Initializing database files
2022-03-23T07:20:02.969389Z 0 [System] [MY-013169] [Server] /usr/sbin/mysqld (mysqld 8.0.27) initializing of server in progress as process 43
2022-03-23T07:20:02.976288Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2022-03-23T07:20:03.322083Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2022-03-23T07:20:04.037840Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1 is enabled for channel mysql_main
2022-03-23T07:20:04.037870Z 0 [Warning] [MY-013746] [Server] A deprecated TLS version TLSv1.1 is enabled for channel mysql_main
2022-03-23T07:20:04.147741Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
2022-03-23 07:20:06+00:00 [Note] [Entrypoint]: Database files initialized
2022-03-23 07:20:06+00:00 [Note] [Entrypoint]: Starting temporary server
mysqld: Error on realpath() on ‘/var/lib/mysql-files’ (Error 2 - No such file or directory)
2022-03-23T07:20:06.479553Z 0 [ERROR] [MY-010095] [Server] Failed to access directory for --secure-file-priv. Please make sure that directory exists and is accessible by MySQL Server. Supplied value : /var/lib/mysql-files
2022-03-23 07:20:06+00:00 [ERROR] [Entrypoint]: Unable to start server.

解决办法

指定 /var/lib/mysql-files的外部目录

全部流程

# 停止容器
sudo docker stop 容器id 
# 删除容器
sudo docker rm 容器id 
# 拉取mysql镜像
sudo docker pull mysql:8.0.27
# 重新启动容器
sudo docker run -p 3306:3306 --name mysql  \
-v /mydata/mysql/conf:/etc/mysql  \
-v /mydata/mysql/logs:/var/log/mysql  \
-v /mydata/mysql/data:/var/lib/mysql  \
-v /mydata/mysql/mysql-files:/var/lib/mysql-files \
-e MYSQL_ROOT_PASSWORD=root \
-d mysql

接下来就是进入容器,修改mysql密码和访问权限

docker exec -it mysql /bin/bash # 进入mysql容器终端
mysql -uroot -proot # 如果提示密码错误 尝试不加密码 mysql -uroot
use mysql;
alter USER 'root'@'localhost' IDENTIFIED BY '你的密码';
# 允许远程连接root
update user set host = "%" where user='root';
flush privileges;

然后使用Navicat连接数据库即可

–end–

参阅:https://www.cnblogs.com/s1956/p/9997691.html

https://www.cnblogs.com/quchunhui/p/11115339.html

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 3
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值