Web Hosting Forums

Results 1 to 7 of 7

This is a discussion on accessing mysql from php cron job/command line in the Hosting Talk & Chit-chat forum
I am getting an error when trying to access mySql. Code: /usr/local/bin/php ./myscript.php gives: Code: Warning: mysql_connect(): Can't connect to local MySQL server through socket ...

  1. #1
    Loyal Client
    Join Date
    Apr 2004
    Location
    Norway
    Posts
    21

    Question accessing mysql from php cron job/command line

    I am getting an error when trying to access mySql.
    Code:
    /usr/local/bin/php ./myscript.php
    gives:
    Code:
    Warning: mysql_connect(): Can't connect to local MySQL server through socket 
    '/var/tmp/mysql.sock' (2) in /home/<userid>/bin/myscript.php on line 14
    I'm using the same login and password in my web application, so that shouldn't be the problem.

    Do I have to place my script in the public_html area and use GET og wget in order to connect? It is meant to be a cron job so I would prefer not to put it together with the web scripts...

  2. #2
    the Windlord Gwaihir's Avatar
    Join Date
    Jun 2002
    Posts
    2,570
    You did prefix both the MySQL username and the database name with your userid?
    Regards,

    Wim Heemskerk
    ---
    Visit MeCCG.net - Cardgaming in J.R.R. Tolkien's Middle-earth
    And Gwaihir.net - The Middle-earth CCG store

  3. #3
    Loyal Client
    Join Date
    Apr 2004
    Location
    Norway
    Posts
    21
    Yes, I did prefix both the userid and database name. The settings are working perfectly well when I use them in a web script. The error occurs only when I run the script from command line.

  4. #4
    Community Leader jason's Avatar
    Join Date
    Sep 2001
    Location
    Rochester, NY
    Posts
    5,884
    I seem to remember this being an issue a while back for someone else. The problem was that the mysql driver wasn't available to the command line version of PHP, it was only being loaded by the Apache module version.

    I'll do some digging through older threads and see if I can find anything about this. In the meantime, a support ticket is probably all that is needed to get it fixed.

    --Jason
    Jason Pitoniak
    Interbrite Communications
    www.interbrite.com www.kodiakskorner.com

  5. #5
    Community Leader jason's Avatar
    Join Date
    Sep 2001
    Location
    Rochester, NY
    Posts
    5,884
    Here's the older thread on this issue. Not a whole lot of info, but I suspect your issue is the same.

    http://forums.jaguarpc.com/showthrea...mmand+line+php

    --Jason
    Jason Pitoniak
    Interbrite Communications
    www.interbrite.com www.kodiakskorner.com

  6. #6
    Loyal Client
    Join Date
    Apr 2004
    Location
    Norway
    Posts
    21
    Thanks, jason.
    I contacted support, and they told me to use "127.0.0.1" instead of "localhost".
    A small change, but a great result

  7. #7
    Loyal Client
    Join Date
    Sep 2002
    Posts
    640
    Quote Originally Posted by gorgon
    Thanks, jason.
    I contacted support, and they told me to use "127.0.0.1" instead of "localhost".
    A small change, but a great result
    That's somethign I would expect to be fixed on their end (server-wide). Not a hard thing to do, by the way.

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
  •