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