Automating MySql Scripts

2 Aug

So I needed to run a mysql script on a daily basis to do some maintenance on a database.

Pretty straight forward

davessql.sql:

USE databasename
DELETE FROM 'tablename' where timestamp <= DATE_SUB(NOW(), INTERVAL 1 MONTH);

davesbatch.bat

"C:\Program Files\MySQL\MySQL Server 5.5\bin\mysql.exe" -uUSERNAME -pPASSWORD < "davessql.sql"

Then a scheduled task to call the batch file, job done.