截断Mysql表Cron作业

截断Mysql表Cron作业

本文介绍了截断Mysql表Cron作业?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在使用cron作业截断Mysql表时遇到了一些麻烦.不管我尝试什么,我似乎都无法使数据库清除表..谢谢您的帮助.

I am having some trouble on how to Truncate a Mysql Table with a cron job. No matter what I try I can't seem to get the database to clear out the table.. Thanks for the help.

mysql -uderp_example -pexample -hlocalhost -Dexample -e"TRUNCATE TABLE juicebox"

我正在使用这个:

http://i.stack.imgur.com/FUmow.png

&& /var/lib/mysql/fruitloops_juicebox添加路径仍然不能解决问题...我不明白这是怎么回事.

&& /var/lib/mysql/fruitloops_juicebox adding the path still doesn't solve the issue... I don't understand whats wrong.

推荐答案

命令失败的最可能原因是您没有提供mysql的绝对路径.用这种方式做

The most likely reason your command is failing is that you didn't provide an absolute path for mysql. Do it this way

/path/to/mysql -uderp_example -pexample -hlocalhost -Dexample -e"TRUNCATE TABLE juice box"
^^^^^^^^

它应该可以正常工作.

这是因为cron在未定义PATH或不包含mysql路径的帐户下执行.

It's because cron executes under an account which either does not have PATH defined or does not include a path to mysql.

现在还有另一种选择-使用 MySQL事件

Now there is another option - using a MySQL event

CREATE EVENT update_date_column
  ON SCHEDULE EVERY 1 HOUR STARTS NOW()
  DO TRUNCATE TABLE juicebox;

如果您决定采用事件方法:

If you'll decide to go with an event approach:

  • 使用 SHOW EVENTS 列出创建的事件及其属性(例如status)
  • 使用 SHOW PROCESSLIST 检查是否事件调度程序已启用.如果打开,您应该会看到用户"event_scheduler"的进程"Daemon".
  • 使用SET GLOBAL event_scheduler = ON;启用调度程序(如果当前未启用).
  • 有关配置事件调度程序的更多信息,请在此处
  • use SHOW EVENTS to list created events with their attributes (e.g. status)
  • use SHOW PROCESSLIST to check if the event scheduler is enabled. If it's ON you should see a process "Daemon" by user "event_scheduler".
  • use SET GLOBAL event_scheduler = ON;to enable the scheduler if it's currently not enabled.
  • More on configuring event scheduler read here

这篇关于截断Mysql表Cron作业?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-22 16:54