Skip to content

Instantly share code, notes, and snippets.

@lichti
Created October 29, 2015 03:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save lichti/a21d79d34de60a2707f0 to your computer and use it in GitHub Desktop.
Save lichti/a21d79d34de60a2707f0 to your computer and use it in GitHub Desktop.
mysql_optimize_ng.sh
#!/bin/bash
MYSQL_LOGIN='-uroot --password=neOfByon'
while read line
do
# SIZE | DATABASE | TABLE | FLAG
SIZE=$( echo "$line" | cut -d\| -f 1)
DATABASE=$( echo "$line" | cut -d\| -f 2)
TABLE=$( echo "$line" | cut -d\| -f 3)
FLAG=$( echo "$line" | cut -d\| -f 4)
if [ $FLAG -eq 1 ];then
echo -n " * Optimizing $DATABASE $TABLE ($SIZE) ... "
echo "USE $DATABASE; OPTIMIZE TABLE $TABLE" | mysql $MYSQL_LOGIN >/dev/null
fi
done < $1
#Executar script
# timeout 140m ./bin/mysql_optimize_ng.sh /root/tables.txt
#Gerar lista
# cd /var/lib/mysql/; ls -lhS */*.ibd | tac | awk '{print $5,$9}' | tr '/' ' ' | sed s/\ /\ \|\ /g | sed s/\.ibd/\ \|\ 1/g > /tmp/tables.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment