Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to create an event in Mysql database

2025-04-05 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >

Share

Shulou(Shulou.com)05/31 Report--

How to create an event in Mysql database? for this question, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and easy way.

Brief introduction of event

Events (event) are procedural database objects that MySQL calls at the appropriate time. An event can be called once or started periodically, and it is managed by a specific thread, which is called the event Scheduler.

Events, like triggers, are started when something happens. When a statement is started on the database, the trigger starts, and the event starts based on the scheduled event. Because they are similar to each other, events are also called temporary triggers.

Events replace work that can only be performed by the scheduled tasks of the operating system, and MySQL's event Scheduler can be accurate to execute one task per second, while the scheduled tasks of the operating system (such as CRON under Linux or task scheduling under Windows) can only be executed once per minute.

Advantages and disadvantages of events

Advantages: some data timed operations no longer rely on external programs, but directly use the functions provided by the database itself.

It can execute one task per second, which is very practical in some environments with high real-time requirements.

Disadvantages: timing trigger, can not be called.

Create an event

A create event statement creates an event. Each event consists of two main parts, the first part is the event event schedule, which indicates when and how often the event starts, and the second part is the event action (event action), which is the code executed when the event is started. The action of the event contains a SQL statement, which may be a simple insert or update statement, or a stored procedure or benin...end statement block. These two situations allow us to perform multiple SQL.

An event can be active (open) or stopped (closed), which means that the event scheduler checks whether the event action must be called, and stopping means that the declaration of the event is stored in the directory, but the scheduler does not check whether it should be called. Immediately after an event is created, it becomes active, and an active event can be executed one or more times.

Open event

Before using the event feature, first make sure that your mysql version is above 5.1, and then check to see if the event on your mysql server is turned on.

To see if the event is enabled, use the following command to view it:

SHOW VARIABLES LIKE 'event_scheduler'

Modify SET GLOBAL event_scheduler = ON through dynamic parameters

After changing this parameter, it will take effect immediately.

Note: you still need to add event_scheduler=ON to my.ini. Because if it is not added, the mysql restart event will return to its original state.

This is the answer to the question about how to create an event in the Mysql database. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel for more related knowledge.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Database

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report