@@ -66,25 +66,40 @@ connect()
6666 return " $s " ;
6767 ;;
6868 esac
69- # falling back to this if there wasn't a connection answer.
70- set +e +o pipefail
71- # (on second extra_file)
72- # shellcheck disable=SC2086
73- mariadb ${nodefaults: +--no-defaults} \
69+ # falling back to tcp if there wasn't a connection answer.
70+ s=$( mariadb ${nodefaults: +--no-defaults} \
7471 ${def['file']: +--defaults-file=${def['file']} } \
7572 ${def['extra_file']: +--defaults-extra-file=${def['extra_file']} } \
7673 ${def['group_suffix']: +--defaults-group-suffix=${def['group_suffix']} } \
7774 --skip-ssl --skip-ssl-verify-server-cert \
78- -h localhost --protocol tcp -e ' select 1' 2>&1 \
79- | grep -qF " Can't connect"
80- local ret=${PIPESTATUS[1]}
81- set -eo pipefail
82- if (( "$ret " == 0 )) ; then
83- # grep Matched "Can't connect" so we fail
84- connect_s=1
85- else
86- connect_s=0
87- fi
75+ -h localhost --protocol tcp \
76+ --skip-column-names --batch --skip-print-query-on-error \
77+ -e ' select @@skip_networking' 2>&1 )
78+
79+ case " $s " in
80+ 1) # skip-networking=1 (no network)
81+ ;&
82+ ERROR\ 2002\ \( HY000\) :* )
83+ # cannot connect
84+ connect_s=1
85+ ;;
86+ 0) # skip-networking=0
87+ ;&
88+ ERROR\ 1820\ \( HY000\) * ) # password expire
89+ ;&
90+ ERROR\ 4151\ \( HY000\) :* ) # account locked
91+ ;&
92+ ERROR\ 1226\ \( 42000\) * ) # resource limit exceeded
93+ ;&
94+ ERROR\ 1[0-9][0-9][0-9]\ \( 28000\) :* )
95+ # grep access denied and other 28000 client errors - we did connect
96+ connect_s=0
97+ ;;
98+ * )
99+ >&2 echo " Unknown error $s "
100+ connect_s=1
101+ ;;
102+ esac
88103 return $connect_s
89104}
90105
@@ -367,8 +382,8 @@ while [ $# -gt 0 ]; do
367382 fi
368383 shift
369384done
370- if [ -z " $connect_s " ]; then
371- # we didn't do a connnect test, so the current success status is suspicious
385+ if [ " $connect_s " != " 0 " ]; then
386+ # we didn't pass a connnect test, so the current success status is suspicious
372387 # return what connect thinks.
373388 connect
374389 exit $?
0 commit comments