@@ -16,102 +16,79 @@ else
1616fi
1717
1818mysql () {
19- mysql_9_2
19+ mysql_9_4
2020}
2121
2222mysql_8_0 () {
23- $CONTAINER_CLI rm -f mysql || true
24- $CONTAINER_CLI run --name mysql -e MYSQL_USER=hibernate_orm_test -e MYSQL_PASSWORD=hibernate_orm_test -e MYSQL_ROOT_PASSWORD=hibernate_orm_test -e MYSQL_DATABASE=hibernate_orm_test -e MYSQL_ROOT_PASSWORD=hibernate_orm_test -p3306:3306 -d ${DB_IMAGE_MYSQL_8_0:- docker.io/ mysql: 8.0.31} --character-set-server=utf8mb4 --collation-server=utf8mb4_0900_as_cs --skip-character-set-client-handshake --log-bin-trust-function-creators=1 --lower_case_table_names=2
25- # Give the container some time to start
26- OUTPUT=
27- n=0
28- until [ " $n " -ge 5 ]
29- do
30- # Need to access STDERR. Thanks for the snippet https://stackoverflow.com/a/56577569/412446
31- { OUTPUT=" $( { $CONTAINER_CLI logs mysql; } 2>&1 1>&3 3>& - ) " ; } 3>&1 ;
32- if [[ $OUTPUT == * " ready for connections" * ]]; then
33- break ;
34- fi
35- n=$(( n+ 1 ))
36- echo " Waiting for MySQL to start..."
37- sleep 5
38- done
39- if [ " $n " -ge 5 ]; then
40- echo " MySQL failed to start and configure after 15 seconds"
41- else
42- echo " MySQL successfully started"
43- fi
23+ local skip=" --skip-character-set-client-handshake"
24+ mysql_setup " 8.0" " $skip "
4425}
4526
4627mysql_8_1 () {
47- $CONTAINER_CLI rm -f mysql || true
48- $CONTAINER_CLI run --name mysql -e MYSQL_USER=hibernate_orm_test -e MYSQL_PASSWORD=hibernate_orm_test -e MYSQL_ROOT_PASSWORD=hibernate_orm_test -e MYSQL_DATABASE=hibernate_orm_test -e MYSQL_ROOT_PASSWORD=hibernate_orm_test -p3306:3306 -d ${DB_IMAGE_MYSQL_8_1:- docker.io/ mysql: 8.1.0} --character-set-server=utf8mb4 --collation-server=utf8mb4_0900_as_cs --skip-character-set-client-handshake --log-bin-trust-function-creators=1 --lower_case_table_names=2
49- # Give the container some time to start
50- OUTPUT=
51- n=0
52- until [ " $n " -ge 5 ]
53- do
54- # Need to access STDERR. Thanks for the snippet https://stackoverflow.com/a/56577569/412446
55- { OUTPUT=" $( { $CONTAINER_CLI logs mysql; } 2>&1 1>&3 3>& - ) " ; } 3>&1 ;
56- if [[ $OUTPUT == * " ready for connections" * ]]; then
57- break ;
58- fi
59- n=$(( n+ 1 ))
60- echo " Waiting for MySQL to start..."
61- sleep 5
62- done
63- if [ " $n " -ge 5 ]; then
64- echo " MySQL failed to start and configure after 15 seconds"
65- else
66- echo " MySQL successfully started"
67- fi
28+ local skip=" --skip-character-set-client-handshake"
29+ mysql_setup " 8.1" " $skip "
6830}
6931
7032mysql_8_2 () {
71- $CONTAINER_CLI rm -f mysql || true
72- $CONTAINER_CLI run --name mysql -e MYSQL_USER=hibernate_orm_test -e MYSQL_PASSWORD=hibernate_orm_test -e MYSQL_ROOT_PASSWORD=hibernate_orm_test -e MYSQL_DATABASE=hibernate_orm_test -e MYSQL_ROOT_PASSWORD=hibernate_orm_test -p3306:3306 -d ${DB_IMAGE_MYSQL_8_2:- docker.io/ mysql: 8.2.0} --character-set-server=utf8mb4 --collation-server=utf8mb4_0900_as_cs --skip-character-set-client-handshake --log-bin-trust-function-creators=1 --lower_case_table_names=2
73- # Give the container some time to start
74- OUTPUT=
75- n=0
76- until [ " $n " -ge 5 ]
77- do
78- # Need to access STDERR. Thanks for the snippet https://stackoverflow.com/a/56577569/412446
79- { OUTPUT=" $( { $CONTAINER_CLI logs mysql; } 2>&1 1>&3 3>& - ) " ; } 3>&1 ;
80- if [[ $OUTPUT == * " ready for connections" * ]]; then
81- break ;
82- fi
83- n=$(( n+ 1 ))
84- echo " Waiting for MySQL to start..."
85- sleep 5
86- done
87- if [ " $n " -ge 5 ]; then
88- echo " MySQL failed to start and configure after 15 seconds"
89- else
90- echo " MySQL successfully started"
91- fi
33+ local skip=" --skip-character-set-client-handshake"
34+ mysql_setup " 8.2" " $skip "
9235}
9336
9437mysql_9_2 () {
38+ local init_connect=" --init-connect=SET character_set_client='utf8mb4';SET character_set_results='utf8mb4';SET character_set_connection='utf8mb4';SET collation_connection='utf8mb4_0900_as_cs';"
39+ mysql_setup " 9.2" " $init_connect "
40+ }
41+
42+ mysql_9_4 () {
43+ local init_connect=" --init-connect=SET character_set_client='utf8mb4';SET character_set_results='utf8mb4';SET character_set_connection='utf8mb4';SET collation_connection='utf8mb4_0900_as_cs';"
44+ mysql_setup " 9.4" " $init_connect "
45+ }
46+
47+ # Generic MySQL function that handles all versions
48+ mysql_setup () {
49+ local version=$1
50+ local extra_args=$2
51+
52+ echo " ${extra_args} "
53+
54+ # Derive image_var and default_image from version
55+ local version_underscore=$( echo " $version " | tr ' .' ' _' )
56+ local image_var=" DB_IMAGE_MYSQL_${version_underscore} "
57+ local default_image=" docker.io/mysql:${version} "
58+ local image_value
59+ eval " image_value=\$ {${image_var} :-${default_image} }"
60+
9561 $CONTAINER_CLI rm -f mysql || true
96- $CONTAINER_CLI run --name mysql -e MYSQL_USER=hibernate_orm_test -e MYSQL_PASSWORD=hibernate_orm_test -e MYSQL_ROOT_PASSWORD=hibernate_orm_test -e MYSQL_DATABASE=hibernate_orm_test -e MYSQL_ROOT_PASSWORD=hibernate_orm_test -p3306:3306 -d ${DB_IMAGE_MYSQL_9_2:- docker.io/ mysql: 9.2.0} --character-set-server=utf8mb4 --collation-server=utf8mb4_0900_as_cs --init-connect=" SET character_set_client= 'utf8mb4';SET character_set_results = 'utf8mb4'; SET character_set_connection= 'utf8mb4'; SET collation_connection = 'utf8mb4_0900_as_cs';" --log-bin-trust-function-creators=1 --lower_case_table_names=2
97- # Give the container some time to start
62+
63+ $CONTAINER_CLI run --name mysql \
64+ -e MYSQL_USER=hibernate_orm_test \
65+ -e MYSQL_PASSWORD=hibernate_orm_test \
66+ -e MYSQL_ROOT_PASSWORD=hibernate_orm_test \
67+ -e MYSQL_DATABASE=hibernate_orm_test \
68+ -p3306:3306 -d " ${image_value} " \
69+ --character-set-server=utf8mb4 \
70+ --collation-server=utf8mb4_0900_as_cs \
71+ --log-bin-trust-function-creators=1 \
72+ --lower_case_table_names=2 \
73+ " ${extra_args} "
74+
75+ # Wait for MySQL to start
9876 OUTPUT=
9977 n=0
100- until [ " $n " -ge 5 ]
101- do
102- # Need to access STDERR. Thanks for the snippet https://stackoverflow.com/a/56577569/412446
78+ until [ " $n " -gt 5 ]; do
10379 { OUTPUT=" $( { $CONTAINER_CLI logs mysql; } 2>&1 1>&3 3>& - ) " ; } 3>&1 ;
10480 if [[ $OUTPUT == * " ready for connections" * ]]; then
105- break ;
81+ break ;
10682 fi
10783 n=$(( n+ 1 ))
10884 echo " Waiting for MySQL to start..."
109- sleep 3
85+ sleep 5
11086 done
111- if [ " $n " -ge 5 ]; then
112- echo " MySQL failed to start and configure after 15 seconds"
87+
88+ if [ " $n " -gt 5 ]; then
89+ echo " MySQL failed to start and configure after 30 seconds"
11390 else
114- echo " MySQL successfully started"
91+ echo " MySQL successfully started"
11592 fi
11693}
11794
@@ -1132,6 +1109,7 @@ if [ -z ${1} ]; then
11321109 echo -e " \tmssql_2022"
11331110 echo -e " \tmssql_2017"
11341111 echo -e " \tmysql"
1112+ echo -e " \tmysql_9_4"
11351113 echo -e " \tmysql_9_2"
11361114 echo -e " \tmysql_8_2"
11371115 echo -e " \tmysql_8_1"
0 commit comments