title: Mysql connection refused on localhost
body: <p>After an upgrade to El Capitan I'm having issues connecting to MySql. I have a basic PHP file called <code>index.php</code> with the following code:</p>
  
  <pre><code>&lt;?php
    $conn = new mysqli("127.0.0.1", "xxxx", "xxxx");
    if ($conn-&gt;connect_error) die("Connection failed: " . $conn-&gt;connect_error); 
    echo "Connected successfully";
  ?&gt;
  </code></pre>
  
  <p>Now when I visit the page in my browser, I get the following message:</p>
  
  <pre><code>Warning: mysqli::mysqli(): (HY000/2002): Connection refused in /Users/rich/Documents/DESIGN/test/index.php on line 3
  Connection failed: Connection refused
  </code></pre>
  
  <p>I can't understand what's going wrong here. I should mention that I also had this problem on Yosemite before upgrade. The problem began when I wiped my computer to do a fresh install and had to setup Apache and PHP config again. I think something must have been left out of one of the files.</p>
  
  <p><strong>EDIT</strong>
  I've also tried using <code>localhost</code> in the connection instead of <code>127.0.0.1</code>. That changes the error slightly to:</p>
  
  <pre><code>Warning: mysqli::mysqli(): (HY000/2002): No such file or directory in /Users/rich/Documents/DESIGN/test/index.php on line 4
  Connection failed: No such file or directory
  </code></pre>