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
some webhosts don't allow remote mySQL connections. You should check with your web host to see if they allow it.
most decent webhosts allow you to add a host to accept incomming connections for the mysql database on your account. if you have cPanel version 3, click on REMOTE DATABASES in the Databases section, then configure accordingly. if you have cPanel version 2, click on MySQL Databases >> Remote Databases and its somewhere in there (look around) if you dont have cpanel jsut have a look around the databases section or contact your host for more information. however, if you have a lowball host, they might have it turned off or disabled to save on resources.
the error is a common error indicating a problem connecting to the db host, it could be possible that you are connecting to a remote db and not on the local machine