Running a stored procedure from crontab

只谈情不闲聊 提交于 2019-12-10 10:12:50

问题


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?


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/5377059/running-a-stored-procedure-from-crontab

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!