PHP-MYSQL Error: Can't connect to MySQL socket. Can someone helpme out please?

This is a discussion on PHP-MYSQL Error: Can't connect to MySQL socket. Can someone helpme out please? within the PHP General forums, part of the PHP Programming Forums category; I am using Fedora Core 4. As I was unable to use PHP or MySQL together, I uninstalled both of ...


Go Back   Usenet Forums > PHP Programming Forums > PHP General

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 05-11-2008
Rahul
 
Posts: n/a
Default PHP-MYSQL Error: Can't connect to MySQL socket. Can someone helpme out please?

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?
Reply With Quote
  #2 (permalink)  
Old 05-11-2008
Rahul
 
Posts: n/a
Default Re: PHP-MYSQL Error: Can't connect to MySQL socket. Can someone helpmeout please?

By the way it installed MySQL 6 and PHP 5.0.4 and from the console this
command does not work:

mysql -u root -p

but only this works:

mysql -h <hostname> -u root -p

I tried doing the same while connecting to the database via php but it
does not work.

Rahul 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?

Reply With Quote
  #3 (permalink)  
Old 05-11-2008
Nathan Nobbe
 
Posts: n/a
Default Re: [PHP] PHP-MYSQL Error: Can't connect to MySQL socket. Can someone help me out please?

On Sun, May 11, 2008 at 12:30 AM, Rahul <rahul986@gmail.com> 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

Reply With Quote
  #4 (permalink)  
Old 05-11-2008
Rahul
 
Posts: n/a
Default Re: [PHP] PHP-MYSQL Error: Can't connect to MySQL socket. Can someonehelp me out please?

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 <rahul986@gmail.com> 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
>

Reply With Quote
  #5 (permalink)  
Old 05-11-2008
Nathan Nobbe
 
Posts: n/a
Default Re: [PHP] PHP-MYSQL Error: Can't connect to MySQL socket. Can someone help me out please?

On Sun, May 11, 2008 at 12:42 AM, Rahul <rahul986@gmail.com> 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



so, from above (previous post), it looks like the errors youve shown are
actually coming from mysql_query(). what is the result of this (using
credentials from this post and [mycomputer.webaddress.com])

<?php
if(!mysql_connect($host, $dusername, $dbpass)) {
die(mysql_error());
} else {
die('successful connection established');
}

-nathan

Reply With Quote
  #6 (permalink)  
Old 05-11-2008
Rahul
 
Posts: n/a
Default Re: [PHP] PHP-MYSQL Error: Can't connect to MySQL socket. Can someonehelpme out please?

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

[root@mycomputer.webaddress.com] 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 <rahul986@gmail.com> 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
>>

Reply With Quote
  #7 (permalink)  
Old 05-11-2008
Nathan Nobbe
 
Posts: n/a
Default Re: [PHP] PHP-MYSQL Error: Can't connect to MySQL socket. Can someonehelp me out please?

On Sun, May 11, 2008 at 1:05 AM, Rahul <rahul986@gmail.com> wrote:

> 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



i have seen this before, but i cant recall, specifically what the problem
could be. i recommend google ;)


> $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 believe this is because the user root, does not have permission to connect
to the datbase from host 'localhost', especially since you said this didnt
work from the command line either. you will have to add a grant clause to
allow the root user to connect from the localhost.

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
>


that is likely the way your distribution has designed the permission scheme
for the mysql server.

And when I try to change the ownership of the directory to mysql by
>
> [root@mycomputer.webaddress.com] chown mysql ./mysql6
> chown: changing ownership of `./mysql6': Operation not permitted
>


this is probly because you dont have permission to make the change... you
could do it via sudo, but i wouldnt recommend it. your distro has set it up
this way on purpose.


> Just thought it might be related to the problem



have you created any databases after installing mysql? you should create at
least one, like test db or something, and its good practice to create a
specific user to access the database through as well. instead of having php
connect as root. thats like a hackers dream right there.

-nathan

Reply With Quote
  #8 (permalink)  
Old 05-11-2008
Rahul P
 
Posts: n/a
Default Re: [PHP] PHP-MYSQL Error: Can't connect to MySQL socket. Can someonehelp me out please?

Thanks. I just stopped mysql and when I try to start it again it throws
another set of errors:

chown: changing ownership of `/home-public/mysql6': Operation not permitted

