-1

I recently moved my mysql directory as it was filling up the partition.

I went ahead and updated my.cnf with the new datadir.

Then i went ahead and updated my php.ini default_socket (mysqli & mysql) to the new location and restarted apache. Yet every time a cron (php script) runs that does an mysqli update on a table i get:

Connection Failed: 2002

Should i be including the full path including filename or just the path.

/home/mysql/mysql.sock

Error Log:

[26-Feb-2014 11:30:01 America/New_York] PHP Warning: mysqli::mysqli(): (HY000/2002): Can't connect to local MySQL server through socket '/home/mysql/mysql.sock' (2) in /home/user/public_html/models/db-settings.php on line 21

Keelan
  • 325
  • 1
  • 4
  • 12
  • Is the socket really in `/home/mysql/mysql.sock`? Try with `ls /home/mysql/mysql.sock`. – Sjoerd Feb 26 '14 at 16:29
  • @Sjoerd result: `/home/mysql/mysql.sock=` – Keelan Feb 26 '14 at 16:31
  • So it seems changing localhost to 127.0.0.1 in my mysqli connection settings resolved this. But more than likely this means something is wrong else where. – Keelan Feb 26 '14 at 18:49

2 Answers2

-1

You should test separately mysql connection and php-mysql connection and proceed step by step. As I saw, the error is related on MySQL. So, verify if connecting using mysql on command line works. The verification is simply made by the following command

mysql -u<username> -p<password>

If you can access to mysql shell interface, mysql works well. Otherwise, investigate mysql problem.

Ranaivo
  • 1,578
  • 12
  • 6
-2

try this line:

$conn = mysqli_connect('host name', 'user name', 'password', 'database name');

if (!$conn) {
  echo ' error' . '<br>' . mysqli_connect_errno() ;
}

avoid space between the string and host name ... and u will get the result

Amir Asyraf
  • 613
  • 1
  • 7
  • 18