似乎无法让 MySQL 在 Docker 容器中启动

问题描述 投票:0回答:3

我试图让 MySQL 在 Windows 10 WSL 2 下的 Docker 容器中运行。我尝试使用以下命令启动容器:

docker run -d --name mysql -v /mnt/g/DockerVolumes/mysql:/var/lib/mysql -e MYSQL_ROOT_PASSWORD=***** -e bind-address:0.0.0 -p 3306:3306 -p 33060:33060 mysql

/mnt/g/DockerVolumes/mysql 映射到 NTFS 驱动器上的文件夹,且不包含在虚拟驱动器中。

由于锁权限表不存在,启动中止。

以下是完整的启动日志。

我哪里做错了?

注意:我想将 MySQL 数据文件保留在虚拟硬盘驱动器之外,以便于管理并且不填满系统驱动器。

谢谢

-马克

2020-05-31 22:43:04+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.20-1debian10 started.
2020-05-31 22:43:04+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2020-05-31 22:43:04+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.20-1debian10 started.
2020-05-31T22:43:04.902473Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2020-05-31T22:43:04.902824Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.20) starting as process 1
2020-05-31T22:43:04.907865Z 0 [Warning] [MY-010159] [Server] Setting lower_case_table_names=2 because file system for /var/lib/mysql/ is case insensitive
2020-05-31T22:43:04.945736Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2020-05-31T22:43:06.174472Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
mysqld: Table 'mysql.plugin' doesn't exist
2020-05-31T22:43:06.288074Z 0 [ERROR] [MY-010735] [Server] Could not open the mysql.plugin table. Please perform the MySQL upgrade procedure.
2020-05-31T22:43:06.346697Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock' bind-address: '::' port: 33060
2020-05-31T22:43:06.438801Z 0 [Warning] [MY-010015] [Repl] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-05-31T22:43:06.490799Z 0 [Warning] [MY-000054] [Server] World-writable config file './auto.cnf' is ignored.
2020-05-31T22:43:06.491760Z 0 [Warning] [MY-010107] [Server] World-writable config file './auto.cnf' has been removed.
2020-05-31T22:43:06.492104Z 0 [Warning] [MY-010075] [Server] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 18344f03-a390-11ea-9829-0242ac110002.
2020-05-31T22:43:06.643342Z 0 [Warning] [MY-010015] [Repl] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-05-31T22:43:06.677570Z 0 [Warning] [MY-010069] [Server] Failed to set up SSL because of the following SSL library error: SSL context is not usable without certificate and private key
mysqld: Cannot change permissions of the file 'private_key.pem' (OS errno 1 - Operation not permitted)
2020-05-31T22:43:06.781193Z 0 [ERROR] [MY-010295] [Server] Could not set file permission for private_key.pem
2020-05-31T22:43:06.781489Z 0 [ERROR] [MY-010119] [Server] Aborting
2020-05-31T22:43:08.628123Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.20)  MySQL Community Server - GPL.
2020-05-31 22:57:41+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.20-1debian10 started.
2020-05-31 22:57:41+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2020-05-31 22:57:41+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.20-1debian10 started.
2020-05-31T22:57:42.103154Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2020-05-31T22:57:42.103457Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.20) starting as process 1
2020-05-31T22:57:42.107950Z 0 [Warning] [MY-010159] [Server] Setting lower_case_table_names=2 because file system for /var/lib/mysql/ is case insensitive
2020-05-31T22:57:42.142430Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2020-05-31T22:57:43.422720Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
mysqld: Table 'mysql.plugin' doesn't exist
2020-05-31T22:57:43.537107Z 0 [ERROR] [MY-010735] [Server] Could not open the mysql.plugin table. Please perform the MySQL upgrade procedure.
2020-05-31T22:57:43.579174Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock' bind-address: '::' port: 33060
2020-05-31T22:57:43.645481Z 0 [Warning] [MY-010015] [Repl] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-05-31T22:57:43.698518Z 0 [Warning] [MY-000054] [Server] World-writable config file './auto.cnf' is ignored.
2020-05-31T22:57:43.700522Z 0 [Warning] [MY-010107] [Server] World-writable config file './auto.cnf' has been removed.
2020-05-31T22:57:43.701295Z 0 [Warning] [MY-010075] [Server] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 230fcd30-a392-11ea-9633-0242ac110002.
2020-05-31T22:57:43.863312Z 0 [Warning] [MY-010015] [Repl] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-05-31T22:57:43.911332Z 0 [Warning] [MY-010069] [Server] Failed to set up SSL because of the following SSL library error: SSL context is not usable without certificate and private key
2020-05-31T22:57:43.916234Z 0 [Warning] [MY-010284] [Server] RSA public key file not found: /var/lib/mysql//public_key.pem. Some authentication plugins will not work.
2020-05-31T22:57:43.918367Z 0 [Warning] [MY-010284] [Server] RSA public key file not found: /var/lib/mysql//public_key.pem. Some authentication plugins will not work.
2020-05-31T22:57:43.959367Z 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.
2020-05-31T22:57:43.959849Z 0 [Warning] [MY-010441] [Server] Failed to open optimizer cost constant tables
2020-05-31T22:57:43.960109Z 0 [ERROR] [MY-013129] [Server] A message intended for a client cannot be sent there as no client-session is attached. Therefore, we're sending the information to the error-log instead: MY-001146 - Table 'mysql.component' doesn't exist
2020-05-31T22:57:43.960251Z 0 [Warning] [MY-013129] [Server] A message intended for a client cannot be sent there as no client-session is attached. Therefore, we're sending the information to the error-log instead: MY-003543 - The mysql.component table is missing or has an incorrect definition.
2020-05-31T22:57:43.960694Z 0 [ERROR] [MY-010326] [Server] Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist
2020-05-31T22:57:43.960866Z 0 [ERROR] [MY-010952] [Server] The privilege system failed to initialize correctly. For complete instructions on how to upgrade MySQL to a new version please see the 'Upgrading MySQL' section from the MySQL manual.
2020-05-31T22:57:43.961186Z 0 [ERROR] [MY-010119] [Server] Aborting
2020-05-31T22:57:45.340240Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.20)  MySQL Community Server - GPL.
2020-05-31 22:58:54+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.20-1debian10 started.
2020-05-31 22:58:54+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2020-05-31 22:58:54+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.20-1debian10 started.
2020-05-31T22:58:54.696468Z 0 [Warning] [MY-011070] [Server] 'Disabling symbolic links using --skip-symbolic-links (or equivalent) is the default. Consider not using this option as it' is deprecated and will be removed in a future release.
2020-05-31T22:58:54.696779Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.20) starting as process 1
2020-05-31T22:58:54.702278Z 0 [Warning] [MY-010159] [Server] Setting lower_case_table_names=2 because file system for /var/lib/mysql/ is case insensitive
2020-05-31T22:58:54.730454Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
2020-05-31T22:58:56.003162Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
mysqld: Table 'mysql.plugin' doesn't exist
2020-05-31T22:58:56.209309Z 0 [ERROR] [MY-010735] [Server] Could not open the mysql.plugin table. Please perform the MySQL upgrade procedure.
2020-05-31T22:58:56.270890Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock' bind-address: '::' port: 33060
2020-05-31T22:58:56.330541Z 0 [Warning] [MY-010015] [Repl] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-05-31T22:58:56.383656Z 0 [Warning] [MY-000054] [Server] World-writable config file './auto.cnf' is ignored.
2020-05-31T22:58:56.384744Z 0 [Warning] [MY-010107] [Server] World-writable config file './auto.cnf' has been removed.
2020-05-31T22:58:56.385289Z 0 [Warning] [MY-010075] [Server] No existing UUID has been found, so we assume that this is the first time that this server has been started. Generating a new UUID: 4e62808d-a392-11ea-9118-0242ac110002.
2020-05-31T22:58:56.543387Z 0 [Warning] [MY-010015] [Repl] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2020-05-31T22:58:56.581873Z 0 [Warning] [MY-010069] [Server] Failed to set up SSL because of the following SSL library error: SSL context is not usable without certificate and private key
2020-05-31T22:58:56.586523Z 0 [Warning] [MY-010284] [Server] RSA public key file not found: /var/lib/mysql//public_key.pem. Some authentication plugins will not work.
2020-05-31T22:58:56.588981Z 0 [Warning] [MY-010284] [Server] RSA public key file not found: /var/lib/mysql//public_key.pem. Some authentication plugins will not work.
2020-05-31T22:58:56.641897Z 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.
2020-05-31T22:58:56.642366Z 0 [Warning] [MY-010441] [Server] Failed to open optimizer cost constant tables
2020-05-31T22:58:56.642657Z 0 [ERROR] [MY-013129] [Server] A message intended for a client cannot be sent there as no client-session is attached. Therefore, we're sending the information to the error-log instead: MY-001146 - Table 'mysql.component' doesn't exist
2020-05-31T22:58:56.642800Z 0 [Warning] [MY-013129] [Server] A message intended for a client cannot be sent there as no client-session is attached. Therefore, we're sending the information to the error-log instead: MY-003543 - The mysql.component table is missing or has an incorrect definition.
2020-05-31T22:58:56.643205Z 0 [ERROR] [MY-010326] [Server] Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist
2020-05-31T22:58:56.643377Z 0 [ERROR] [MY-010952] [Server] The privilege system failed to initialize correctly. For complete instructions on how to upgrade MySQL to a new version please see the 'Upgrading MySQL' section from the MySQL manual.
2020-05-31T22:58:56.643668Z 0 [ERROR] [MY-010119] [Server] Aborting
2020-05-31T22:58:57.917989Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.20)  MySQL Community Server - GPL.
mysql docker windows-subsystem-for-linux
3个回答
3
投票

我通过不将存储映射到 Windows 卷解决了这个问题。


1
投票

这里有类似的问题 - 在 Windows Home WSL2 上为我的 Laravel 项目使用 Laradock Docker 设置,并且错误

Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist
停止了 MySQL 容器的工作 - 问题出在
DATA_PATH_HOST
设置上:

# docker/docker-compose.yml

### MySQL ################################################
    mysql:
      build:
        context: ./mysql
        args:
          - MYSQL_VERSION=${MYSQL_VERSION}
      environment:
        - MYSQL_DATABASE=${MYSQL_DATABASE}
        - MYSQL_USER=${MYSQL_USER}
        - MYSQL_PASSWORD=${MYSQL_PASSWORD}
        - MYSQL_ROOT_PASSWORD=${MYSQL_ROOT_PASSWORD}
        - TZ=${WORKSPACE_TIMEZONE}
      volumes:
        - ${DATA_PATH_HOST}/mysql:/var/lib/mysql
# docker/.env

# Choose storage path on your machine. For all storage systems
DATA_PATH_HOST=~/.projectname/data

问题是神奇的 linux 主目录字符

~
没有被解释为主目录,而是字面上的 - 在无法访问的位置为 MySQL 创建数据目录并阻止正确的初始化 - 解决方案很简单 - 只需重命名数据即可-dir 到其他东西,例如:

# docker/.env

# Choose storage path on your machine. For all storage systems
DATA_PATH_HOST=/home/picard/.projectname/data

...但是找到它花了我半天:(

希望这能帮助别人节省一些时间:)


0
投票

我正在使用相同的 docker compose 配置开发多个项目 并遇到了同样的问题。 添加 -v 标志很有帮助,它在删除容器时删除了卷,一切都开始正常。

docker compose down -v  
© www.soinside.com 2019 - 2024. All rights reserved.