Solved

MySQL Stored Procedure

Posted on 2014-01-17
6
415 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
Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

 
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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
password_verify with prepared statements 10 36
If more than 10% of results are over X in mysql 2 48
Clean text to insert in database 9 51
MySQL Grouping 2 21
Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
Hi friends,  in this video  I'll show you how new windows 10 user can learn the using of windows 10. Thank you.

912 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

16 Experts available now in Live!

Get 1:1 Help Now