Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

MySQL Stored Procedure

Posted on 2014-01-17
6
Medium Priority
?
422 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 
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 2000 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

Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

Question has a verified solution.

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

Creating and Managing Databases with phpMyAdmin in cPanel.
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.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

722 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