From 66391045140de2a9ba3518b7346a0f4317752d40 Mon Sep 17 00:00:00 2001 From: HOHO <591310381@qq.com> Date: Sun, 19 Sep 2021 20:26:33 +0800 Subject: [PATCH 1/2] support all databases outside system schema --- analyze.sh | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/analyze.sh b/analyze.sh index 0b40fc0..09aec18 100755 --- a/analyze.sh +++ b/analyze.sh @@ -2,7 +2,7 @@ settings(){ # Configuration db information - db_name='test' + # db_name='test' db_user='root' db_port=4000 # Note: Password cannot be empty !!!! @@ -17,7 +17,7 @@ environment(){ analyze(){ # Execute analyze table command and run in background - analyze_table=$(($mysql_path -u$db_user -h$db_ip -P$db_port -p$db_password $db_name -e "analyze TABLE $table_names;") >> analyze.log &) + analyze_table=$($mysql_path -u$db_user -h$db_ip -P$db_port -p$db_password $d_name -e "analyze TABLE $1;") } other(){ @@ -30,19 +30,36 @@ main(){ settings; environment; - # Get all table names in the library - local table_name=$($mysql_path -u$db_user -h$db_ip -P$db_port -p$db_password $db_name -e "show tables;") - local table_name=($table_name) + # Get all databases in the instance + local db_name=$($mysql_path -u$db_user -h$db_ip -P$db_port -p$db_password $db_name -e "show databases;") + local db_name=($db_name) - # Loop analyze all tables - for ((i=1;i<${#table_name[@]};i++)) + echo '==================begin==================' >> analyze.log + current_time=`date +"%Y-%m-%d %H:%M:%S"` + echo $current_time >> analyze.log + + # Loop analyze all tables of each database + for ((i=1;i<${#db_name[@]};i++)) do - local table_names=${table_name[i]} - echo "Analyze table "$table_names - analyze; + local d_name=${db_name[i]} + if [ "$d_name" != "test" ] && [ "$d_name" != "mysql" ] && [ "$d_name" != "INFORMATION_SCHEMA" ] && [ "$d_name" != "METRICS_SCHEMA" ] && [ "$d_name" != "PERFORMANCE_SCHEMA" ];then + echo "----use database: $d_name----" >> analyze.log + + local table_name=$($mysql_path -u$db_user -h$db_ip -P$db_port -p$db_password $d_name -e "show tables;") + local table_name=($table_name) + for ((j=1;j<${#table_name[@]};j++)) + do + local table_names=${table_name[j]} + echo "analyze table:$table_names" >> analyze.log + analyze $table_names; + # other; + sleep 0.5 + done + fi # other; - sleep 0.5 + #sleep 0.5 done + echo '==================end==================' >> analyze.log } main; From 683805b008fa890f5d92cea23d84a5366695e8b7 Mon Sep 17 00:00:00 2001 From: HOHO <591310381@qq.com> Date: Sun, 19 Sep 2021 20:36:28 +0800 Subject: [PATCH 2/2] Update analyze.sh --- analyze.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/analyze.sh b/analyze.sh index 09aec18..854f20c 100755 --- a/analyze.sh +++ b/analyze.sh @@ -17,7 +17,7 @@ environment(){ analyze(){ # Execute analyze table command and run in background - analyze_table=$($mysql_path -u$db_user -h$db_ip -P$db_port -p$db_password $d_name -e "analyze TABLE $1;") + analyze_table=$(($mysql_path -u$db_user -h$db_ip -P$db_port -p$db_password $d_name -e "analyze TABLE $1;") >> analyze.log &) } other(){