15

I want to increment a field on the first minute of every day, and then once it hits a certain value, set the value to 1. I would like to do this directly in MySQL, but preferably through phpMyAdmin.

I am aware of the Event Scheduler, and so I'm looking for a way to use and manage it through phpMyAdmin. Is this possible?

3 Answers 3

33

It is.. Just issue appropriate CREATE EVENT SQL from SQL box.

However: your MySQL server needs to have event scheduler enabled AND have EVENT privileges for the database user.

Calling SELECT @@event_scheduler; will tell you if the scheduler is available and enabled.

To enable event scheduler if it's disabled try calling SET GLOBAL event_scheduler := 1; You need the SUPER privilege for this to succeed.

2
  • 1
    Great, also just as an aside, you need MySQL 5.1 or greater to use this feature.
    – Lars
    Jul 8, 2011 at 14:13
  • Yup. SELECT @@event_scheduler; will raise an error in lower versions.
    – Mchl
    Jul 8, 2011 at 18:02
25

Select query browser in phpmyadmin run the query to ON event scheduler

SET GLOBAL event_scheduler = ON;

Only super privilege user can do this. To grand privilege to user by

GRANT EVENT ON myschema.* TO jon@ghidora;

Check event_sheduler status ON or OFF by

SELECT @@event_scheduler;

If status is ON go ahead for create event

CREATE EVENT e_store_ts
    ON SCHEDULE
      EVERY 10 SECOND
    DO
      INSERT INTO myschema.mytable VALUES (UNIX_TIMESTAMP());

To see the events that created

SHOW EVENTS;
1
  • Hello you example is really greate but how about update data with every one month especially first date in month, i hvae been teested your query is really great, but change as needed it doesn't work, please have see images is here prntscr.com/a2ncgl Feb 13, 2016 at 9:35
3

If doing this on Amazon RDS you need to edit the parameter group to add EVENT_SCHEDULER = ON. One easy way to do this is via a free Rightscale account.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.