Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running a stored procedure from crontab

Tags:

linux

mysql

cron

I have the layout:

Mysql DB
DB name: db_name
DB User name: user_name
Password: 12345
Stored procedure: my_stored_procedure

How can I execute "my_stored_procedure" daily from a crontab?

like image 904
Ran Avatar asked Nov 23 '25 12:11

Ran


2 Answers

Try to run something like this

mysql -h 'your ipadress' -u user_name –p'12345' mydatabase -e 'CALL my_stored_procedure()'

Just a guess i dont know if it will work.

like image 103
Michael Koper Avatar answered Nov 28 '25 15:11

Michael Koper


I think better to use Events from mysql.

For more information please visit Using the Event Scheduler

Or use solution suggested by Michael.
Personally I like to execut mysql using -ss and socket file:

mysql -S/path_to_sock_file/mysql.sock -u user_name –p'12345' mydatabase -ss  -e 'CALL my_stored_procedure()'

-ss returns results as a plain text.

Cheers Arman.

like image 40
Arman Avatar answered Nov 28 '25 16:11

Arman



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!