Clear di un database
Ecco come creare uno script sql che svuota tutte le tabelle di un database. Il comando TRUNCATE elimina i dati e resetta gli auto_increment. Prima di eseguire il comando su una tabella disabilita il controllo delle foreign_key e lo riabilita subito dopo.
1mysql -u [username] -p [password] [dbname] -e "show tables" | grep -v Tables_in | grep -v "+" | \gawk '{print "SET FOREIGN_KEY_CHECKS=0; truncate table " $1 "; SET FOREIGN_KEY_CHECKS=1;"}' > dump.sql
In alternativa è possibile eseguire direttamente lo script con il comando mysql:
1mysql -u [username] -p [password] [dbname] -e "show tables" | grep -v Tables_in | grep -v "+" | \gawk '{print "SET FOREIGN_KEY_CHECKS=0; truncate table " $1 "; SET FOREIGN_KEY_CHECKS=1;"}' | mysql -u [username] -p [password] [dbname]
Tip precedente: Estrarre tutte le procedure di un DB
Tip successivo: Ricavare i character set

MySQL Report un tool di shell per tenere tutto sotto controllo