[HCoop-Help] MySQL/PHP lost ability to connect in the last 24 hours

John T. Settino john at johnsettino.com
Mon Sep 29 13:46:06 EDT 2008


Try this out:

function connectdb($database=NULL) {
  $connection = mysql_connect("mysql","user","password") or die ("Unable
to connect to MySQL server: " . mysql_error() );
  if(is_null($database)) { $database = "default_db_name"; }
  $db = mysql_select_db($database) or die ("Unable to select requested
database: " . mysql_error() );
}


> Again, I haven't changed anything, but it is working again.  Here's
> the MySQL I use-- connect with (username, password, host) and select
> database separately.
>
> $local_status = mysql_connect("mysql","myusername","mysecretpassword");
> if ($local_status > 0)
> {
>    if (mysql_select_db("caden_samples") == false)
>    {
>       $local_error_code = "DATABASE";
>       $local_error_message = "Unable to select database.";
>    }
> }
>
> Thanks for writing back.   If there are different settings I should
> use to make this connection more resilient, I'd happily use them. :)
> Caden
>
> On Mon, Sep 29, 2008 at 5:49 AM, Davor Ocelic <docelic at hcoop.net> wrote:
>> On Sat, 27 Sep 2008 20:54:43 -0500
>> "C. Howell" <caden at hcoop.net> wrote:
>>
>>> Hello,
>>>
>>> I've made no changes to my portfolio in the last 24 hours, but PHP no
>>> longer connects to MySQL.
>>>
>>> I can connect to MySQL from the command line:
>>>
>>> caden at mire:~/caden_htdocs$ mysql -hmysql -p
>>> Enter password:
>>> Welcome to the MySQL monitor.  Commands end with ; or \g.
>>> Your MySQL connection id is 2956114
>>>
>>> However, when I connect within a PHP page I get:
>>>
>>> Warning: mysql_connect() [function.mysql-connect]: Unknown MySQL
>>> server host 'mysql' (2) in
>>> /afs/hcoop.net/user/c/ca/caden/caden_htdocs/cadenhowell.com/samples/index.php
>>> on line 11
>>
>> Okay, so looks the problem is not related to mysql per-se, but with
>> inability to find or contact server 'mysql'.
>>
>>> Warning: mysql_query() [function.mysql-query]: Can't connect to local
>>> MySQL server through socket '/var/run/mysqld/mysqld.sock' (2) in
>>> /afs/hcoop.net/user/c/ca/caden/caden_htdocs/cadenhowell.com/samples/index.php
>>> on line 37
>>
>> Here we see that PHP is trying to connect through local unix socket,
>> which won't work because unix sockets only work locally and not accross
>> network.
>>
>> In your case, you do need network connection to host 'mysql'.
>>
>>> Does anyone have any suggestions?  Has anything related on the server
>>> changed?  Environment variables, network configuration related to
>>> mysql?  My whole portfolio site is database-driven so I'd be grateful
>>> for any tips.
>>
>> Well first of all check if it's still giving the same message.
>>
>> Then next thing is checking where you have defined your MySQL connection
>> settings, and see if you have host/port option explicitly set.
>>
>> If it still tries to connect to local Unix socket on Mire, we'll
>> see what to do next.
>>
>> -doc
>>
>> _______________________________________________
>> HCoop-Help mailing list
>> HCoop-Help at lists.hcoop.net
>> https://lists.hcoop.net/listinfo/hcoop-help
>>
>
> _______________________________________________
> HCoop-Help mailing list
> HCoop-Help at lists.hcoop.net
> https://lists.hcoop.net/listinfo/hcoop-help
>
>


-- 
John T. Settino
Linux System Admin /
HCOOP Member since 2003
C: (410) 279-3039
H: (410) 697-5653




More information about the HCoop-Help mailing list