需求:在数据库中有一个datetine类型的字段,该字段的值为数据库服务器的当前时间,该字段自动实时获取系统时间。
解决方案:
1、首先新建一个【函数】:
create procedure Time_Function() begain update test set test_time=Now() where Id=0 end
2、查看并打开event_scheduler调度事件:
注:如果event_scheduler值为OFF则使用set global event_scheduler =1;打开。
3、创建Event调度任务:
在定义中调用我们上一步定义的函数:
call Time_Function()
设置计划
这里的意思是每10秒 调用一次函数。
PS:如果事件计划没有执行成功,直接调用函数:call Time_Function()
提示:
mysql 1449 : The user specified as a definer ('montor'@'%') does not exist
说明是权限问题;执行:grant all privileges on *.* to monitor@"%" identified by ".";