Is it possible to run a sql query when azure VM starts? - mysql

Every day after turning on azure VM I'm executing one SQL query.
ie,
SET GLOBAL sql_mode=(SELECT REPLACE(##sql_mode,'ONLY_FULL_GROUP_BY',''));
and also I have to restart my ngnix service after running this query.
I'm planning to do this using a bash script and will schedule a run for the same bash script using a cronjob.
Is there any other way to do this?

Yes, you can try it with the bash script, that is the best option.
Apart from that, as mentioned by #Anand in comment section, you can try to make Automatically Running Stored Procedures at SQL Server Startup.
Refer this third party tutorial for the same.

Related

Does crontab leave mysql connections open?

When I run report jobs (get net sales data from mysql) in crontab (bashscript) , I establish a connection to mysql and get the required data.
Does this leave mysql connections open or all the connections are closed on job completion?
UPDATE - I use bash script to connect to mysql.
In basic scenarios the MySQL connections will be closed when the mysql client within the bash script finishes running.
If you are running the mysql command line Linux client within your bash script then bash would normally wait for the mysql process to exit before continuing to the end of the script.
There are ways to persist processes beyond the life of the bash script but you haven't mentioned using those in your question.
If you are using a mysql library that has a close function - most of the MySQL libraries have this in the api then you should use it. Although the default process behaviour will probably clean up open connections for you, it helps to get in the habit of closing resources that you are not going to require again within your code as this makes it more scalable and also informs other developers of your intended behaviour.

Schedule periodic mysql script to run automatically every hour

I've been searching, but nothing clear came up.
I wonder if there is a way to schedule a big MYSQL script which takes normally up to 2 minutes to run (with workbench not able to run in phpmyadmin cause of timeout -> server not in my hands) so that it would automatically run every hour?
First, just to clarify, MySQL Workbench is a native application. It cannot run in PMA or any other web application.
MySQL Workbench itself (or MySQL for that matter) does not have a scheduler or something like that. You can however use your OS' means. E.g. use AT or crontab to run MySQL Workbench and pass it the script to execute. Run MySQL Workbench from the commandline with the -h (or --h on non-Win) switch to get a list of possible parameters.

How to execute mysql scripts in cloudfoundry

I have a .sql file (initial sql scripts). I have recently deployed application in cloudfoundry, So I want to run these scripts to make application work, Scripts will update more than 5 db tables.
Is there any other way to run the mysql scripts from the grails application on start up Or Is there any provision to run the scripts in the cloudfoundry.
you have several options here.
The first one (which I recommend), is to use something like http://liquibase.org/ (there is a Grails plugin for it: http://grails.org/plugin/liquibase). This tool will make sure that any script you give it will run prior to the app starting, without running the same script twice, etc. This is great to keep track of your database changes.
This works independently of CloudFoundry and would help anyone installing your app having an up to date schema
The second option would be to tunnel to the CloudFoundry database and run the script to the db. Have a look at http://docs.cloudfoundry.com/tools/vmc/caldecott.html or even easier with STS : http://blog.cloudfoundry.com/2012/07/31/cloud-foundry-integration-for-eclipse-now-supports-tunneling-to-services/
Yup, what ebottard said! :-) Although, personally I would opt for using the tunnel feature on VMC, but that said, I am a Ruby guy!
Be weary of the fact that there are timeouts against queries in MySQL if are bootstrapping your database with large datasets!

Getting SQL agent in mysql

I am coming from a SQL server 2008 background. I have a mysql local server running, and I wanted to set up some scheduled jobs via the sql agent. I have found some sketchy third party sql agents for mysql but none built in. Is there a sql agent or a recommended one for mysql? Thank you.
Usual approach is to set up a cron job to run a script. I used to use Perl for the scripts, but bash etc will do it as well.

Log warnings into a table

I found the following code on mysql forge site.
MySQL Proxy : An easy way to log all warnings and errors into a MySQL table.
http://forge.mysql.com/tools/tool.php?id=133
This may sound too basic, but from where do I start if I need this functionality.
Here you have more details about MySQL proxy scripting.
What you need to do with the script you linked is just run it on MySQL database and it will do all the magic for you. It's a complete server side solution so you don't have to worry about logging errors in your client application. MySQL will automatically run read_query function for every row returned and read_query_result for every set returned.