informatique:base_de_donnees:script_d_optimisation_automatique_des_bases

Script d'optimisation automatique des bases

Ce script optimise les bases de données MySQL présentes sous /var/lib/mysql.

  #!/bin/bash 
 
  for base in `ls -l /var/lib/mysql/|grep dr|grep -Ev "test|status|mail|dumps"|awk '{print $NF}'`
  do
  echo "use $base;" > /tmp/optmz_${base}.sql
  echo -e "OPTIMIZE TABLE \c" >> /tmp/optmz_${base}.sql
          for table in `ls -1 /var/lib/mysql/$base/*.frm|awk -F "/" '{print $6}'|awk -F "." '{print $1}'`
          do
          echo -e "$table,\c" >> /tmp/optmz_${base}.sql
          done
  echo ";" >> /tmp/optmz_${base}.sql
  cat /tmp/optmz_${base}.sql|sed "s/,;/;/g" > /tmp/optmz_${base}.sql.temp
  mv /tmp/optmz_${base}.sql.temp /tmp/optmz_${base}.sql
  done
 
  for file in `ls -1 /tmp/optmz*.sql`
  do
  mysql -u ''user'' --password=XXXXXXXX < $file #''user'' doit avoir les droits full
  done
 
  rm -f /tmp/optmz*.sql
  • informatique/base_de_donnees/script_d_optimisation_automatique_des_bases.txt
  • Dernière modification : 2009/06/29 21:04
  • de 127.0.0.1