docker-library / mysql

Docker Official Image packaging for MySQL Community Server
https://dev.mysql.com/
GNU General Public License v2.0
2.46k stars 2.19k forks source link

mysql not binding to port when importing SQL on init until restart of container #995

Closed tech-knowledgy closed 1 year ago

tech-knowledgy commented 1 year ago

I'm volume mount binding an SQL file:

  mysql:
    image: mysql:8.1.0
    restart: always
    env_file: .env
    volumes:
      - mysql:/var/lib/mysql
      - ./wp_prodtesting1.sql:/docker-entrypoint-initdb.d/import.sql

  phpMyAdmin:
    image: phpmyadmin:5.2.1-apache
    env_file: .env
    ports:
      - 8081:80
    depends_on:
      - mysql

On first startup, I see:

wordpress-mysql-1       | 2023-09-13T03:24:54.758848Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Socket: /var/run/mysqld/mysqlx.sock                                                                             
wordpress-mysql-1       | 2023-09-13T03:24:54.758934Z 0 [System] [MY-010931] [Server] /usr/sbin/mysqld: ready for connections. Version: '8.1.0'  socket: '/var/run/mysqld/mysqld.sock'  port: 0  MySQL Community Server - GPL.        
wordpress-mysql-1       | 2023-09-13T03:24:54.760681Z 0 [System] [MY-015016] [Server] MySQL Server - end.                                                                                                                             
wordpress-mysql-1       | 2023-09-13 03:24:54+00:00 [Note] [Entrypoint]: Temporary server started.                                                                                                                                    
wordpress-mysql-1       | '/var/lib/mysql/mysql.sock' -> '/var/run/mysqld/mysqld.sock'                                                                                                                                                
... Skip cruft
wordpress-mysql-1       | 2023-09-13 03:24:56+00:00 [Note] [Entrypoint]: Creating user wordpress
wordpress-mysql-1       | 2023-09-13 03:24:56+00:00 [Note] [Entrypoint]: /usr/local/bin/docker-entrypoint.sh: running /docker-entrypoint-initdb.d/import.sql

I can exec in to the container and connect to the socket fine, list databases and see the import worked as expected.

However, I cannot access it through other containers or on the host until I restart, upon which I see:

wordpress-mysql-1       | 2023-09-13T03:28:03.437184Z 0 [System] [MY-011323] [Server] X Plugin ready for connections. Bind-address: '::' port: 33060, socket: /var/run/mysqld/mysqlx.sock                                             

Here you can see it is indicating it's bound to :: and a port, which was missing before.

No amount of waiting starts this binding and requires to manually restart the container (or the entire compose project).


I do realize there is a section in the README called No connections until MySQL init completes, and it says no connections before init - that makes sense. But like I said, I'm able to connect on the socket from within the container just fine, it's init'd - just not binding to IP/PORT for external access.

tech-knowledgy commented 1 year ago

My apologies, it's working fine...

I tried with a minimal SQL import script, and it actually ended up listening.

Apparently the dump I'm working with is fairly large and it took over 30 minutes to import!!!