-
Notifications
You must be signed in to change notification settings - Fork 49
Expand file tree
/
Copy pathrun_sql_file
More file actions
executable file
·31 lines (23 loc) · 1.05 KB
/
run_sql_file
File metadata and controls
executable file
·31 lines (23 loc) · 1.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/bin/bash
# parameter 1: path to sql file
# parameter 2: database host
# parameter 3: database port
set -eu
prepare="set global tidb_enable_clustered_index = 'int_only'; set global tidb_enable_fast_create_table = OFF;"
# Check if OUT_DIR contains TEST_NAME, if so, truncate OUT_DIR to the parent directory
ADJUSTED_OUT_DIR="$OUT_DIR"
if [ -n "$TEST_NAME" ] && [[ "$OUT_DIR" == *"/$TEST_NAME"* ]]; then
ADJUSTED_OUT_DIR="${OUT_DIR%/$TEST_NAME}"
fi
log_file="$ADJUSTED_OUT_DIR/$TEST_NAME/sql_res.$TEST_NAME.log"
remainLogFile="$ADJUSTED_OUT_DIR/$TEST_NAME/sql_res.$TEST_NAME.remain.log"
log_with_timestamp() {
# Clear the log file at the start of each command
while IFS= read -r line; do
echo "[$(date)] $line" >>"$remainLogFile"
done
}
echo "[$(date)] Executing SQL: $1" >"$log_file"
echo "[$(date)] Executing SQL: $1" >>"$remainLogFile"
mysql -uroot -h$2 -P$3 --default-character-set utf8mb4 -E -e "${prepare}" 2>&1 | tee "$log_file" | log_with_timestamp
mysql -uroot -h$2 -P$3 --default-character-set utf8mb4 -vv <"$1" 2>&1 | tee "$log_file" | log_with_timestamp