mysql-timed call to stored procedure

Source: Internet
Author: User

MySQL periodically calls the stored procedure to back up the table data set table structure

Stored Procedure instance:

CREATE PROCEDURE backupsms () begindeclare tname varchar (+), set @tname = CONCAT (' Sms_accpet ', Date_format (now (), '%y%m ') Set @rname = CONCAT (' CREATE table ', @tname, ' select * from Sms_accpet '); PREPARE create_table from @rname; EXECUTE Create_table;delete from Sms_accpet;

Timer instances

CREATE EVENT event_sms on    SCHEDULE every 1 MONTH starts Date_add (Date_add (Date_sub (curdate), INTERVAL Day (Curdate () )-1 day), INTERVAL 1 MONTH), INTERVAL 1 HOUR) on  completion PRESERVE ENABLE does call  backupsms ();

Reference website:

Stored procedures:

http://blog.csdn.net/youngqj/article/details/6936632
http://blog.csdn.net/sun886/article/details/7992935

Timer:

Http://www.cnblogs.com/gaizai/archive/2012/12/24/2831315.html

http://lobert.iteye.com/blog/1953827


1. Copy table structure and data to new table CREATE table new Table select * from old table 2. Only copy table structure to new table CREATE table new Table select * from old table where 1=2 is: let the Where condition not be established. Method two: (Low version of Mys QL not supported, mysql4.0.25 not supported, MYSQL5 already supported) CREATE table new table like old table 3. Copy data from old table to new table (assuming two table structure) INSERT into new table select * FROM Old table 4. Copy the data from the old table to the new table (assuming two table structures are different) INSERT into new table (Field 1, Field 2,.......) SELECT field 1, Field 2,...... From old table

Sample Lottery

Create event Event_call_defer on schedule every daily three o'clock in the morning 1 day starts Date_add (date (curdate () + 1), Interval 3 hour)  On completion preserve enable does begin call Test.warn (); End every month 1 o'clock in the morning execute CREATE EVENT EVENT2 on SCHEDULE Every 1 month starts Date_add (Date_add (Date_sub (), curdate   L Day (Curdate ()) – 1 day), INTERVAL 1 MONTH), INTERVAL 1 HOUR) on completion PRESERVE ENABLE does BEGIN call STAT (); END every quarter of 2 o'clock in the morning executes the CREATE EVENT total_season_event on SCHEDULE every 1 QUARTER starts Date_add (Date_add (DATE (CONCA T (Year (Curdate ()), '-', ELT (QUARTER (Curdate ()), 1,4,7,10), '-', 1)], INTERVAL 1 QUARTER), INTERVAL 2 HOUR) on completion   PRESERVE ENABLE do BEGIN call Season_stat (); END every January 1 four o'clock in the morning execute CREATE EVENT total_year_event on SCHEDULE Every 1 year starts Date_add (DATE (CONCAT ()   ) + 1, '-', 1, '-', 1 '), INTERVAL 4 HOUR) on completion PRESERVE ENABLE does BEGIN call Year_stat (); END




mysql-timed call to stored procedure

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.