github.com/pingcap/tiflow@v0.0.0-20240520035814-5bf52d54e205/dm/tests/_utils/run_tidb_server (about)

     1  #!/bin/sh
     2  # parameter 1: tidb port
     3  # parameter 2: tidb password
     4  # parameter 3: optional, tidb config file
     5  
     6  set -eu
     7  
     8  tmp_config="/tmp/dm_test/tidb.toml"
     9  
    10  PORT=$1
    11  PASSWORD=$2
    12  CONFIG=""
    13  
    14  if [ "$#" -ge 3 ]; then
    15  	cat $3 >$tmp_config
    16  else
    17  	# turn on collation framework https://docs.pingcap.com/tidb/stable/character-set-and-collation#new-framework-for-collations
    18  	rm $tmp_config || true
    19  	cat >$tmp_config <<EOF
    20  new_collations_enabled_on_first_bootstrap = true
    21  
    22  [experimental]
    23  enable-new-charset = true
    24  
    25  EOF
    26  fi
    27  
    28  TEST_DIR=/tmp/dm_test
    29  
    30  echo "Starting TiDB on port ${PORT}"
    31  bin/tidb-server \
    32  	-P ${PORT} \
    33  	--config "$tmp_config" \
    34  	--log-file "$TEST_DIR/downstream/tidb/log/tidb.log" &
    35  
    36  echo "Verifying TiDB is started..."
    37  i=0
    38  while ! mysql -uroot -h127.0.0.1 -P${PORT} --default-character-set utf8 -e 'select * from mysql.tidb;'; do
    39  	i=$((i + 1))
    40  	if [ "$i" -gt 10 ]; then
    41  		echo 'Failed to start TiDB'
    42  		exit 1
    43  	fi
    44  	sleep 2
    45  done
    46  
    47  # if user test is already exist, add || true to avoid exit with 2
    48  mysql -uroot -h127.0.0.1 -P${PORT} --default-character-set utf8 -e "CREATE USER 'test'@'%' IDENTIFIED BY '$PASSWORD';" || true
    49  mysql -uroot -h127.0.0.1 -P${PORT} --default-character-set utf8 -e "GRANT ALL PRIVILEGES ON *.* TO 'test'@'%' WITH GRANT OPTION;" || true
    50  mysql -uroot -h127.0.0.1 -P${PORT} --default-character-set utf8 -e "SET @@global.tidb_enable_clustered_index = 'INT_ONLY'"
    51  mysql -uroot -h127.0.0.1 -P${PORT} --default-character-set utf8 -e "SET @@global.tidb_ddl_enable_fast_reorg = 0" || true
    52  mysql -uroot -h127.0.0.1 -P${PORT} --default-character-set utf8 -e "SET @@global.tidb_enable_dist_task = 0" || true