开发者

how to get the result of non-select mysql statements into OUTFILE?

I have created event in mysql to do repair, optimize, and delete old data from some tables on monthly bases.

delimiter $$
Create event CheckMyDB
On SCHEDULE AT current_timestamp + INTERVAL 1 MONTH
DO 
DELETE FROM SESSIONS where MYCONDITION;
REPAIR TABLE DATANODES;
OPTIMIZE TABLE DATANODES;
$$

now how can i know what is the output of my event?? in other words can i save the output of delete, repair and otimize in table (something like INTO OUTFILE) or to insert it into custom table or to send it by email (i dont think se开发者_运维技巧nding email from mysql is possible!!)

Thanks for your help


You can't get the output if it's run as an event (as far as I'm aware) without looking through your logs. However, if you ran it as a script, using a command like:

# mysql -u <user> -p<password> -vvv database < script.sql > script.log 2>&1

You can capture all the output into a text file. The -vvv raises the verbosity of the output so that you get x rows affected etc.

Running this script as a cron job will allow you to set up the same scheduling as your event, but also make emailing out your results file easier.

For security, consider storing your password in the my.cnf file for the user that will be running the script:

[client]
user=<user>
password=<password>

Remember to chmod this file so that only the owner can read it.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