Detailed explanation of how to create MySql scheduled tasks in navicat

Detailed explanation of how to create MySql scheduled tasks in navicat

Detailed explanation of creating MySql scheduled tasks with navicat

An event is a procedural database object that MySQL calls at a specific time. An event can be called once or started periodically. It is managed by a specific thread, the so-called "event scheduler". Events are similar to triggers in that they are triggered when something happens. A trigger is fired when a statement is started on the database, whereas an event is fired based on a scheduled event. Because of their similarity to each other, events are also called temporary triggers. Events replace the work that could previously only be performed by the operating system's scheduled tasks, and MySQL's event scheduler can accurately execute one task per second, while the operating system's scheduled tasks (such as CRON under Linux or task scheduling under Windows) can only be executed once a minute.

1. Start a scheduled task

1. Scheduled tasks are closed by default, and when the Value is ON, they are turned on;

SHOW VARIABLES LIKE '%event_sche%';

insert image description here

2. Start a scheduled task

SET GLOBAL event_scheduler = 1;

3. Turn off scheduled tasks

SET GLOBAL event_scheduler = 0;

If you need to run a scheduled task for a long time, you need to configure event_scheduler = on in my.ini

2. Create a scheduled task through navicat

1. Find事件and create a new event

insert image description here

2. The definition is to fill in the SQL or event or stored procedure that needs to be run.
3. The plan is the operating rules of this scheduled task.
There are two types of events in the plan, AT and EVERY. EVERY is also called the "event scheduler". An event can be called once or started periodically. It is managed by a specific thread.

insert image description here

The setting here is to execute once every day starting from 2020-08-06 12:00:00.
Click Preview SQL to view the creation of scheduled tasks.

insert image description here

4. Here are many examples for you to understand this setting.

1. Execute an update CREATE EVENT myevent one hour after the event myevent is created
  ON SCHEDULE AT CURRENT_TIMESTAMP + INTERVAL 1 HOUR
DO
 UPDATE myschema.mytable SET mycol = mycol + 1;

2. Clear the test table at 12:00 on March 20, 2014:

CREATE EVENT e_test
  ON SCHEDULE AT TIMESTAMP '2014-03-20 12:00:00'
  DO TRUNCATE TABLE test.aaa;

3.5 days later, start clearing the test table every day:

CREATE EVENT e_test
  ON SCHEDULE EVERY 1 DAY
  STARTS CURRENT_TIMESTAMP + INTERVAL 5 DAY
  DO TRUNCATE TABLE test.aaa;

4. Clear the test table regularly every day and stop executing CREATE EVENT e_test after 5 days
  ON SCHEDULE EVERY 1 DAY
  ENDS CURRENT_TIMESTAMP + INTERVAL 5 DAY
  DO TRUNCATE TABLE test.aaa;

5. After 5 days, start clearing the test table every day, and stop after one month:

CREATE EVENT e_test
  ON SCHEDULE EVERY 1 DAY
  STARTS CURRENT_TIMESTAMP + INTERVAL 5 DAY
  ENDS CURRENT_TIMESTAMP + INTERVAL 1 MONTH
  DO TRUNCATE TABLE test.aaa;

6. Clear the test table regularly every day (only execute once, and terminate the event after the task is completed):

CREATE EVENT e_test
  ON SCHEDULE EVERY 1 DAY
  ON COMPLETION NOT PRESERVE
  DO TRUNCATE TABLE test.aaa;

[ON COMPLETION [NOT] PRESERVE] can set this event to be executed once or persistently. The default is NOT PRESERVE.

3. Close, start, alias, move, delete event

Modify the scheduled task ALTER. The only difference between modifying and creating is that the first word of creation is CREATE, which is changed to ALTER.

ALTER EVENT myevent 
... Specific changes

Temporarily close an event

ALTER EVENT myevent DISABLE;

Start an event

ALTER EVENT myevent ENABLE;

Alias ​​an event

ALTER EVENT olddb.myevent
RENAME TO newdb.myevent;

Move myevent from olddb to newdb

ALTER EVENT olddb.myevent
RENAME TO newdb.myevent;

Deleting an event

DROP EVENT [IF EXISTS] event_name

4. Query Event Information

Event information related table

information_schema.events
mysql.event

View the creation information of the event

show create event countsum \G

View the events information of the sem library

USE sem;
SHOW EVENTS \G

This is the end of this article about the detailed explanation of how to create MySql scheduled tasks with Navicat. For more information about how to create MySql scheduled tasks with Navicat, please search for previous articles on 123WORDPRESS.COM or continue to browse the following related articles. I hope you will support 123WORDPRESS.COM in the future!

You may also be interested in:
  • Solve the problem that Navicat cannot connect to the MySQL server in the Centos system in VMware
  • Perfect solution to the problem that Navicat cannot connect after installing mysql in docker
  • About the problem of Navicat connecting to MySql database slowly
  • Navicat for MySQL 15 Registration and Activation Detailed Tutorial
  • How to remotely connect to MySQL database with Navicat Premium
  • Solve the problem of error 10038 when connecting to MySQL remotely in Navicat
  • Navicat for MySQL 11 Registration Code\Activation Code Summary
  • Detailed explanation of Navicat's slow remote connection to MySQL
  • Navicat Premium operates MySQL database (executes sql statements)
  • Common errors and solutions for connecting Navicat to virtual machine MySQL
  • When Navicat Premium connects to the database, the error message appears: 2003 Can't connect to MySQL server on''localhost''(10061)
  • Solution to the problem that Navicat cannot remotely connect to MySql server
  • How to use Navicat to operate MySQL

<<:  Summary of common commands for Ubuntu servers

>>:  An article teaches you how to implement a recipe system with React

Recommend

Access the MySQL database by entering the DOS window through cmd under Windows

1. Press win + R and type cmd to enter the DOS wi...

Design Theory: A Method to Understand People's Hearts

<br />Once, Foyin and Mr. Dongpo were chatti...

Summary of the differences between Vue's watch, computed, and methods

Table of contents 1 Introduction 2 Basic usage 2....

How to create an Nginx server with Docker

Operating environment: MAC Docker version: Docker...

Zabbix configures DingTalk's alarm function with pictures

Implementation ideas: First of all, the alarm inf...

JavaScript source code for Elimination

JavaScript to achieve the source code download ad...

Detailed steps to build a file server in Windows Server 2012

The file server is one of the most commonly used ...

JavaScript to achieve simple drag effect

This article shares the specific code of JavaScri...

A simple example of how to implement fuzzy query in Vue

Preface The so-called fuzzy query is to provide q...

Summary of Linux sftp command usage

sftp is the abbreviation of Secure File Transfer ...