I'm looking for a way to run a MySQL procedure at database startup. I can only see sql triggers for MySQL. No database and user event triggers Are there other ways of doing this please? Thanks
Asked
Active
Viewed 32 times
1
1 Answers
0
Basically you are right when you say that triggers cannot do that. However, it is possible to achieve this via other means.
For instance you could have a program or a script that would check whether MySQL is already running. In Ubuntu that would be
sudo service mysql status
If MySQL is not active, then start it and execute the script. In Ubuntu it would look like this
sudo service mysql start && yourpassword | mysql -u youruser -p -e "yourcode"
where yourcode
would be the procedure call. Now, you need to make sure that:
- this is a cron job and runs periodically
- MySQL is not started automatically by your OS, to make sure that if it's a reboot, then your stored procedure is being executed
- the script is safe and can only be reached by a superuser because of its awareness of your MySQL password

Lajos Arpad
- 64,414
- 37
- 100
- 175