Docker Community Forums

Share and learn in the Docker community.

Issues connecting to MySQL container

Hi, I’m trying to make local docker DB instance for developer, I’ve build a small script and basically it ends up running
docker run
–detach
–name=$CONTAINER_NAME
–env=“MYSQL_ROOT_PASSWORD=$ROOT_PASSWORD”
–env=“MYSQL_DB_SCHEMA=$DB_SCHEMA”
–publish 6603:3306
–volume=$CONF_D_PATH:/etc/mysql/conf.d
–volume=$HOME/docker/$CONTAINER_NAME/mysql-data:/var/lib/mysql
mysql:5.7.32

On my Ubuntu 18.04 with docker 19.03 it works fine, but we tried the same run to my colleague on her Ubuntu 16.04 and docker 18.x and we are having issue connecting to mysql. So basically I’ve tried to play with permissions, but even can’t connect to DB from container itself.
I run docker exec -it bash and then mysql -u root -p
ERROR 1130 (HY000): Host ‘xxxx’ is not allowed to connect to this MySQL server

I checked port is open using telnet. Tried to add --env=“MYSQL_ROOT_HOST=%” still doesn’t help. I’m running out of ideas, and with remote work I really can’t constantly access her computer to try to fix the issue. I mean if there are any ideas I can try them, but I can’t gain access for hours and play with it on my own time.

Any ideas will be appreciated

It looks like container doesn’t use the socket setting fro my.cnf. I can see that bind-address works fine, but socket file gets picked up from different location though it’s added to my.cnf. Here are my docker logs if that helps

2021-03-18 16:14:22+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.32-1debian10 started.
2021-03-18 16:14:23+00:00 [Note] [Entrypoint]: Switching to dedicated user 'mysql'
2021-03-18 16:14:23+00:00 [Note] [Entrypoint]: Entrypoint script for MySQL Server 5.7.32-1debian10 started.
2021-03-18 16:14:23+00:00 [Note] [Entrypoint]: Initializing database files
2021-03-18T16:14:23.264147Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-03-18T16:14:26.425677Z 0 [Warning] InnoDB: New log files created, LSN=45790
2021-03-18T16:14:27.018413Z 0 [Warning] InnoDB: Creating foreign key constraint system tables.
2021-03-18T16:14:27.254254Z 0 [Warning] 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: 03103ea7-8805-11eb-a5fa-0242ac110002.
2021-03-18T16:14:27.314149Z 0 [Warning] Gtid table is not ready to be used. Table 'mysql.gtid_executed' cannot be opened.
2021-03-18T16:14:28.089336Z 0 [Warning] CA certificate ca.pem is self signed.
2021-03-18T16:14:28.411300Z 1 [Warning] root@localhost is created with an empty password ! Please consider switching off the --initialize-insecure option.
2021-03-18 16:14:51+00:00 [Note] [Entrypoint]: Database files initialized
2021-03-18 16:14:51+00:00 [Note] [Entrypoint]: Starting temporary server
2021-03-18 16:14:51+00:00 [Note] [Entrypoint]: Waiting for server startup
2021-03-18T16:14:51.517414Z 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2021-03-18T16:14:51.518987Z 0 [Note] mysqld (mysqld 5.7.32) starting as process 81 ...
2021-03-18T16:14:51.522786Z 0 [Note] InnoDB: PUNCH HOLE support available
2021-03-18T16:14:51.522811Z 0 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2021-03-18T16:14:51.522817Z 0 [Note] InnoDB: Uses event mutexes
2021-03-18T16:14:51.522824Z 0 [Note] InnoDB: GCC builtin __atomic_thread_fence() is used for memory barrier
2021-03-18T16:14:51.522829Z 0 [Note] InnoDB: Compressed tables use zlib 1.2.11
2021-03-18T16:14:51.522835Z 0 [Note] InnoDB: Using Linux native AIO
2021-03-18T16:14:51.523130Z 0 [Note] InnoDB: Number of pools: 1
2021-03-18T16:14:51.523236Z 0 [Note] InnoDB: Using CPU crc32 instructions
2021-03-18T16:14:51.524802Z 0 [Note] InnoDB: Initializing buffer pool, total size = 128M, instances = 1, chunk size = 128M
2021-03-18T16:14:51.535056Z 0 [Note] InnoDB: Completed initialization of buffer pool
2021-03-18T16:14:51.537129Z 0 [Note] InnoDB: If the mysqld execution user is authorized, page cleaner thread priority can be changed. See the man page of setpriority().
2021-03-18T16:14:51.549729Z 0 [Note] InnoDB: Highest supported file format is Barracuda.
2021-03-18T16:14:51.629108Z 0 [Note] InnoDB: Creating shared tablespace for temporary tables
2021-03-18T16:14:51.629290Z 0 [Note] InnoDB: Setting file './ibtmp1' size to 12 MB. Physically writing the file full; Please wait ...
2021-03-18T16:14:52.083841Z 0 [Note] InnoDB: File './ibtmp1' size is now 12 MB.
2021-03-18T16:14:52.102357Z 0 [Note] InnoDB: 96 redo rollback segment(s) found. 96 redo rollback segment(s) are active.
2021-03-18T16:14:52.102386Z 0 [Note] InnoDB: 32 non-redo rollback segment(s) are active.
2021-03-18T16:14:52.114587Z 0 [Note] InnoDB: Waiting for purge to start
2021-03-18T16:14:52.164856Z 0 [Note] InnoDB: 5.7.32 started; log sequence number 2747535
2021-03-18T16:14:52.175898Z 0 [Note] InnoDB: Loading buffer pool(s) from /var/lib/mysql/ib_buffer_pool
2021-03-18T16:14:52.178252Z 0 [Note] InnoDB: Buffer pool(s) load completed at 210318 16:14:52
2021-03-18T16:14:52.192120Z 0 [Note] Plugin 'FEDERATED' is disabled.
2021-03-18T16:14:52.218316Z 0 [Note] Found ca.pem, server-cert.pem and server-key.pem in data directory. Trying to enable SSL support using them.
2021-03-18T16:14:52.218347Z 0 [Note] Skipping generation of SSL certificates as certificate files are present in data directory.
2021-03-18T16:14:52.219841Z 0 [Warning] CA certificate ca.pem is self signed.
2021-03-18T16:14:52.219918Z 0 [Note] Skipping generation of RSA key pair as key files are present in data directory.
2021-03-18T16:14:52.263314Z 0 [Warning] Insecure configuration for --pid-file: Location '/var/run/mysqld' in the path is accessible to all OS users. Consider choosing a different directory.
2021-03-18T16:14:52.280504Z 0 [Note] Event Scheduler: Loaded 0 events
2021-03-18T16:14:52.280764Z 0 [Note] mysqld: ready for connections.
Version: '5.7.32'  socket: '/var/run/mysqld/mysqld.sock'  port: 0  MySQL Community Server (GPL)
2021-03-18T16:14:52.631178Z 2 [Note] Access denied for user 'root'@'localhost' (using password: YES)
2021-03-18T16:14:53.690839Z 3 [Note] Access denied for user 'root'@'localhost' (using password: YES)
2021-03-18T16:14:54.706471Z 4 [Note] Access denied for user 'root'@'localhost' (using password: YES)
2021-03-18T16:14:55.720031Z 5 [Note] Access denied for user 'root'@'localhost' (using password: YES)
2021-03-18T16:14:56.731014Z 6 [Note] Access denied for user 'root'@'localhost' (using password: YES)
2021-03-18T16:14:57.743711Z 7 [Note] Access denied for user 'root'@'localhost' (using password: YES)
2021-03-18T16:14:58.755482Z 8 [Note] Access denied for user 'root'@'localhost' (using password: YES)
2021-03-18T16:14:59.767971Z 9 [Note] Access denied for user 'root'@'localhost' (using password: YES)
2021-03-18T16:15:00.779261Z 10 [Note] Access denied for user 'root'@'localhost' (using password: YES)
2021-03-18T16:15:01.792012Z 11 [Note] Access denied for user 'root'@'localhost' (using password: YES)
2021-03-18T16:15:02.801793Z 12 [Note] Access denied for user 'root'@'localhost' (using password: YES)
2021-03-18T16:15:03.906096Z 13 [Note] Access denied for user 'root'@'localhost' (using password: YES)
2021-03-18T16:15:04.925055Z 14 [Note] Access denied for user 'root'@'localhost' (using password: YES)
2021-03-18T16:15:05.932830Z 15 [Note] Access denied for user 'root'@'localhost' (using password: YES)
2021-03-18T16:15:06.941662Z 16 [Note] Access denied for user 'root'@'localhost' (using password: YES)
2021-03-18T16:15:07.952481Z 17 [Note] Access denied for user 'root'@'localhost' (using password: YES)
2021-03-18T16:15:08.961665Z 18 [Note] Access denied for user 'root'@'localhost' (using password: YES)
2021-03-18T16:15:09.971413Z 19 [Note] Access denied for user 'root'@'localhost' (using password: YES)
2021-03-18T16:15:10.979228Z 20 [Note] Access denied for user 'root'@'localhost' (using password: YES)
2021-03-18T16:15:11.986993Z 21 [Note] Access denied for user 'root'@'localhost' (using password: YES)
2021-03-18T16:15:12.996308Z 22 [Note] Access denied for user 'root'@'localhost' (using password: YES)
2021-03-18T16:15:14.003705Z 23 [Note] Access denied for user 'root'@'localhost' (using password: YES)
2021-03-18T16:15:15.013193Z 24 [Note] Access denied for user 'root'@'localhost' (using password: YES)
2021-03-18T16:15:16.022428Z 25 [Note] Access denied for user 'root'@'localhost' (using password: YES)
2021-03-18T16:15:17.033096Z 26 [Note] Access denied for user 'root'@'localhost' (using password: YES)
2021-03-18T16:15:18.044153Z 27 [Note] Access denied for user 'root'@'localhost' (using password: YES)
2021-03-18T16:15:19.056646Z 28 [Note] Access denied for user 'root'@'localhost' (using password: YES)
2021-03-18T16:15:20.070921Z 29 [Note] Access denied for user 'root'@'localhost' (using password: YES)
2021-03-18T16:15:21.084078Z 30 [Note] Access denied for user 'root'@'localhost' (using password: YES)
2021-03-18T16:15:22.095390Z 31 [Note] Access denied for user 'root'@'localhost' (using password: YES)
2021-03-18 16:15:23+00:00 [ERROR] [Entrypoint]: Unable to start server.

I had the same issue with a recent project and as far as i know you may wanna check the library you’re using for mysql in your application. In my case i was working with Node 12.x and mysql library from NPM when i had this issue, i changed the library from mysql to mysql2 from NPM and it worked fine.