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
Solved

MySQL Stored Procedure

Posted on 2014-01-17
6
418 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
Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

 
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

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

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

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). …
All XML, All the Time; More Fun MySQL Tidbits – Dynamically Generate XML via Stored Procedure in MySQL Extensible Markup Language (XML) and database systems, a marriage we are seeing more and more of.  So the topics of parsing and manipulating XM…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

809 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