Mysql-timed call of stored procedures, mysql-stored procedures

Source: Internet
Author: User

Mysql-timed call of stored procedures, mysql-stored procedures

Mysql regularly calls the stored procedure to back up the table structure.

Stored Procedure instance:

CREATE PROCEDURE backUpSms()BEGINDECLARE tname varchar(64);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 instance

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  DO CALL backUpSms();

Reference website:

Stored Procedure:

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 the TABLE structure and data to the new table create table new table select * FROM old TABLE 2. only copy the TABLE structure to the new table create table new table select * FROM old table where 1 = 2 that is: Make the WHERE condition not true. method 2: (mysql of earlier versions is not supported, mysql 4.0.25 is not supported, and mysql 5 is supported) create table new table like old TABLE 3. copy the data FROM the old table to the new table (assuming the two tables have the same structure) insert into the new table SELECT * FROM the old table 4. copy the data from the old table to the new table (assuming the two tables have different structures) insert into the new table (Field 1, Field 2 ,.......) SELECT Field 1, Field 2 ,...... FROM old table

Sample extraction

Execute create event event_call_defer on schedule every 1 day starts date_add (date (curdate () + 1), interval 3 hour) on completion preserve enable do begin call test every three o'clock. warn (); end: Execute create event EVENT2 on schedule every 1 month starts DATE_ADD (DATE_SUB (CURDATE (), interval day (CURDATE () at each MONTH ()) -1 DAY), INTERVAL 1 MONTH), INTERVAL 1 HOUR) on completion preserve enable do begin call stat (); END execute create event TOTAL_SEASON_EVENT on schedule every 1 quarter starts DATE_ADD (DATE (CONCAT (YEAR (CURDATE ()),'-', ELT (QUARTER (CURDATE (),), '-', 1), INTERVAL 1 QUARTER), INTERVAL 2 HOUR) on completion preserve enable do begin call SEASON_STAT (); END execute create event TOTAL_YEAR_EVENT on schedule every 1 year starts DATE_ADD (DATE (CONCAT (YEAR (CURDATE () at ON January 1, January 1 EVERY YEAR ()) + 1, '-', 1, '-', 1), INTERVAL 4 HOUR) on completion preserve enable do begin call YEAR_STAT (); END




Related Article

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.