In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Database >
Share
Shulou(Shulou.com)05/31 Report--
Editor to share with you a case of Mysql timing tasks under Linux, I believe most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!
Assume that stored procedures are executed regularly every 10 minutes from 10:00 to 5 a.m.
Implementation method:
The first is to use Mysql itself to make event scheduled tasks, which can be done with the help of Navicat For Mysql or other database development tools.
The second way is to use the timed task of linux, which is realized by using the task management tool of Linux system.
1. Commands related to event scheduled tasks in Mysql
1. Check to see if event is enabled:
SELECT @ @ event_scheduler; or SHOW VARIABLES LIKE 'event%'
two。 Start a timing task:
Set GLOBAL event_scheduler = 1; or SET GLOBAL event_scheduler = ON
3. Set up scheduled tasks:
DROP EVENT IF EXISTS JOB_ALARM;CREATE EVENT JOB_ALARM ON SCHEDULE EVERY 10 MINUTEDO BEGIN if (date_format (current_time (),'% H') > 22 | | date_format (current_time (),'% H') UNIX_TIMESTAMP ()-60 * 60 * 24) tmp INNER JOIN EVENTS t ON tmp.USER_ID = t.USER_ID AND tmp.TIME_GMT = t.TIME_GMT WHERE TYPE_ID! = '34001' # set a termination tag DECLARE CONTINUE HANDLER FOR SQLSTATE '02000' SET s = 1; OPEN cursor_data; # gets the record of the current pointer of the cursor, reads a row of data and passes it to the variable AGI b FETCH cursor_data INTO userId # start a loop to determine whether the cursor has reached the last condition WHILE s 1 DO INSERT INTO EVENTS_NOTIFICATION VALUES (NULL, SYSDATE (), UNIX_TIMESTAMP (SYSDATE ()), UNIX_TIMESTAMP (SYSDATE ()), '00000, userId,' 1percent,'0'); # read the data FETCH cursor_data INTO userId; END WHILE of the next line # close cursor CLOSE cursor_data; END
Second, using the scheduled tasks of linux
Basic commands for linux scheduled tasks:
View scheduled tasks: crontab-l
Edit scheduled tasks: crontab-e
* / 10 22-23 use db_name;CALL PRO_ALARM 0-5 * mysql-u user name-p password-e "use db_name;CALL PRO_ALARM ();"
Or save use db_name;CALL PRO_ALARM (); in the sql script, and edit the scheduled tasks as follows:
* / 10 22-23 0-5 * mysql-u username-p password < / application/Job_mysql.sql
These are all the contents of this article entitled "the case of realizing Mysql scheduled tasks under Linux". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!
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.