MySQL 8.0 Docker could not create connection to database server

That’s good to hear @dkayiwa ! Which version and flavor of Java you use? I cannot think what else could be different in my environment. Here are my details:

 mvn -version
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option PermSize=256m; support was removed in 8.0
Java HotSpot(TM) 64-Bit Server VM warning: ignoring option MaxPermSize=512m; support was removed in 8.0
Apache Maven 3.9.9 (8e8579a9e76f7d015ee5ec7bfcdc97d260186937)
Maven home: /opt/homebrew/Cellar/maven/3.9.9/libexec
Java version: 1.8.0_431, vendor: Oracle Corporation, runtime: /Library/Java/JavaVirtualMachines/jdk-1.8.jdk/Contents/Home/jre
Default locale: en_US, platform encoding: UTF-8
OS name: "mac os x", version: "15.1.1", arch: "aarch64", family: "mac"
docker version
Client:
 Version:           27.4.0
 API version:       1.47
 Go version:        go1.22.10
 Git commit:        bde2b89
 Built:             Sat Dec  7 10:35:43 2024
 OS/Arch:           darwin/arm64
 Context:           desktop-linux

Server: Docker Desktop 4.37.1 (178610)
 Engine:
  Version:          27.4.0
  API version:      1.47 (minimum version 1.24)
  Go version:       go1.22.10
  Git commit:       92a8393
  Built:            Sat Dec  7 10:38:33 2024
  OS/Arch:          linux/arm64
  Experimental:     false
 containerd:
  Version:          1.7.21
  GitCommit:        472731909fa34bd7bc9c087e4c27943f9835f111
 runc:
  Version:          1.1.13
  GitCommit:        v1.1.13-0-g58aa920
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0
mysql> status
--------------
mysql  Ver 8.0.40 for macos14 on arm64 (MySQL Community Server - GPL)

Connection id:		9
Current database:	haiti
Current user:		root@172.17.0.1
SSL:			Cipher in use is TLS_AES_256_GCM_SHA384
Current pager:		stdout
Using outfile:		''
Using delimiter:	;
Server version:		8.4.1 MySQL Community Server - GPL
Protocol version:	10
Connection:		127.0.0.1 via TCP/IP
Server characterset:	utf8mb4
Db     characterset:	utf8mb3
Client characterset:	utf8mb4
Conn.  characterset:	utf8mb4
TCP port:		3308
Binary data as:		Hexadecimal
Uptime:			21 hours 40 min 44 sec

mvn -v

Apache Maven 3.8.6 (84538c9988a25aec085021c365c560670ad80f63)
Maven home: /Users/danielkayiwa/Libraries/apache-maven-3.8.6
Java version: 1.8.0_352, vendor: Temurin, runtime: /Library/Java/JavaVirtualMachines/temurin-8.jdk/Contents/Home/jre
Default locale: en_UG, platform encoding: UTF-8
OS name: "mac os x", version: "10.16", arch: "x86_64", family: "mac"

docker version

Client:
 Cloud integration: v1.0.29
 Version:           20.10.21
 API version:       1.41
 Go version:        go1.18.7
 Git commit:        baeda1f
 Built:             Tue Oct 25 18:01:18 2022
 OS/Arch:           darwin/arm64
 Context:           default
 Experimental:      true

Server: Docker Desktop 4.15.0 (93002)
 Engine:
  Version:          20.10.21
  API version:      1.41 (minimum version 1.12)
  Go version:       go1.18.7
  Git commit:       3056208
  Built:            Tue Oct 25 17:59:41 2022
  OS/Arch:          linux/arm64
  Experimental:     false
 containerd:
  Version:          1.6.10
  GitCommit:        770bd0108c32f3fb5c73ae1264f7e503fe7b2661
 runc:
  Version:          1.1.4
  GitCommit:        v1.1.4-0-g5fd4c4d
 docker-init:
  Version:          0.19.0
  GitCommit:        de40ad0

mysql status

mysql  Ver 8.4.4 for Linux on aarch64 (MySQL Community Server - GPL)

Connection id:		232
Current database:	
Current user:		root@localhost
SSL:			Not in use
Current pager:		stdout
Using outfile:		''
Using delimiter:	;
Server version:		8.4.4 MySQL Community Server - GPL
Protocol version:	10
Connection:		Localhost via UNIX socket
Server characterset:	utf8mb3
Db     characterset:	utf8mb3
Client characterset:	latin1
Conn.  characterset:	latin1
UNIX socket:		/var/run/mysqld/mysqld.sock
Binary data as:		Hexadecimal
Uptime:			14 hours 32 min 56 sec

Threads: 2  Questions: 374030  Slow queries: 0  Opens: 3815  Flush tables: 3  Open tables: 1388  Queries per second avg: 7.141

Thanks @dkayiwa ! How did you get that docker container with MySQL 8.4.4? And how did you change the client and connection characterset?

