Re: [PHP] PHP-MYSQL Error: Can't connect to MySQL socket. Can someonehelp me out please?

[email protected] (Rahul)
Newsgroups php.general
Message-ID <[email protected]>
I have recorded both the errors by changing the variable:

$host = "mycomputer.webaddress.com"

PHP Warning:  mysql_connect(): Lost connection to MySQL server during 
query in /export/home/rpo219/may/conf_global.php on line 18
Lost connection to MySQL server during query

$host = "localhost"

PHP Warning:  mysql_connect(): Can't connect to local MySQL server 
through socket '/var/lib/mysql/mysql.sock' (111) in 
/export/home/rpo219/may/conf_global.php on line 18
Can't connect to local MySQL server through socket 
'/var/lib/mysql/mysql.sock'

I found something weird for the first time:

I tried looking at the mysql6 data directory and it says the following:

total 28
drwxr-xr-x   3 nfsnobody nfsnobody 4096 May 10 23:57 .
drwxrwxrwx  21 root      root      4096 May  7 14:35 ..
-rw-rw----   1 nfsnobody nfsnobody 1009 May 10 23:57 
mycomputer.webaddress.com.err
drwxr-xr-x   2 nfsnobody nfsnobody 4096 Jan 24 20:07 mysql

And when I try to change the ownership of the directory to mysql by

[[email protected]] chown mysql ./mysql6
chown: changing ownership of `./mysql6': Operation not permitted

Just thought it might be related to the problem

Thanks,
Rahul
Rahul wrote:
> Thanks a lot for your reply.
> 
> I have tried using
> 
> $host = "localhost";
> $db = "dbname";
> $table_main = "tablename";
> $dbusername = "root";
> $dbpass = "passhere";
> 
> mysql_connect($host, $dbusername, $dbpass) or die(mysql_error());
> 
> and
> 
> $host = "mycomputer.webaddress.com";
> $db = "dbname";
> $table_main = "tablename";
> $dbusername = "root";
> $dbpass = "passhere";
> 
> mysql_connect($host, $dbusername, $dbpass) or die(mysql_error());
> 
> And this mycomputer.webaddress.com works when I use with mysql like this:
> 
> mysql -h mycomputer.webaddress.com -u root -p
> 
> Thank You
> 
> Nathan Nobbe wrote:
>> On Sun, May 11, 2008 at 12:30 AM, Rahul <[email protected]> wrote:
>>
>>> I am using Fedora Core 4. As I was unable to use PHP or MySQL 
>>> together, I
>>> uninstalled both of them and installed again using the following 
>>> commands:
>>>
>>> yum install mysql
>>>
>>> And then
>>>
>>> apt-get install php php-devel php-gd php-imap php-ldap php-mysql 
>>> php-odbc
>>> php-pear php-xml php-xmlrpc curl curl-devel perl-libwww-perl ImageMagick
>>>
>>> And then started the mysql server.
>>>
>>> I am able to connect to the server from the console my typing
>>>
>>> mysql -h <hostname> -u root -p <mypass>
>>>
>>> However, when I try to connect to mysql through PHP I get the following
>>> errors:
>>>
>>> PHP Warning:  mysql_query(): Can't connect to local MySQL server through
>>> socket '/var/lib/mysql/mysql.sock' (2) in 
>>> /export/home/rahul/may/sample.php
>>> on line 5
>>> PHP Warning:  mysql_query(): A link to the server could not be 
>>> established
>>> in /export/home/rahul/may/sample.php on line 5
>>> Can't connect to local MySQL server through socket
>>> '/var/lib/mysql/mysql.sock' (2)
>>>
>>> Can someone please help me out?
>>
>>
>> what is the hostname you are typing at the command line and what is 
>> the one
>> you are using when trying to connect from php?  when using mysql, you 
>> will
>> have to have a separate entry for localhost connections.
>>
>> -nathan
>>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.