PHP Warning: mysqli_connect(): (HY000/2002): Can’t connect to local MySQL server through socket ‘/var/lib/mysql/mysql.sock’ (2) in sugarcrm/include/database/MysqliManager.php on line
We have faced such an error with SugarCRM today. The above error was reporting in error_log file every time the cron.php is executed via cron job. We have taken a closer look and couldn’t find any real reason why it cannot connect via MySQL socket. Everything looks good and every testing via command line were giving good results. What we have checked is for the existence of the socket file ( the errors 2 states it canbot find the sock file ) and whether running the cron as user from command line can return the error. If it is cPanel system, all cron jobs are running in a Jailed shell from version 11.38. Make sure it is disabled, as it can cause this issue. We have find many similar threads in INTERNET, but could not find any real reason which can cause it. Finally we have decided to go ahead and force it to use TCP connection rather than using MySQL socket file. To do that we have edited config.php and changed the value of db_host_name parameter to “127.0.0.1” from “localhost. That fixed the issue and the error is not reporting so far. It may slow down MySQL connection a bit, as using socket file is stated to be the faster method.