title: Warning: mysqli::__construct(): (HY000/2002): No such file or directory in
body: <p>I'm totally stuck having spent a couple of days trying to figure this out...</p>
  
  <p>I have set up an Apache web server (version 2.4.34) on my Mac OS running Mojave (10.14.3) and have installed the current version of MySQL Community Server (8.0.15). Both running perfectly as I can determine (from command line). I have PHP 7.1.23 installed. When I create a .php file with the following code and put it in my Sites directory and then in Safari go to <a href="http://localhost/~dave/hello.php" rel="nofollow noreferrer">http://localhost/~dave/hello.php</a> I get this error:</p>
  
  <blockquote>
    <p>"Warning: mysqli::__construct(): (HY000/2002): No such file or
    directory in /Users/dave/Sites/hello.php on line 7 Connection failed:
    No such file or directory".</p>
  </blockquote>
  
  <p>Code in hello.php:</p>
  
  <pre><code>&lt;?php
  $servername = "localhost";
  $username = "dave";
  $password = "*****";
  
  //Create connection
  $conn = new mysqli($servername, $username, $password);
  
  //Check connection
  if ($conn-&gt;connect_error) {
     die("Connection failed: " . $conn-&gt;connect_error);
  }
  echo "Connected successfully";
  ?&gt;
  </code></pre>
  
  <p>I have tried everything I can think of, including those suggestions in the other two similar posts (this one: <a href="https://stackoverflow.com/q/20073168/11156316">My database user exists, but I still get an (HY000/2002): No such file or directory</a> and this one: <a href="https://stackoverflow.com/q/53660726/11156316">PHP Warning: mysqli::__construct(): (HY000/2002): No such file or directory (Debian GNU/Linux 9)</a>), and I cannot connect to MySQl with php. In particular, I checked with the php info page and the socket for mysqli is given as <code>var/mysql/mysql.sock</code>. In the relevant table in mysql the value for socket is given as <code>/tmp/mysql.sock</code>. I tried changing the php.ini.default file by adding each of these sockets (in place of the empty value) and neither worked (still generates the same error). I thought that the 2002 MySQL socket error might be the problem, so I made a symlink by doing this:</p>
  
  <pre><code>sudo mkdir /var/mysql
  sudo ln -s /tmp/mysql.sock /var/mysql/mysql.sock
  </code></pre>
  
  <p>but all that did was generate a new error:</p>
  
  <blockquote>
    <p>Warning: mysqli::__construct(): The server requested authentication
    method unknown to the client [caching_sha2_password] in
    /Users/dave/Sites/hello.php on line 7</p>
    
    <p>Warning: mysqli::__construct(): (HY000/2054): The server requested
    authentication method unknown to the client in
    /Users/dave/Sites/hello.php on line 7 Connection failed: The server
    requested authentication method unknown to the client</p>
  </blockquote>
  
  <p>So I removed the symlink...and returned to the original error.</p>
  
  <p>I also tried replacing "localhost" with the IP address 127.0.0.1 as well as "localhost:3306" as other question threads have suggested. Nothing worked here either.</p>
  
  <p>Please help, I am new to this kind of use of the computer/web design and I'm out of obvious (googleable/understandable) options.</p>