MySQL stored procedures and timed calls

Source: Internet
Author: User

1. Create a stored procedure

1 Create procedure Proc_name () 2 begin 3 SQL; 4 End

SQL executes the code at a fixed value, for example, inserting the current time into the table: INSERT INTO Table VALUES (now ()), and then execute the stored procedure periodically with event dispatch.

2. Create a Trigger Event

1 Create if  not exists Event_Name 2  on  - Second 3  on Completion Preserve 4 Do-Call Proc_name ()

Creates an event dispatch that executes the call to the stored procedure once every 30 seconds after the event dispatch completes. If you only want the stored procedure to execute only once at a time, change the preserve to not preserve.

3. Check if event is turned on

1  like ' %sche% '

4. Open the event plan

1 set global Event_scheduler=1;

Global event Dispatch switch, 1 is on, 0 is off.

5. Turn on event tasks

1 Alter  on completion preserve enable;

Opens the specified event dispatch switch

6. Close Event Task

1 Alter  on completion preserve disable;

Turn off the specified event dispatch switch

7. View all stored procedures in the database

1 SELECT *  from MySQL. proc

View all stored procedures of the database, after MySQL installation, there is a database called MySQL by default, there is a table called Proc, by looking at this table can also query the database of all stored procedures.

8. View all stored procedures + content in the database

1 procedure Status;

9. View the creation code of a stored procedure or function

1 Create procedure You_proc_name;

10. Delete stored Procedures

1 Drop procedure Proc_name;

MySQL stored procedures and timed calls

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.