SitePoint Sponsor

User Tag List

Results 1 to 11 of 11

Thread: SQL - cron job

  1. #1
    SitePoint Member
    Join Date
    Jan 2012
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question 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

  2. #2
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,031
    Mentioned
    152 Post(s)
    Tagged
    2 Thread(s)
    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).
    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  3. #3
    SitePoint Member
    Join Date
    Jan 2012
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  4. #4
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,031
    Mentioned
    152 Post(s)
    Tagged
    2 Thread(s)
    I use putty. I think most people do
    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  5. #5
    SitePoint Member
    Join Date
    Jan 2012
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    nope i cannot get ssh connection to the server any other ideas on how to find the location of mysql's path??
    thanks
    Noel.

  6. #6
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,031
    Mentioned
    152 Post(s)
    Tagged
    2 Thread(s)
    Can you execute php from the browser and use for example the exec function?

    PHP Code:
    <?php
    exec
    ('which mysql'$output);
    var_dump($output);
    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  7. #7
    SitePoint Member
    Join Date
    Jan 2012
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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

    Quote Originally Posted by ScallioXTX View Post
    Can you execute php from the browser and use for example the exec function?

    PHP Code:
    <?php
    exec
    ('which mysql'$output);
    var_dump($output);

  8. #8
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,031
    Mentioned
    152 Post(s)
    Tagged
    2 Thread(s)
    I'm pretty sure it's

    Code:
    /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).
    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  9. #9
    SitePoint Member
    Join Date
    Jan 2012
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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
    other way??
    Thanks
    Noel

  10. #10
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,031
    Mentioned
    152 Post(s)
    Tagged
    2 Thread(s)
    Nope, you should really test cron jobs with cron
    Rémon - Hosting Advisor

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  11. #11
    SitePoint Member
    Join Date
    Jan 2012
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    lol looks like more reseach is needed thank you everyone that helped out


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •