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

     1  #!/bin/bash
     2  set -e
     3  
     4  host="127.0.0.1"
     5  port=3306
     6  user="root"
     7  password=""
     8  file=""
     9  ssl_key=""
    10  ssl_cert=""
    11  
    12  while [[ ${1} ]]; do
    13  	case "${1}" in
    14  	--host)
    15  		host=${2}
    16  		shift
    17  		;;
    18  	--port)
    19  		port=${2}
    20  		shift
    21  		;;
    22  	--user)
    23  		user=${2}
    24  		shift
    25  		;;
    26  	--password)
    27  		password=${2}
    28  		shift
    29  		;;
    30  	--ssl-key)
    31  		ssl_key=${2}
    32  		shift
    33  		;;
    34  	--ssl-cert)
    35  		ssl_cert=${2}
    36  		shift
    37  		;;
    38  	*)
    39  		file=${1}
    40  		;;
    41  	esac
    42  
    43  	if ! shift; then
    44  		echo 'Missing parameter argument.' >&2
    45  		exit 1
    46  	fi
    47  done
    48  
    49  cmd="mysql -u${user} -h${host} -P${port}"
    50  if [[ -n ${password} ]]; then
    51  	cmd="${cmd} -p${password}"
    52  fi
    53  if [[ -n ${ssl_key} ]]; then
    54  	cmd="${cmd} --ssl-key=${ssl_key}"
    55  fi
    56  if [[ -n ${ssl_cert} ]]; then
    57  	cmd="${cmd} --ssl-cert=${ssl_cert}"
    58  fi
    59  cmd="${cmd} --default-character-set utf8mb4 <${file}"
    60  
    61  echo "will execute: $cmd"
    62  eval $cmd