Page 1 of 1

Connecting Mysql database located in different server in php

Posted: Wed Nov 05, 2008 10:22 am
by anujphp
Hello
I have a website where i have used php and mysql,till now both php and mysql were located in same server and my site was working fine but recently we have shifted Mysql to a different server.
In the php code we have changed the server name with the new server name.but when we try to open the page we are getting error

THE ERROR IS

Warning: mysql_connect() [function.mysql-connect]: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /home/web/XXXXX/STONEDIVER_PHP_LIBRARY/source/shared/database.php on line 38
Could not connect: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)


The code before migration of Mysql was

$server = "localhost";
$dbname = "database";
$user = "username"; //Allowed for the ip
$password = "password";
$link = mysql_connect($server,$user,$password) or die(mysql_error());
mysql_select_db($dbname);


The code after migrating Mysql is

$server = "serverip/servername";
$dbname = "database";
$user = "username"; //Allowed for the ip
$password = "password";
$link = mysql_connect($server,$user,$password) or die(mysql_error());
mysql_select_db($dbname);

I have tried using both server IP and server name...

Please help me out in solving this problem...
THANKS IN ADVANCE

Re: Connecting Mysql database located in different server in php

Posted: Wed Nov 05, 2008 10:56 am
by onion2k
http://dev.mysql.com/doc/refman/5.0/en/ ... erver.html

Check the right port (3306) is open on the firewall if there is one.

Re: Connecting Mysql database located in different server in php

Posted: Wed Nov 05, 2008 12:47 pm
by anujphp
Thank you onion2k
port is open and there is no problem with firewall.

Re: Connecting Mysql database located in different server in php

Posted: Fri Nov 07, 2008 12:18 am
by oddsmojo
Warning: mysql_connect() [function.mysql-connect]: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2) in /home/web/XXXXX/STONEDIVER_PHP_LIBRARY/source/shared/database.php on line 38
Could not connect: Can't connect to local MySQL server through socket '/var/lib/mysql/mysql.sock' (2)
After you updated the $server with your new server, are you still getting that exact error? I'm curious why it is trying to connect to a local server if you have updated the $server to your new host.

Re: Connecting Mysql database located in different server in php

Posted: Tue Nov 18, 2008 3:06 pm
by anujphp
Thank you guys the link from onion2k was of great help i am able to solve my issue..thanks once again