Page MenuHomeDevCentral

Configure MySQL socket in php.ini
Closed, ResolvedPublic

Description

Trying to connect to mediawiki-saas@localhost,
Warning: mysqli_connect(): (HY000/2002): No such file or directory.

By default, libmysqlclient resoles localhost to /tmp/mysql.sock.

This behavior isn't especially PHP related, for example, with the fbsql TCL extension:

02:03 <Dereckson> .tcl sql5 connect localhost a b
02:03 <daeghrefn> Tcl error: Error 2002 (Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2))

The workaround used was to ask to connect to 127.0.0.1.

But in PHP, we can configure the socket path.

php.ini
mysql.default_socket = /var/run/mysqld/mysqld.sock
mysqli.default_socket = /var/run/mysqld/mysqld.sock

Related Objects

StatusSubtypeAssignedTask
OpenNone
ResolvedNone