Yevgeny Simkin
Yevgeny Simkin

Reputation: 28389

Is it possible to schedule cron tasks in mysql?

I'm curious if there's a mysql built-in mechanism for scheduling queries to run at given intervals or if I'm stuck having to use (tried and true) cron for this? If I AM stuck, what's the command for having the command line execute the contents of a sql file? as in...

//created file containing some sql query and put it in the file system
//cd over to that folder...
>mysql -u username -p'password' myDB ... now what?

but if there IS a way... where is it documented, I'm not seeing anything at the mysql doc site. Specifically, I need something to run every night at midnight.

TIA

Upvotes: 0

Views: 310

Answers (3)

Sandeep Nair
Sandeep Nair

Reputation: 3660

Are you looking for event schedulers in mysql. If yes please look at the following link http://dev.mysql.com/doc/refman/5.1/en/events.html

Upvotes: 3

Sergii Kudriavtsev
Sergii Kudriavtsev

Reputation: 10532

You can run arbitrary batch file with commands using syntax

mysql < batch-file

Some information on how to do this and more elaborate syntax is available here: MySQL Reference Manual: Using mysql in Batch Mode

Upvotes: 1

Tarandeep Gill
Tarandeep Gill

Reputation: 1534

I dont know about inbuilt, but if you end up using cron, this is the command:

>mysql -u username -p'password' myDB < filename.sql

Upvotes: 1

Related Questions