无法启动Docker容器内的MySQL

5

我正在尝试在Windows 10 WSL 2下将MySQL运行在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.

1
看起来这个消息是关键:mysqld: Cannot change permissions of the file 'private_key.pem' (OS errno 1 - Operation not permitted)。也许与此相关:https://github.com/docker/for-win/issues/4824? - Don't Panic
@Don'tPanic,谢谢。那肯定是问题所在。 - mhsimkin
2个回答

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

1

我这里也遇到了类似的问题——在 Windows Home WSL2 上使用 Laradock Docker 配置来运行 Laravel 项目时,出现了错误 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的数据目录,并阻止正确的初始化 - 解决方案很简单 - 只需将数据目录重命名为其他名称,例如:
# docker/.env

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

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

希望这可以帮助某人节省一些时间 :)


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接