Skip to content

Commit 6683a07

Browse files
committed
Fetch client --socket value from config instead of hardcoding it
Hardcoding the socket path for the init run broke initdb.d/ scripts that expected a different location (because 5.5 has a different default or the user changed the config). Added a function for fetching it with mysqld --verbose --help as we do for datadir, and use that for the initialization runs of the server and client.
1 parent 9898215 commit 6683a07

File tree

4 files changed

+32
-8
lines changed

4 files changed

+32
-8
lines changed

5.5/docker-entrypoint.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ _datadir() {
5858
"$@" --verbose --help --log-bin-index="$(mktemp -u)" 2>/dev/null | awk '$1 == "datadir" { print $2; exit }'
5959
}
6060

61+
# For use with the client if user passes the --socket argument
62+
_socket() {
63+
"$@" --verbose --help --log-bin-index="$(mktemp -u)" 2>/dev/null | awk '$1 == "socket" { print $2; exit }'
64+
}
65+
6166
# allow the container to be started with `--user`
6267
if [ "$1" = 'mysqld' -a -z "$wantHelp" -a "$(id -u)" = '0' ]; then
6368
_check_config "$@"
@@ -87,10 +92,11 @@ if [ "$1" = 'mysqld' -a -z "$wantHelp" ]; then
8792
mysql_install_db --datadir="$DATADIR" --rpm --basedir=/usr/local/mysql
8893
echo 'Database initialized'
8994

90-
"$@" --skip-networking --basedir=/usr/local/mysql --socket=/var/run/mysqld/mysqld.sock &
95+
SOCKET="$(_socket "$@")"
96+
"$@" --skip-networking --basedir=/usr/local/mysql --socket="${SOCKET}" &
9197
pid="$!"
9298

93-
mysql=( mysql --protocol=socket -uroot -hlocalhost --socket=/var/run/mysqld/mysqld.sock)
99+
mysql=( mysql --protocol=socket -uroot -hlocalhost --socket="${SOCKET}" )
94100

95101
for i in {30..0}; do
96102
if echo 'SELECT 1' | "${mysql[@]}" &> /dev/null; then

5.6/docker-entrypoint.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ _datadir() {
5858
"$@" --verbose --help --log-bin-index="$(mktemp -u)" 2>/dev/null | awk '$1 == "datadir" { print $2; exit }'
5959
}
6060

61+
# For use with the client if user passes the --socket argument
62+
_socket() {
63+
"$@" --verbose --help --log-bin-index="$(mktemp -u)" 2>/dev/null | awk '$1 == "socket" { print $2; exit }'
64+
}
65+
6166
# allow the container to be started with `--user`
6267
if [ "$1" = 'mysqld' -a -z "$wantHelp" -a "$(id -u)" = '0' ]; then
6368
_check_config "$@"
@@ -87,10 +92,11 @@ if [ "$1" = 'mysqld' -a -z "$wantHelp" ]; then
8792
mysql_install_db --datadir="$DATADIR" --rpm --keep-my-cnf
8893
echo 'Database initialized'
8994

90-
"$@" --skip-networking --socket=/var/run/mysqld/mysqld.sock &
95+
SOCKET="$(_socket "$@")"
96+
"$@" --skip-networking --socket="${SOCKET}" &
9197
pid="$!"
9298

93-
mysql=( mysql --protocol=socket -uroot -hlocalhost --socket=/var/run/mysqld/mysqld.sock)
99+
mysql=( mysql --protocol=socket -uroot -hlocalhost --socket="${SOCKET}" )
94100

95101
for i in {30..0}; do
96102
if echo 'SELECT 1' | "${mysql[@]}" &> /dev/null; then

5.7/docker-entrypoint.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ _datadir() {
5858
"$@" --verbose --help 2>/dev/null | awk '$1 == "datadir" { print $2; exit }'
5959
}
6060

61+
# For use with the client if user passes the --socket argument
62+
_socket() {
63+
"$@" --verbose --help --log-bin-index="$(mktemp -u)" 2>/dev/null | awk '$1 == "socket" { print $2; exit }'
64+
}
65+
6166
# allow the container to be started with `--user`
6267
if [ "$1" = 'mysqld' -a -z "$wantHelp" -a "$(id -u)" = '0' ]; then
6368
_check_config "$@"
@@ -94,10 +99,11 @@ if [ "$1" = 'mysqld' -a -z "$wantHelp" ]; then
9499
echo 'Certificates initialized'
95100
fi
96101

97-
"$@" --skip-networking --socket=/var/run/mysqld/mysqld.sock &
102+
SOCKET="$(_socket "$@")"
103+
"$@" --skip-networking --socket="${SOCKET}" &
98104
pid="$!"
99105

100-
mysql=( mysql --protocol=socket -uroot -hlocalhost --socket=/var/run/mysqld/mysqld.sock)
106+
mysql=( mysql --protocol=socket -uroot -hlocalhost --socket="${SOCKET}" )
101107

102108
for i in {30..0}; do
103109
if echo 'SELECT 1' | "${mysql[@]}" &> /dev/null; then

8.0/docker-entrypoint.sh

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,11 @@ _datadir() {
5858
"$@" --verbose --help 2>/dev/null | awk '$1 == "datadir" { print $2; exit }'
5959
}
6060

61+
# For use with the client if user passes the --socket argument
62+
_socket() {
63+
"$@" --verbose --help --log-bin-index="$(mktemp -u)" 2>/dev/null | awk '$1 == "socket" { print $2; exit }'
64+
}
65+
6166
# allow the container to be started with `--user`
6267
if [ "$1" = 'mysqld' -a -z "$wantHelp" -a "$(id -u)" = '0' ]; then
6368
_check_config "$@"
@@ -94,10 +99,11 @@ if [ "$1" = 'mysqld' -a -z "$wantHelp" ]; then
9499
echo 'Certificates initialized'
95100
fi
96101

97-
"$@" --skip-networking --socket=/var/run/mysqld/mysqld.sock &
102+
SOCKET="$(_socket "$@")"
103+
"$@" --skip-networking --socket="${SOCKET}" &
98104
pid="$!"
99105

100-
mysql=( mysql --protocol=socket -uroot -hlocalhost --socket=/var/run/mysqld/mysqld.sock)
106+
mysql=( mysql --protocol=socket -uroot -hlocalhost --socket="${SOCKET}" )
101107

102108
for i in {30..0}; do
103109
if echo 'SELECT 1' | "${mysql[@]}" &> /dev/null; then

0 commit comments

Comments
 (0)