Mysql
 sql >> Database >  >> RDS >> Mysql

Impossibile connettersi al server MySQL locale tramite socket

Poiché l'errore viene generato dalla chiamata a mysql_real_escape_string() implica piuttosto che non hai chiamato mysql_connect() prima e passa un valido db handle a mysql_real_escape_string (o la chiamata a mysql_connect() fallito).

In alcune circostanze, l'estensione mysql tenterà di connettersi automaticamente utilizzando le impostazioni predefinite in php.ini, eseguendo il failover su my.cnf se queste non sono disponibili, che ovviamente non sono valide. Oppure può essere che le impostazioni siano valide ma mysqld non sia in esecuzione.

Hai degli script che si connettono correttamente al database?

Hai un nome utente e una password per il database?

Prova:

check_running();

$user=''; // fill in your details
$password=''; // fill in your details

$hosts=array(
  'localhost', '127.0.0.1', $_SERVER['HTTP_HOST'], $_SERVER['SERVER_ADDR']
);
foreach ($hosts as $addr) {
   try_con($addr, $user, $password);
   try_con($addr . ':3306', $user, $password);
}

function try_con($host, $user, $password)
{
 $dbh=mysql_connect($host, $user, $password);
 if ($dbh) {
     print "Connected OK with $host, $user, $password<br />\n";
 } else {
     print "Failed with $host, $user, $password<br />\n";
 }
}

function check_running()
{
   // this assumes that you are using Apache on a Unix/Linux box
   $chk=`ps -ef | grep httpd | grep -v grep`;
   if ($chk) {
      print "Checking for mysqld process: " . `ps -ef | grep mysqld | grep -v grep` . "<br />\n";
   } else {
       print "Cannot check mysqld process<br />\n";
   }
 }