In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces "MySQL event Scheduler Event Scheduler is an example introduction". In daily operation, I believe many people have doubts about the introduction of MySQL event Scheduler Event Scheduler. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts of "MySQL event Scheduler Event Scheduler is an example introduction". Next, please follow the editor to study!
Event Scheduler is another new feature in MySQL 5.1. it can be used as a scheduled task scheduler to replace some of the timing functions that can only be done by using the operating system task scheduler. For example, crontabe in can only be executed once per minute, while MySQL's event Scheduler can execute one task per second, which is very practical in some real-time environments.
The event scheduler is timed to trigger execution, which can also be called a "temporary trigger" from this point of view. Triggers simply execute statements against events generated by a table, while the event scheduler executes statements at a certain (interval) time. Events are managed by a specific thread, known as the event Scheduler. With the event Scheduler enabled, the thread can be seen by an account with SUPER permission to execute SHOW PROCESSLIST. You can dynamically control whether the event scheduler is enabled by setting the value of the global variable event_scheduler.
(root:localhost:) test > SET GLOBAL event_scheduler = ON; (root:localhost:) test > show processlistG** 4. Row * * Id: 46147User: event_schedulerHost: localhostdb: NULLCommand: DaemonTime: 1State: Waiting on empty queueInfo: NULL
As mentioned above, the owner of the thread is event_scheduler.
Application case
In this case, using the characteristics of event scheduler, the stored procedure is called once per second to determine whether the SLAVE is running properly. If it is found that SLAVE is closed, ignore 0 errors, and then restart SLAVE.
First create a stored procedure
Delimiter / / create procedure `Slave_ Monitor` () beginSELECT VARIABLE_VALUE INTO @ SLAVE_STATUS FROM information_schema.GLOBAL_STATUS WHERE VARIABLE_NAME=SLAVE_RUNNING;IF (ON! = @ SLAVE_STATUS) THENSET GLOBAL SQL_SLAVE_SKIP_COUNTER=0;SLAVE START;END IF;end; / / delimiter
Because the statement like SHOW SLAVE STATUS cannot be called in the stored procedure, the exact copy error message and error code cannot be obtained, and the various cases of SLAVE stop can not be further handled.
Next, create the task
CREATE EVENT IF NOT EXISTS `Slave_ Monitor`
ON SCHEDULE EVERY 5 SECOND
ON COMPLETION PRESERVE
DO
CALL Slave_Monitor ()
A task is created and executed every 5 seconds, and after the task ends, the task is retained instead of deleted. Of course, the task in this example will not end unless it is manually disabled.
If you want to temporarily shut down a task while running, simply execute the ALTER EVENT statement:
(root:localhost:) test > alter event `Slave_ Monitor` ON
COMPLETION PRESERVE DISABLE
(root:localhost:) test > alter event `Slave_ Monitor` ON
COMPLETION PRESERVE ENABLE
At this point, the study of "MySQL event Scheduler Event Scheduler is an example introduction" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.