So I guess something is messed up completely. I wish I installed it better.
Now the installing is messed up I guess with all sorts of bad files. I will
try Google now...

Thanks for the help... :)

On Sun, May 11, 2008 at 12:17 AM, Nathan Nobbe <quickshiftin@gmail.com>
wrote:

> On Sun, May 11, 2008 at 1:05 AM, Rahul <rahul986@gmail.com> wrote:
>
>> 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

>
>
> i have seen this before, but i cant recall, specifically what the problem
> could be. i recommend google ;)
>
>
>> $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 believe this is because the user root, does not have permission to
> connect to the datbase from host 'localhost', especially since you said this
> didnt work from the command line either. you will have to add a grant
> clause to allow the root user to connect from the localhost.
>
> 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
>>

>
> that is likely the way your distribution has designed the permission scheme
> for the mysql server.
>
> And when I try to change the ownership of the directory to mysql by
>>
>> [root@mycomputer.webaddress.com] chown mysql ./mysql6
>> chown: changing ownership of `./mysql6': Operation not permitted
>>

>
> this is probly because you dont have permission to make the change... you
> could do it via sudo, but i wouldnt recommend it. your distro has set it up
> this way on purpose.
>
>
>> Just thought it might be related to the problem

>
>
> have you created any databases after installing mysql? you should create
> at least one, like test db or something, and its good practice to create a
> specific user to access the database through as well. instead of having php
> connect as root. thats like a hackers dream right there.
>
> -nathan
>
>



--
Rahul
Computer Engineering and Systems Division.
Department of Electrical Engineering and Computer Science
Robert R. McCormick School of Engineering
Northwestern University
2145 Sheridan Road, Evanston,IL60208.

Administrator: The En?gma Project
Website: http://www.enigmaportal.com

Reply With Quote
  #9 (permalink)  
Old 05-11-2008
Nathan Nobbe
 
Posts: n/a
Default Re: [PHP] PHP-MYSQL Error: Can't connect to MySQL socket. Can someonehelp me out please?

On Sun, May 11, 2008 at 1:22 AM, Rahul P <rahul986@gmail.com> wrote:

> Thanks. I just stopped mysql and when I try to start it again it throws
> another set of errors:
>
> chown: changing ownership of `/home-public/mysql6': Operation not permitted
>
> So I guess something is messed up completely. I wish I installed it better.
> Now the installing is messed up I guess with all sorts of bad files. I will
> try Google now...
>
> Thanks for the help... :)
>


one benefit of package managers is that they let you uninstall and reinstall
easily. are you using yum or apt-get ? in your first post you included
both the commands.. anyway, id just uninstall and reinstall it; should take
10 minutes or so.

-nathan

Reply With Quote
  #10 (permalink)  
Old 05-11-2008
Rahul P
 
Posts: n/a
Default Re: [PHP] PHP-MYSQL Error: Can't connect to MySQL socket. Can someonehelp me out please?

Oh... This is the fourth time I'm doing that except that this time yum
installed mysql6 instead of older versions... I don't see any way out other
than reinstalling the OS itself... There are so many dependency failures....
I'm spending more time troubleshooting than actually coding something :)

On Sun, May 11, 2008 at 12:27 AM, Nathan Nobbe <quickshiftin@gmail.com>
wrote:

> On Sun, May 11, 2008 at 1:22 AM, Rahul P <rahul986@gmail.com> wrote:
>
>> Thanks. I just stopped mysql and when I try to start it again it throws
>> another set of errors:
>>
>> chown: changing ownership of `/home-public/mysql6': Operation not
>> permitted
>>
>> So I guess something is messed up completely. I wish I installed it
>> better. Now the installing is messed up I guess with all sorts of bad files.
>> I will try Google now...
>>
>> Thanks for the help... :)
>>

>
> one benefit of package managers is that they let you uninstall and
> reinstall easily. are you using yum or apt-get ? in your first post you
> included both the commands.. anyway, id just uninstall and reinstall it;
> should take 10 minutes or so.
>
> -nathan
>
>



--
Rahul
Computer Engineering and Systems Division.
Department of Electrical Engineering and Computer Science
Robert R. McCormick School of Engineering
Northwestern University
2145 Sheridan Road, Evanston,IL60208.

Administrator: The En?gma Project
Website: http://www.enigmaportal.com

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT +1. The time now is 10:41 PM.


Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO 3.0.0