noel_the_silent — 2012-01-04T17:43:15-05:00 — #1
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
scallioxtx — 2012-01-04T17:58:54-05:00 — #2
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).
noel_the_silent — 2012-01-04T18:18:45-05:00 — #3
great thanks for the quick reply can you recomend a command line software to be use on win7 to connect to my linx hosting
scallioxtx — 2012-01-04T18:21:41-05:00 — #4
I use putty. I think most people do
noel_the_silent — 2012-01-04T18:31:18-05:00 — #5
nope i cannot get ssh connection to the server any other ideas on how to find the location of mysql's path??
scallioxtx — 2012-01-04T18:45:12-05:00 — #6
Can you execute php from the browser and use for example the exec function?
exec('which mysql', $output);
noel_the_silent — 2012-01-04T19:05:54-05:00 — #7
Thank you that worked well now i just have to get my syntx right lol for the cron job
usr/bin/mysql -u db_user -ppass /home/dump.sql >/dev/null 2>&1
scallioxtx — 2012-01-04T19:13:22-05:00 — #8
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).
noel_the_silent — 2012-01-04T19:27:42-05:00 — #9
lol this is going to test the crap out of me
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
scallioxtx — 2012-01-04T19:40:05-05:00 — #10
Nope, you should really test cron jobs with cron
noel_the_silent — 2012-01-04T19:53:48-05:00 — #11
lol looks like more reseach is needed thank you everyone that helped out