Solved

MySQL Stored Procedure

Posted on 2014-01-17
6
413 Views
Last Modified: 2014-02-17
I have a stored procedure in a MYSQL database

I have to manually run the SP everytime, is there a way of doing this at a set time everyday?
0
Comment
Question by:Brogrim
  • 3
  • 2
6 Comments
 
LVL 11

Expert Comment

by:Angelp1ay
ID: 39788203
http://dev.mysql.com/doc/refman/5.1/en/create-event.html

CREATE EVENT myevent
    ON SCHEDULE 
    AT '2014-01-17 03:00:00'    
    EVERY 1 WEEK
    DO yourProcedure();

Open in new window


CREATE
    [DEFINER = { user | CURRENT_USER }]
    EVENT
    [IF NOT EXISTS]
    event_name
    ON SCHEDULE schedule
    [ON COMPLETION [NOT] PRESERVE]
    [ENABLE | DISABLE | DISABLE ON SLAVE]
    [COMMENT 'comment']
    DO event_body;

schedule:
    AT timestamp [+ INTERVAL interval] ...
  | EVERY interval
    [STARTS timestamp [+ INTERVAL interval] ...]
    [ENDS timestamp [+ INTERVAL interval] ...]

interval:
    quantity {YEAR | QUARTER | MONTH | DAY | HOUR | MINUTE |
              WEEK | SECOND | YEAR_MONTH | DAY_HOUR | DAY_MINUTE |
              DAY_SECOND | HOUR_MINUTE | HOUR_SECOND | MINUTE_SECOND}

Open in new window

0
 

Author Comment

by:Brogrim
ID: 39788253
Thanks for the advice, I am not very proficient on this and am having trouble understanding above code

The name of my SP is "PermitWeb" and I want it to run everyday at 18:00 hours.

Can you give me an extra hint on this
0
 

Author Comment

by:Brogrim
ID: 39788321
This is my latest attempt

DELIMITER $$
CREATE EVENT `ParkingEnforcement` 
ON SCHEDULE EVERY 1 Day Starts '2014-01-17 13:00:00'
BEGIN
Call PermitWeb;
END 

Open in new window


How can I check this to ensure it executed?
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 11

Expert Comment

by:Angelp1ay
ID: 39788582
I would just schedule it for close to the current time and check you get the result you expect when you run the SP.

You can use SHOW EVENTS to list them:
http://dev.mysql.com/doc/refman/5.1/en/show-events.html
SHOW EVENTS [{FROM | IN} schema_name]
    [LIKE 'pattern' | WHERE expr]

Open in new window


There's also a log:
http://dev.mysql.com/doc/refman/5.1/en/events-status-info.html
Beginning with MySQL 5.1.12, event scheduler status information can be obtained by running mysqladmin debug (see Section 4.5.2, “mysqladmin — Client for Administering a MySQL Server”); after running this command, the server's error log contains output relating to the Event Scheduler

Open in new window

Events status:
LLA = Last Locked At  LUA = Last Unlocked At
WOC = Waiting On Condition  DL = Data Locked

Event scheduler status:
State      : INITIALIZED
Thread id  : 0
LLA        : init_scheduler:313
LUA        : init_scheduler:318
WOC        : NO
Workers    : 0
Executed   : 0
Data locked: NO

Event queue status:
Element count   : 1
Data locked     : NO
Attempting lock : NO
LLA             : init_queue:148
LUA             : init_queue:168
WOC             : NO
Next activation : 0000-00-00 00:00:00

Open in new window

0
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 total points
ID: 39788763
I learned something new (events in mysql) :)

I would have done it like this:
you can build up such a command line:
mysql --user=your_username --execute="call stored_procedure_name()" db_name

Open in new window

, eventually into a batch/script file....
and then schedule that in your normal OS scheduling application
0
 

Author Comment

by:Brogrim
ID: 39801860
sorry about the delay in getting back, I will try the above ASAP, Guy that looks the simplest solution
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Fore-Foreword Today (2016) Maxmind has a new approach to the distribution of its data sets.  This article may be obsolete.  Instead of using the examples here, have a look at the MaxMind API (https://www.maxmind.com/en/geolite2-developer-package). …
Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now