I just copied and pasted this from the PIH documentation. But changed the image from 5.6 to 8. Then i run the sdk setup as instructed there, together with installing the config and finally sdk run.

docker run --name mysql-mirebalais -d -p 3308:3306 \
          -e MYSQL_ROOT_PASSWORD=root \
          mysql:8 \
          --character-set-server=utf8 \
          --collation-server=utf8_general_ci \
          --max_allowed_packet=1G \
          --innodb-buffer-pool-size=2G \
          --user=mysql \
          --server-id=1 \
          --log-bin=mysql-bin \
          --binlog_format=ROW \
          --max_binlog_size=100M
1 Like

@dkayiwa , it is interesting that when I run the same docker command:

docker run --name mysql-mirebalais -d -p 3308:3306 \
          -e MYSQL_ROOT_PASSWORD=root \
          mysql:8 \
          --character-set-server=utf8 \
          --collation-server=utf8_general_ci \
          --max_allowed_packet=1G \
          --innodb-buffer-pool-size=2G \
          --user=mysql \
          --server-id=1 \
          --log-bin=mysql-bin \
          --binlog_format=ROW \
          --max_binlog_size=100M
Unable to find image 'mysql:8' locally
8: Pulling from library/mysql
102fd35c7a1a: Download complete 
903087d703a7: Download complete 
12c3c76ec2bc: Download complete 
9dcae24b624f: Download complete 
6ad65461c369: Download complete 
355b97fa6b39: Download complete 
5dd6251984b1: Download complete 
e176816781e5: Download complete 
ed8658491a3a: Download complete 
d1014e296527: Download complete 
Digest: sha256:0917ecc5863323a48203dda0bb7d58582d958da62914024c474bf2e8c5f5ee73
Status: Downloaded newer image for mysql:8
95913b0ca7fd9b7be51190b776ba847ec23afa3ac57ae5ebb9ba35d0ce197eef

I end up with slightly different MySql server configuration than yours:

mysql> status
--------------
mysql  Ver 8.0.40 for macos14 on arm64 (MySQL Community Server - GPL)

Connection id:		8
Current database:	
Current user:		root@172.17.0.1
SSL:			Cipher in use is TLS_AES_256_GCM_SHA384
Current pager:		stdout
Using outfile:		''
Using delimiter:	;
Server version:		8.4.4 MySQL Community Server - GPL
Protocol version:	10
Connection:		127.0.0.1 via TCP/IP
Server characterset:	utf8mb3
Db     characterset:	utf8mb3
Client characterset:	utf8mb4
Conn.  characterset:	utf8mb4
TCP port:		3308
Binary data as:		Hexadecimal
Uptime:			8 sec

I have to figure out how to change the client and connection characterset.

I have just run it again with image mysql:8.0.40 and it runs very well.

mysql status

mysql  Ver 8.0.40 for Linux on aarch64 (MySQL Community Server - GPL)

Connection id:		285
Current database:	
Current user:		root@localhost
SSL:			Not in use
Current pager:		stdout
Using outfile:		''
Using delimiter:	;
Server version:		8.0.40 MySQL Community Server - GPL
Protocol version:	10
Connection:		Localhost via UNIX socket
Server characterset:	utf8mb3
Db     characterset:	utf8mb3
Client characterset:	latin1
Conn.  characterset:	latin1
UNIX socket:		/var/run/mysqld/mysqld.sock
Binary data as:		Hexadecimal
Uptime:			1 hour 8 min 7 sec

Threads: 2  Questions: 2857842  Slow queries: 0  Opens: 7140  Flush tables: 3  Open tables: 1917  Queries per second avg: 699.251

1 Like

You can use mysql 5.6. It is avaible in zldev/mysql:5.6 This is the command to create your container : “docker run --name mysql-server -p 3308:3306 -e MYSQL_ROOT_PASSWORD=Admin123 -d zldev/mysql:5.6”. I use a M4.

I was able to get it working using MySql 8.4.4 docker image. The only thing that I did differently this time was that I first logged into the docker image and then created the database from within the container(per existing instructions), as opposed as before when I was using the host mysql client to create the database. Not sure why this would make a difference.

docker exec -it mysql-mirebalais bash
mysql -u root -p
create database openmrs default charset utf8;

Thank you @dkayiwa and @ibacher for your persistent assistance with this issue.

Very interesting that i did not have to manually create the database to make it work. Anyway :wink:

Hmmmm… It’s entirely possible that there’s also a leaked connection in the initial setup code? I’m working on some patches for the DatabaseUpdater to:

  • Try to ensure we’re always closing the underlying connection, mostly by using try-with-resources blocks. I don’t think this technique works for 2.5 or lower due to the Liquibase object not being autocloseable, but it should work for 2.6 and higher
  • Try to default to reusing connections from the Hibernate connection pool once that’s available and only manually creating connections at initial startup.