MySQL-run on a daily basis, MySQL-run

Source: Internet
Author: User

MySQL-run on a daily basis, MySQL-run

Design the script executed at a specified point every day during the recent project, so Mark it here to facilitate searching

 

Set time_zone = '+ 8:00 ';
Set GLOBAL event_scheduler = 1;

-- Set the database base database to which the event is used or belongs
Use nitrogenates;

# Delete a task scheduler with the same name first
Drop event if exists upload_to_sdmp;

# Set the separator to '$' and mysql's default statement separator to ';'. In this way, the code from create to end will be executed as a statement.
DELIMITER $
# Create a scheduled task, set the first execution time to '2017-07-30 10:00:00 ', and run the task once a day
Create event upload_to_sdmp
On schedule every 1 day starts timestamp '2017-01-17 07:16:00'
# On schedule every 1 SECOND
Do

# What to do to start the scheduled task
Begin


-- Do something: compile your scheduled tasks
# INSERT test_group (name, project_id) VALUES ("haha", 1 );


# Obtain the last executed Case_ALL and copy it to the new ID
# Change the time to the current time
# Change the ID of the last executed Case to a new ID.
Insert into execution (name, project_id, test_suite_id) select name, project_id, test_suite_id from execution WHERE test_suite_id = 3 order by created_time desc limit 1;
UPDATE execution SET created_time = (select CURRENT_TIMESTAMP) WHERE created_time = "0000-00-00 00:00:00 ";
# UPDATE queue_entry SET execution_id = (SELECT id FROM execution order by id desc limit 1) WHERE execution_id = (select id from execution WHERE test_suite_id = 3 order by created_time desc limit 1, 1 );
Insert into queue_entry (test_case_id, project_id) select test_case_id, project_id from queue_entry WHERE execution_id = (select id from execution WHERE test_suite_id = 3 order by created_time desc limit 1, 1 );
UPDATE queue_entry SET execution_id = (SELECT id FROM execution order by id desc limit 1) WHERE execution_id = 0;


# Obtain the second to last
# Select id from execution WHERE test_suite_id = 3 order by created_time desc limit 1, 1;
# Latest ID
# SELECT id FROM execution order by id desc limit 1;

-- End a scheduled task
End $

# Set the statement delimiter back ';'
DELIMITER;

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.