skip to Main Content

I am trying to connect to ProxySQL from PHP with mysqlnd using the local socket, but I get

“No such file or directory”

, as the socket would not exist. The same code can connect to the mysql socket with no problem.

Basically I am reproducing what was described at:
https://www.percona.com/blog/2017/09/19/proxysql-improves-mysql-ssl-connections/

<?php
$i = 10000;
$user = 'percona';
$pass = 'percona';
while($i>=0) {
 $mysqli = mysqli_init();

 // ProxySQL
 $link = mysqli_real_connect($mysqli, "localhost",      $user, $pass, "", 6033, "/tmp/proxysql.sock")
 or die(mysqli_connect_error());
 $info = mysqli_get_host_info($mysqli);
 $i--;
 mysqli_close($mysqli);
 unset($mysqli);
}
?>

This throws:

mysqli_real_connect(): (HY000/2002): No such file or directory

The socket file (/tmp/proxysql.sock) is in fact there:

$ ls -all /tmp
total 12
drwxrwxrwt. 11 root     root      4096 Oct  7 17:33 .
dr-xr-xr-x. 28 root     root      4096 Sep 20 17:42 ..
drwxrwxrwt.  2 root     root         6 Aug  8 02:40 .font-unix
drwxrwxrwt.  2 root     root         6 Aug  8 02:40 .ICE-unix
srwxrwxrwx   1 proxysql proxysql     0 Oct  7 17:11 proxysql.sock

I can use the mysql client to connect through it:

$ mysql -u myuser -p --socket /tmp/proxysql.sock --prompt='ProxySQLClient> '

If in the above PHP code I replace the socket file with the MySQL socket, then that works. It is only the proxysql.sock which doesn’t work with mysqlnd.

I am using:
mysqlnd version mysqlnd 5.0.12-dev – 20150407
ProxySQL version 2.0.6

Any idea why the proxysql.sock is not accepted by mysqlnd?

UPDATE: Following @EternalHour’s suggestion below, I have also tried moving the proxysql.sock file out of /tmp, but unfortunately that didn’t make a difference. I am still receiving the same error.

EDIT (2019-10-08): It turns out this issue has nothing to do with PHP, as netcat throws the same problem too, whether the socket files in in /tmp or in /var/sockets/:

$ nc -U /tmp/proxysql.sock
Ncat: No such file or directory.

Out of the 3 nodes of the ProxySQL cluster running on the same OS, same kernel version, 1 has this issue, the other 2 allows connection to the socket file in /tmp/proxsql.sock, although over there too, sometimes restarting ProxySQL results in the socket file being created as private (eg not available to other applications)

2

Answers


  1. Chosen as BEST ANSWER

    I am sorry everyone, the issue was embarrassingly simple - it was simply my fault.

    When I was changing the socket file's location in ProxySQL Admin I was using the following

    update global_variables set variable_value='0.0.0.0:6033;/tmp/proxysql.sock ' where variable_name='mysql-interfaces'; SAVE MYSQL VARIABLES TO DISK;

    Yes, that is a space at the end of "/tmp/proxysql.sock ". When I was changing it to different locations, I only rewrote the first half of that (the folder), never the filename, so I just keep copying the space and hence always got file or directory not found...

    Problem solved!

    Sorry about it


  2. Many MySQL Clients have a special handling of the wordlocalhost. localhost doesn’t mean “use the resolver to resolve localhost and connect via TCP” but “use unix domain socket on the default path” to use TCP use 127.0.0.1 instead. If proxySQL also provides a unix domain socket provide that path.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search