github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/engine/test/utils/wait_mysql_online.sh (about)

     1  #!/bin/bash
     2  set -e
     3  
     4  host="127.0.0.1"
     5  port=3306
     6  user="root"
     7  password=""
     8  args=""
     9  tryNums=100
    10  
    11  while [[ ${1} ]]; do
    12  	case "${1}" in
    13  	--host)
    14  		host=${2}
    15  		shift
    16  		;;
    17  	--port)
    18  		port=${2}
    19  		shift
    20  		;;
    21  	--user)
    22  		user=${2}
    23  		shift
    24  		;;
    25  	--password)
    26  		password=${2}
    27  		shift
    28  		;;
    29  	--try-nums)
    30  		tryNums=${2}
    31  		shift
    32  		;;
    33  	*)
    34  		args="$args ${1}"
    35  		;;
    36  	esac
    37  
    38  	if ! shift; then
    39  		echo 'Missing parameter argument.' >&2
    40  		exit 1
    41  	fi
    42  done
    43  
    44  echo "Verifying database ${user}@${host}:${port} is started..."
    45  i=0
    46  if [ -z ${password} ]; then
    47  	check_cmd="mysql -u${user} -h${host} -P${port} ${args} --default-character-set utf8mb4 -e 'select version()'"
    48  else
    49  	check_cmd="mysql -u${user} -h${host} -P${port} ${args} -p${password} --default-character-set utf8mb4 -e 'select version()'"
    50  fi
    51  while ! eval $check_cmd; do
    52  	i=$((i + 1))
    53  	if [ "$i" -gt ${tryNums} ]; then
    54  		echo 'Failed to start database'
    55  		exit 2
    56  	fi
    57  	sleep 2
    58  done