Docker MySQL 错误没有‘mysql’表

Docker MySQL 错误没有‘mysql’表

当我尝试启动容器时失败了

日志

➜  enigma git:(master) ✗ docker-compose up --build
Starting db    ... done
Starting nginx ... done
Starting pma   ... done
Attaching to db, nginx, pma
db       | 2020-06-23 08:47:31+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.20-1debian10 started.
nginx    | 2020-06-23 08:47:31+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.20-1debian10 started.
db       | 2020-06-23 08:47:32+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
nginx    | 2020-06-23 08:47:31+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
db       | 2020-06-23 08:47:32+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.20-1debian10 started.
nginx    | 2020-06-23 08:47:31+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 8.0.20-1debian10 started.
db       | 2020-06-23T08:47:32.259245Z 0 [Warning] [MY-010139] [Server] Changed limits: max_open_files: 1024 (requested 8161)
db       | 2020-06-23T08:47:32.259248Z 0 [Warning] [MY-010142] [Server] Changed limits: table_open_cache: 431 (requested 4000)
db       | 2020-06-23T08:47:32.569449Z 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.
db       | 2020-06-23T08:47:32.569833Z 0 [System] [MY-010116] [Server] /usr/sbin/mysqld (mysqld 8.0.20) starting as process 1
nginx    | 2020-06-23 08:47:31+00:00 [ERROR] [Entrypoint]: Database is uninitialized and password option is not specified
nginx    |      You need to specify one of MYSQL_ROOT_PASSWORD, MYSQL_ALLOW_EMPTY_PASSWORD and MYSQL_RANDOM_ROOT_PASSWORD
db       | 2020-06-23T08:47:32.632151Z 1 [System] [MY-013576] [InnoDB] InnoDB initialization has started.
nginx exited with code 1
db       | 2020-06-23T08:47:38.409327Z 1 [System] [MY-013577] [InnoDB] InnoDB initialization has ended.
db       | mysqld: Table 'mysql.plugin' doesn't exist
db       | 2020-06-23T08:47:40.082972Z 0 [ERROR] [MY-010735] [Server] Could not open the mysql.plugin table. Please perform the MySQL upgrade procedure.
db       | 2020-06-23T08:47:40.253788Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: '/var/run/mysqld/mysqlx.sock' bind-address: '::' port: 33060
db       | 2020-06-23T08:47:41.287941Z 0 [Warning] [MY-010015] [Repl] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
db       | 2020-06-23T08:47:41.613011Z 0 [Warning] [MY-010015] [Repl] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
pma      | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.18.0.4. Set the 'ServerName' directive globally to suppress this message
db       | 2020-06-23T08:47:41.858709Z 0 [Warning] [MY-010068] [Server] CA certificate ca.pem is self signed.
pma      | AH00558: apache2: Could not reliably determine the server's fully qualified domain name, using 172.18.0.4. Set the 'ServerName' directive globally to suppress this message
db       | 2020-06-23T08:47:42.038096Z 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.
db       | 2020-06-23T08:47:42.039682Z 0 [Warning] [MY-010441] [Server] Failed to open optimizer cost constant tables
db       | 2020-06-23T08:47:42.040884Z 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
db       | 2020-06-23T08:47:42.041600Z 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.
db       | 2020-06-23T08:47:42.044021Z 0 [ERROR] [MY-010326] [Server] Fatal error: Can't open and lock privilege tables: Table 'mysql.user' doesn't exist
db       | 2020-06-23T08:47:42.044832Z 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.
db       | 2020-06-23T08:47:42.046224Z 0 [ERROR] [MY-010119] [Server] Aborting
pma      | [Tue Jun 23 08:47:43.240748 2020] [mpm_prefork:notice] [pid 1] AH00163: Apache/2.4.38 (Debian) PHP/7.4.6 configured -- resuming normal operations
pma      | [Tue Jun 23 08:47:43.241791 2020] [core:notice] [pid 1] AH00094: Command line: 'apache2 -D FOREGROUND'
db       | 2020-06-23T08:47:43.438133Z 0 [System] [MY-010910] [Server] /usr/sbin/mysqld: Shutdown complete (mysqld 8.0.20)  MySQL Community Server - GPL.
db exited with code 1 

docker-compose.yml

version: '3'
services:
  db:
    image: mysql:8.0
    volumes:
      - mysqldata:/var/lib/mysql
    command: mysqld --character-set-server=utf8mb4 --collation-server=utf8mb4_general_ci --default-authentication-plugin=mysql_native_password
    container_name: db
    environment:
      MYSQL_USER: root
      MYSQL_ROOT_PASSWORD: root
    ports:
      - 3306:3306
  pma:
    image: phpmyadmin/phpmyadmin
    container_name: pma
    depends_on:
      - db
    environment:
      - PMA_ARBITARY=1
    restart: always
    ports:
      - 8080:80
    volumes:
      - /sessions
  nginx:
    image: nginx
    container_name: nginx
    ports:
      - 80:80
      - 443:443
    # networks: 
    #   static-network:
    #     ipv4_address: 172.20.128.2
volumes:
  mysqldata:
    driver: local
# networks: 
#   static-network:
#     ipam:
#       config: 
#         - subnet: 172.20.0.0/16

答案1

解决方案是清除卷。从dmkvl 的评论

如果你那里没有数据库,我认为你应该删除 mysql 卷。使用

docker volume ls

列出你的卷,然后

docker volume rm volume_name

删除它。但请记住,它将删除所有数据!在这种情况下,如果您有重要数据,则必须在删除卷之前转储数据库。
另请参阅“运行时问题”部分这里

答案2

我看到了这些类型的错误。您没有说明运行 docker 的主机操作系统。我发现/var/lib/mysql对于 linux 来说,它需要 ext4 和 MacOS APFS。由于限制,exfat 不起作用。我从 mysql 切换到 mariadb,因为它占用空间较小。此外,还链接了用于初始化我的数据库的脚本。

db:
   container_name: db
   image: mariadb
   command: --default-authentication-plugin=mysql_native_password
   networks:
     - htpc-network
   environment:
     MYSQL_ROOT_PASSWORD: xxx
   restart: unless-stopped
   volumes: 
     - ${PLEX}/sniff:/var/lib/mysql
     - ./db:/docker-entrypoint-initdb.d
   ports: 
     - "3306:3306"

db/01_create_database.sql

create database sniffer;
create user 'pi' identified by 'xxx';
create user sniffer identified by 'xxx';
grant all on sniffer.* to 'pi';
grant all on sniffer.* to 'sniffer';

相关内容