#!/bin/bash
DBPATH="/server/shell_scripts/mysql/analyze_all_db_tables"
MYUSER="shukuinfo"
MYPASS="shukuinfo_123."
HOST="172.16.1.100"
#SOCKET=/var/lib/mysql/mysql.sock
MYCMD="/usr/bin/mysql -u$MYUSER -p$MYPASS -h$HOST"
MYDUMP="/usr/bin/mysqldump -u$MYUSER -p$MYPASS -h$HOST"
DATADIR="/var/lib/mysql"
DB_CONFIG="/etc/my.cnf"
[ ! -d "$DBPATH" ]&& mkdir $DBPATH -p
[ -f "$DBPATH/analyze.log" ] || touch $DBPATH/analyze.log
echo $(echo `$MYCMD -e "show databases;"|sed '1,2d'|egrep -v "mysql|schema|sys|hexin_history|performance_schema|information_schema|test|puyuan|temp"`)>/tmp/analyze_db.log
for dbname in `cat /tmp/analyze_db.log`
do
echo $(echo `$MYCMD -e "show tables from $dbname;"|sed '1d'|egrep -v "temp*"`)>/tmp/analyze_table.log
for table in `cat /tmp/analyze_table.log`
do
echo "$(date +%F_%H-%M-%S)-Start to analyze dbname:$dbname -->Table:$table ....">>$DBPATH/analyze.log
$MYCMD -e "analyze table ${dbname}.$table;"
echo "$(date +%F_%H-%M-%S)-analyze dbname:$dbname -->Table:$table success">>$DBPATH/analyze.log
sleep 0.1
done
done
DBPATH="/server/shell_scripts/mysql/analyze_all_db_tables"
MYUSER="shukuinfo"
MYPASS="shukuinfo_123."
HOST="172.16.1.100"
#SOCKET=/var/lib/mysql/mysql.sock
MYCMD="/usr/bin/mysql -u$MYUSER -p$MYPASS -h$HOST"
MYDUMP="/usr/bin/mysqldump -u$MYUSER -p$MYPASS -h$HOST"
DATADIR="/var/lib/mysql"
DB_CONFIG="/etc/my.cnf"
[ ! -d "$DBPATH" ]&& mkdir $DBPATH -p
[ -f "$DBPATH/analyze.log" ] || touch $DBPATH/analyze.log
echo $(echo `$MYCMD -e "show databases;"|sed '1,2d'|egrep -v "mysql|schema|sys|hexin_history|performance_schema|information_schema|test|puyuan|temp"`)>/tmp/analyze_db.log
for dbname in `cat /tmp/analyze_db.log`
do
echo $(echo `$MYCMD -e "show tables from $dbname;"|sed '1d'|egrep -v "temp*"`)>/tmp/analyze_table.log
for table in `cat /tmp/analyze_table.log`
do
echo "$(date +%F_%H-%M-%S)-Start to analyze dbname:$dbname -->Table:$table ....">>$DBPATH/analyze.log
$MYCMD -e "analyze table ${dbname}.$table;"
echo "$(date +%F_%H-%M-%S)-analyze dbname:$dbname -->Table:$table success">>$DBPATH/analyze.log
sleep 0.1
done
done