简体   繁体   English

每5分钟自动执行SQL中的语句

[英]Automate Statement IN SQL Every 5 Minutes

I'm trying to automate a Load Data Infile command in MariaDB/SQL (they are the same?) every 5 minutes. 我试图每5分钟自动执行一次MariaDB / SQL中的“加载数据文件”命令(它们是相同的吗?)。 This is the block of code i'm trying to automate. 这是我要自动执行的代码块。

LOAD DATA LOCAL INFILE 'path to text file'
INTO TABLE Student
FIELDS TERMINATED BY ',';

I've tried some of the simpler solutions already but to no avail. 我已经尝试了一些更简单的解决方案,但无济于事。 I was thinking of creating a script and using the built in system scheduler but I'm on linux and not to familiar and would very much prefer a way to do this within MYSQL. 我当时正在考虑创建脚本并使用内置的系统调度程序,但是我在Linux上并不熟悉,因此非常希望在MYSQL中执行此操作。 Thank you for the help! 感谢您的帮助!

I believe MariaDB should include MySQL's event scheduler - you can find more details on use of it here: http://www.mysqltutorial.org/mysql-triggers/working-mysql-scheduled-event/ 我相信MariaDB应该包含MySQL的事件调度程序-您可以在此处找到有关它的更多使用信息: http : //www.mysqltutorial.org/mysql-triggers/working-mysql-scheduled-event/

I'd suggest putting that code in a stored procedure and using that to fire the process: 我建议将该代码放入存储过程中,并使用它来触发该过程:

CREATE PROCEDURE stored_proc_name ()
BEGIN
    LOAD DATA LOCAL INFILE 'path to text file'
    INTO TABLE Student
    FIELDS TERMINATED BY ',';
END

Then create the event: 然后创建事件:

CREATE EVENT event_name
ON SCHEDULE EVERY 5 MINUTE
DO
    EXEC stored_proc_name

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM