SQL - cron job

Hi folks,
This is my first posting I am having troble with the cron sytex for running a MySQL script linx hosting this is what I have which is not working
mysql -u db_user -p pass /home/sql_script.sql >/dev/null 2>&1
if you can help that would be great and if you can explain how your solution works that would be exellent
thank you
noel

Most problems with cron jobs stem from the difference in environment between you as user in the shell and the environment the cron job is running in. More specifically, when you’re logged in the system knows what you mean when you say ‘mysql’, but when cron runs the job it doesn’t, because there’s a different path in cron’s environment that doesn’t contain the path the ‘mysql’ binary is in.

The easiest solution is to supply the full path to the mysql binary, which you can find either through whereis mysql or which mysql (on the command line).

Also, I’m pretty sure you should not type a space between -p and your password, i.e., it should be -pmypassword instead of -p mypassword (the -u myusername is fine though, in case you’re wondering).

great thanks for the quick reply can you recomend a command line software to be use on win7 to connect to my linx hosting
thank you
Noe.

I use putty. I think most people do :slight_smile:

nope i cannot get ssh connection to the server any other ideas on how to find the location of mysql’s path??
thanks
Noel.

Can you execute php from the browser and use for example the exec function?


<?php
exec('which mysql', $output);
var_dump($output);

Thank you that worked well now i just have to get my syntx right lol for the cron job :slight_smile:
usr/bin/mysql -u db_user -ppass /home/dump.sql >/dev/null 2>&1

I’m pretty sure it’s


/usr/bin/mysql -u db_user -ppass < /home/dump.sql >/dev/null 2>&1

i.e. start with a / and add the < just after -ppass

I’m not sure about the < though, you may want to test with and without

(just schedule a few minutes ahead, wait a few minutes, and see if it worked, don’t schedule for the actual time which may be hours ahead. Once you find the command that works schedule it like it’s supposed to).

lol this is going to test the crap out of me :slight_smile:
I tried with and without < no go I am trying to reset my database
for a demo site I am making can you run this type of script any
other way??
Thanks
Noel

Nope, you should really test cron jobs with cron :slight_smile:

lol looks like more reseach is needed thank you everyone that helped out :slight_smile: