根据时间自动更新数据库中的列的方法 [英] Way to auto update a column in database depending on time

查看:466
本文介绍了根据时间自动更新数据库中的列的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有任何方法或脚本允许自动更新我的数据库中的列每天午夜12。例如,我有一个列'x',当前值在列x的某一行是说10,什么我想要重新初始化该值为0,因为时钟敲00: 00:00.有没有办法做到这一点?
我的数据库的详细信息:mysql in phpmyadmin。
我知道的脚本:javascripts或php。

Is there any way or script that allows to auto update the column in my database everyday at midnight 12.For eg I have a column 'x' ,currently value in certain row under column 'x' is say 10, What I want is to reinitialize that value to 0 as the clock strikes 00:00:00.Is there any way to do this ? My database details : mysql in phpmyadmin. Scripts I am aware of : javascripts or php.

推荐答案

您可以使用MySQL的事件调度程序

You can use MySQL's event scheduler

CREATE EVENT update_status ON SCHEDULE EVERY 1 DAY STARTS '2013-11-02 00:00:00' DO
  UPDATE your_table
  SET    x = 0

为了使事件调度程序运行,可以将其添加到my.cnf :

In order to make the event scheduler run you can add this in my.cnf:

[mysqld]
...
event_scheduler=ON

阅读这个更多信息 http://dev.mysql.com/doc/refman/5.1/en/create-event.html

这篇关于根据时间自动更新数据库中的列的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