Bash Script to Execute Mysql Command

Here is my bash script to execute msyql command

!/bin/bash
tglblk=$(date –date=”8 days ago” +%Y-%m-%d)
tglhapus=”$tglblk 23:00:00″
SQL=”DELETE FROM Events WHERE EndTime<=’$tglhapus’;”
MYSQL_USER=”root”
MYSQL_PASS=””
MYSQL_DB=”mydb”
echo $SQL | mysql –user=$MYSQL_USER –password=$MYSQL_PASS $MYSQL_DB

Then I put it into crontab to run at specific time.

Leave a Reply

Your email address will not be published. Required fields are marked *