【问题标题】:Docker - mysql configured with empty password for the root userDocker - 为 root 用户配置了空密码的 mysql
【发布时间】:2021-05-14 06:20:21
【问题描述】:

我是 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 命令中缺少任何参数?

【问题讨论】:

    标签: spring-boot docker mysql-8.0


    【解决方案1】:

    这只是误导性印刷的一个例子:

    这只是在数据库文件初始化期间打印的警告(mysqld --initialize-insecure)。稍后会在数据库仅侦听 unix 套接字时创建具有密码的 root 用户。

    来自https://github.com/docker-library/mysql/issues/307#issuecomment-313784886

    【讨论】:

      【解决方案2】:

      如果按照 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

      【讨论】:

      • 它下载了一个新图像,但似乎没有运行。我没有看到日志。摘要:sha256:b1cc887ed32cc6c2f217b12703bd05f503f2037892c8bb226047fe5dff85a109 状态:为mysql下载了更新的图像:最新的45283473c3c7b32b4e0ea4b5313b4155ea4dfb32ee78eaedc892a8c8
      • 我需要在现有的 dockerfile 中输入什么条目来启动 mysql?
      • 你有没有尝试过,我发现了这个github.com/docker-library/mysql/issues/307
      • 是的,应用程序说无法连接到数据库。
      • 似乎是一个奇怪的问题。正如你所说,我可以使用给定的root密码登录。即使是非 docker 服务也可以与 dockerized mysql 通信。我发现服务有一些问题。可能需要 docker-compose 吗?
      猜你喜欢
      • 1970-01-01
      • 2016-11-16
      • 1970-01-01
      • 2019-09-21
      • 2015-10-26
      • 2011-05-06
      • 2012-04-21
      • 1970-01-01
      • 2020-09-09
      相关资源
      最近更新 更多