title: localhost: socket: mysqli_connect(): (HY000/2002): No such file or directory
body: <p>When I attempt to use a socket (not TCP) connection to connect to MySQL 5.7.21 using PHP 7.2.4 <code>mysqli_connect()</code> on Centos 7.4 I get an error:  </p>
  
  <blockquote>
    <p>Warning: mysqli_connect(): (HY000/2002): No such file or directory  </p>
  </blockquote>
  
  <h1>php.ini</h1>
  
  <blockquote>
    <p>mysqli.default_socket = /tmp/mysql.sock  </p>
  </blockquote>
  
  <h1>my.cnf</h1>
  
  <blockquote>
    <p>[mysqld]<br>
     socket=/tmp/mysql.sock<br>
     ...<br>
     [client]<br>
     socket=/tmp/mysql.sock  </p>
  </blockquote>
  
  <p>MySQL connection from command line works fine:  </p>
  
  <pre><code>/usr/local/mysql57/bin/mysql --socket tmp/mysql.sock --host localhost -u root -p  
  </code></pre>
  
  <blockquote>
    <p>Welcome to the MySQL monitor.  Commands end with ; or \g.<br>
    Your MySQL connection id is 3<br>
    Server version: 5.7.21 MySQL Community Server (GPL)  </p>
  </blockquote>
  
  <pre><code>ls -l /tmp/my*  
  </code></pre>
  
  <blockquote>
    <p>srwxrwxrwx 1 mysql mysql 0 Apr 19 22:01 /tmp/mysql.sock<br>
    -rw------- 1 mysql mysql 5 Apr 19 22:01 /tmp/mysql.sock.lock  </p>
  </blockquote>
  
  <pre><code>ps -edf | grep mysql  
  </code></pre>
  
  <blockquote>
    <p>mysql     3593  3329  0 22:01 ?        00:00:03 /usr/local/mysql57/bin/mysqld --defaults-file=/usr/local/mysql57/my.cnf --basedir=/usr/local/mysql57 --datadir=/mysql57 --plugin-dir=/usr/local/mysql57/lib/plugin --log-error=myhost.err --pid-file=myhost.pid --socket=/tmp/mysql.sock --port=3306</p>
  </blockquote>
  
  <pre><code>$dblink = mysqli_connect('localhost', 'root', 'rootpass', 'testdb', 3306, '/tmp/mysql.sock');
  if (mysqli_connect_errno($dblink)) {
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
  }
  </code></pre>
  
  <p>MySQL generic tar.gz was installed. I'm using nginx 1.12.2. If I use 127.0.0.1 or locahost:3306 such that TCP is used it works fine. Why doesn't socket work?</p>
  
  <h1>Update #1</h1>
  
  <p>I have another Centos 7.4 image with MySQL 5.7.11 which works with socket. However, I don't start it using <code>systemctl</code>. I also noticed that even though it's running there is no /tmp/mysql.sock.lock file, just /tmp/mysql.sock<br>
  Other than that it's mostly the same, in fact, /tmp/mysql.sock isn't specified anywhere in php.ini nor my.cnf files.</p>