OKR/build-image/mysql_del/entrypoint.sh

12 lines
500 B
Bash
Raw Normal View History

2025-05-28 16:57:11 +08:00
#!/bin/bash
echo -ne "[client]\nhost=${HOST}\nport=${PORT}\nuser=${MYSQL_USER}\npassword=${MYSQL_PASSWORD}\n" > /etc/my.cnf
create_time=$(mysql --defaults-extra-file=/etc/my.cnf -e "SELECT NOW() - INTERVAL '$REMAIN_DAYS' DAY"|egrep '[0-9]{4}')
if [ -z "$create_time" ]; then
echo "Failed to retrieve create_time. Exiting."
exit 1
fi
echo "Deleting records older than: $create_time"
2025-05-28 17:09:55 +08:00
mysql --defaults-extra-file=/etc/my.cnf -e "delete from question.code_run where create_time <'${create_time}'"