Clean remote MySQL database

Dr Panos 4 years ago

Hello.
I am using a remote mySQL database. In this case can I use this script for cleaning the history?
And if yes how would it be the syntax?

Anton Tananaev 4 years ago

Which this script?

Dr Panos 4 years ago

This script

cat > /etc/cron.daily/traccar-clear-database << EOF
#!/bin/bash
result=""
while [[ "$result" != *" 0 rows affected"* ]]; do
  result=$(mysql -u root -proot traccar -vve "DELETE FROM tc_positions WHERE fixTime < DATE(DATE_ADD(NOW(), INTERVAL -7 DAY)) AND id NOT IN (SELECT positionId FROM tc_devices WHERE positionid IS NOT NULL) LIMIT 10000")
  sleep 1
done
result=""
while [[ "$result" != *" 0 rows affected"* ]]; do
  result=$(mysql -u root -proot traccar -vve "DELETE FROM tc_events WHERE eventTime < DATE(DATE_ADD(NOW(), INTERVAL -7 DAY)) LIMIT 10000")
  sleep 1
done
EOF
chmod +x /etc/cron.daily/traccar-clear-database

As I see this is refering to local mySQL install. Is there something similar for remote database?

Anton Tananaev 4 years ago

Yes, you should be able to use the same script. Just change mysql command line arguments.

Dr Panos 4 years ago

You mean with my public address and credentials?

Anton Tananaev 4 years ago

Yes.