Solved

MySQL Stored Procedure

Posted on 2014-01-17
6
419 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
The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

 
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 143

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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I use MySQL for many of my development projects in a Windows environment. To manage my databases (and perform queries) for years I used a tool called MySQL administrator.  This tool has since been replaced by MySQL Workbench. So I decided to m…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

685 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