The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Cron Job unable to access MySQL Database when host is set to localhost

Discussion in 'General Discussion' started by leland, Jul 2, 2013.

  1. leland

    leland Member

    Joined:
    Jan 7, 2011
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    1
    I have some cron jobs that suddenly stopped a few days ago. I traced it back to the host setting when connecting to the database. When I use localhost, the script fails giving me this error: 'Error establishing mySQL database connection. Correct user/password? Correct hostname? Database server running?'. When I use the server's IP address or 127.0.0.1, the script works as it should.

    Also, this only seems to be happening to one account and if I were to access the script through a browser and the host is set to 'localhost' the script works fine.

    What could cause localhost to not work only for crons and for only one account?

    Running:
    CENTOS 6.3 x86_64 standard
    WHM 11.38.0 (build 19)
     
  2. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,678
    Likes Received:
    648
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    Hello :)

    Do you have your MySQL data directory or one of it's parent directories on a separate mount? If so, you may need to utilize the "/var/cpanel/jailshell-additional-mounts" file as documented here:

    Create Custom Jail Shell Mounts

    Thank you.
     
  3. quietFinn

    quietFinn Well-Known Member

    Joined:
    Feb 4, 2006
    Messages:
    998
    Likes Received:
    10
    Trophy Points:
    18
    Location:
    Finland
    cPanel Access Level:
    Root Administrator
    I had similar problems in one server, when mySQL datadir was moved, and then /var/lib/mysql was symliked to the new dir.
     
  4. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,678
    Likes Received:
    648
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    Try creating the "/var/cpanel/jailshell-additional-mounts" file and editing the file to include the path for the custom mount.

    Thank you.
     
  5. quietFinn

    quietFinn Well-Known Member

    Joined:
    Feb 4, 2006
    Messages:
    998
    Likes Received:
    10
    Trophy Points:
    18
    Location:
    Finland
    cPanel Access Level:
    Root Administrator
    Thanks but I already fixed it by removing the symlink and adding datadir in /etc/my.cnf

    Will try that next time.
     
    #5 quietFinn, Jul 4, 2013
    Last edited: Jul 4, 2013
  6. leland

    leland Member

    Joined:
    Jan 7, 2011
    Messages:
    8
    Likes Received:
    0
    Trophy Points:
    1
    Ya, I did move the database to a different mount. I will try it our. Thank you for the suggestion.
     
  7. patchwork

    patchwork Well-Known Member

    Joined:
    Nov 2, 2001
    Messages:
    92
    Likes Received:
    0
    Trophy Points:
    16
    I've got a lot of crons running in each account, I've just added a new job and all of a sudden all the crons for that account have suddenly all stopped working and giving the mysql connection problem.

    MYSQL is on a separate drive and has been for a long time, why would adding a new cronjob all of a sudden cause all the crons in that account to start failing?

    The crons in other accounts are still fine.

    - - - Updated - - -

    I've created /var/cpanel/jailshell-additional-mounts and added the mysql data directory path to it, and it seems to have fixed it.

    This seems like its a bug in cpanel that should be checked and fixed by upcp
     
  8. ksaied

    ksaied Member

    Joined:
    Dec 7, 2007
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Dear Sir,

    i use the following symlink

    /var/lib/mysql -> /home/mysqldata/

    What should i write in /var/cpanel/jailshell-additional-mounts ??

    Regards,
     
    #8 ksaied, Dec 15, 2014
    Last edited: Dec 15, 2014
  9. ksaied

    ksaied Member

    Joined:
    Dec 7, 2007
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Dear Sir,

    Not working.

    I moved /var/lib/mysql -> /home/mysqldata from about 6 months but didn't test cronjobs.

    This is strange, localhost in mysql_connect is working when executed from the web or from shell as root but not in cronjobs.

    I receive the following error only with cronjobs:

    mysql_connect(): Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)

    127.0.0.1 is working, but i don't want to change the code of all my clients.

    What should i do to make localhost work with cronjobs.

    Kindly send me detailed steps.

    Thanks,
     
  10. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,678
    Likes Received:
    648
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    Please post the output from:

    Code:
    cat /etc/my.cnf
    Also, just to verify, did you complete the step referenced in my previous post?

    Thank you.
     
  11. ksaied

    ksaied Member

    Joined:
    Dec 7, 2007
    Messages:
    10
    Likes Received:
    0
    Trophy Points:
    1
    cPanel Access Level:
    Root Administrator
    Yes i made the step of putting (/home/mysqldata) in /var/cpanel/jailshell-additional-mounts

     
  12. cPanelMichael

    cPanelMichael Forums Analyst
    Staff Member

    Joined:
    Apr 11, 2011
    Messages:
    30,678
    Likes Received:
    648
    Trophy Points:
    113
    cPanel Access Level:
    Root Administrator
    Feel free to open a support ticket using the link in my signature so we can take a closer look. You can post the ticket number here so we can update this thread with the outcome.

    Thank you.
     
Loading...

Share This Page