微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Docker - 为root用户配置空密码的mysql

如何解决Docker - 为root用户配置空密码的mysql

我是 docker 新手,并尝试在 Windows 服务器上使用以下命令运行 MysqL 映像。

docker run  -e MysqL_ROOT_PASSWORD=sEe@21 -e MysqL_DATABASE=emp_db -p 3306:3306 --name MysqL_emp MysqL

它已成功下载和配置。我在 CMD 中得到一个日志,上面写着

root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.

我已经提供了我设置为应用程序使用的 root 密码,因此我收到一条错误消息,提示无法从 Spring Boot 服务连接到 DB。 MysqL完整日志如下

2021-02-10 14:25:43+00:00 [Note] [Entrypoint]: Entrypoint script for MysqL Server 8.0.23-1debian10 started.
2021-02-10 14:25:43+00:00 [Note] [Entrypoint]: Switching to dedicated user 'MysqL'
2021-02-10 14:25:43+00:00 [Note] [Entrypoint]: Entrypoint script for MysqL Server 8.0.23-1debian10 started.
2021-02-10 14:25:43+00:00 [Note] [Entrypoint]: Initializing database files
2021-02-10T14:25:43.801929Z 0 [System] [MY-013169] [Server] /usr/sbin/MysqLd (MysqLd 8.0.23) initializing of server in progress as process 43
2021-02-10T14:25:43.808218Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2021-02-10T14:25:44.547274Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2021-02-10T14:25:46.632843Z 6 [Warning] [MY-010453] [Server] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
2021-02-10 14:25:51+00:00 [Note] [Entrypoint]: Database files initialized
2021-02-10 14:25:51+00:00 [Note] [Entrypoint]: Starting temporary server
2021-02-10T14:25:51.770335Z 0 [System] [MY-010116] [Server] /usr/sbin/MysqLd (MysqLd 8.0.23) starting as process 88
2021-02-10T14:25:51.804446Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2021-02-10T14:25:52.039318Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2021-02-10T14:25:52.169969Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: /var/run/MysqLd/MysqLx.sock
2021-02-10T14:25:52.299951Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2021-02-10T14:25:52.300259Z 0 [System] [MY-013602] [Server] Channel MysqL_main configured to support TLS. Encrypted connections are Now supported for this channel.
2021-02-10T14:25:52.304466Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/MysqLd' in the path is accessible to all OS users. Consider choosing a different directory.
2021-02-10T14:25:52.327240Z 0 [System] [MY-010931] [Server] /usr/sbin/MysqLd: ready for connections. Version: '8.0.23'  socket: '/var/run/MysqLd/MysqLd.sock'  port: 0  MysqL Community Server - GPL.
2021-02-10 14:25:52+00:00 [Note] [Entrypoint]: Temporary server started.
Warning: Unable to load '/usr/share/zoneinfo/iso3166.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/leap-seconds.list' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone.tab' as time zone. Skipping it.
Warning: Unable to load '/usr/share/zoneinfo/zone1970.tab' as time zone. Skipping it.
2021-02-10 14:25:58+00:00 [Note] [Entrypoint]: Creating database emp_db

2021-02-10 14:25:58+00:00 [Note] [Entrypoint]: Stopping temporary server
2021-02-10T14:25:58.448858Z 11 [System] [MY-013172] [Server] Received SHUTDOWN from user root. Shutting down MysqLd (Version: 8.0.23).
2021-02-10T14:26:00.212816Z 0 [System] [MY-010910] [Server] /usr/sbin/MysqLd: Shutdown complete (MysqLd 8.0.23)  MysqL Community Server - GPL.
2021-02-10 14:26:00+00:00 [Note] [Entrypoint]: Temporary server stopped

2021-02-10 14:26:00+00:00 [Note] [Entrypoint]: MysqL init process done. Ready for start up.

2021-02-10T14:26:00.738118Z 0 [System] [MY-010116] [Server] /usr/sbin/MysqLd (MysqLd 8.0.23) starting as process 1
2021-02-10T14:26:00.763121Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2021-02-10T14:26:00.999006Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
2021-02-10T14:26:01.135971Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060,socket: /var/run/MysqLd/MysqLx.sock
2021-02-10T14:26:01.269210Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
2021-02-10T14:26:01.269444Z 0 [System] [MY-013602] [Server] Channel MysqL_main configured to support TLS. Encrypted connections are Now supported for this channel.
2021-02-10T14:26:01.275037Z 0 [Warning] [MY-011810] [Server] Insecure configuration for --pid-file: Location '/var/run/MysqLd' in the path is accessible to all OS users. Consider choosing a different directory.
2021-02-10T14:26:01.297388Z 0 [System] [MY-010931] [Server] /usr/sbin/MysqLd: ready for connections. Version: '8.0.23'  socket: '/var/run/MysqLd/MysqLd.sock'  port: 3306  MysqL Community Server - GPL.

想了解我做错了什么吗? docker run 命令中缺少任何参数?

解决方法

如果您按照 MySQL Docker 中心页面上的结构构建运行命令会发生什么:

docker run --name mysql_emp -e MYSQL_ROOT_PASSWORD=sEe@21 -e MYSQL_DATABASE=emp_db -p 3306:3306 -d mysql:latest

如果这不起作用,您可以尝试从 dockerfile 运行,类似于这个问题:MYSQL docker file

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。