MySQL: How can I run (and schedule) queries to my remote MySQL databases on Mac OS X?
-
I run many websites that need daily (some hourly) queries run on them. To date, we've used NaviCat running on WinXP with Windows built-in scheduling utility running the query. However, I want to move this task over to a Mac and take down the XP machine entirely. I thought of just using NaviCat on Mac, BUT (and it's a big but) I would have to recreate all the sites (30+), their log-in credentials, and the queries (for each site) because NaviCat for MySQL doesn't have a cross-platform export/import feature for configured sites. Plus, if I ever have to reformat the Mac or to switch to a new machine, I'll have to rebuild all the sites and queries again. I'm hoping for a command line solution or script that I can just run directly on the Mac. If that's not an option, how about an app that DOES include site and query export and import--preferably cross-platform, but I'll settle just for a Mac-app with that capability. Any advice? Thanks.
-
Answer:
Probably one of the simplest is to wrap your logic in a PHP file, and then use cron to run the php from the command line. your script.php file would sit, say, in your user folder root <?php $username = "your_name"; $password = "your_password"; $hostname = "123.456.789.123"; //port 3306 should be open on remote IP //connection to the database $dbhandle = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL"); $selected = mysql_select_db("mytable",$dbhandle) or die("Could not select examples"); $result = mysql_query("update mytable set lastupdated='".date()."' where rowid=1"); ?> and then edit: crontab -e and put in: EMAIL="" 0 * * * * php script.php This would run the script at the top of every hour, for example. (Email="" just keeps it from emailing you every time the script runs) In this case you're just running php directly, not involving the web server, but it just connects and does whatever. And if you need to move the script to anywhere else, you can do that (another Mac, or Linux machine, or whatever)
Kris Thom White at Quora Visit the source
Other answers
Cron makes this trivial, remembering that the mysql client has a -e option to specify a query as a parameter, so queries can be run from the shell as one-liners; or simply redirect your query from a file. man crontab & man 5 crontab for the details
Toby Thain
Related Q & A:
- How can I auto run ccleaner on Mac OS X?Best solution by forum.piriform.com
- How can I mount a network drive in Mac OS X in Java?Best solution by Stack Overflow
- How can I run all my selenium tests sequentially in C#?Best solution by Stack Overflow
- How can I run CMD command?Best solution by Super User
- How can I run faster?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.