title: Can't connect to Lightsail Managed Database - (HY000/2002): Connection refused
body: <p>I am trying to connect to a Lightsail managed database from a Lightsail instance in the same region using PHP's mysqli extension, but am getting the error:</p>
  
  <blockquote>
    <p>Warning: mysqli_connect(): (HY000/2002): Connection refused</p>
  </blockquote>
  
  <p>My script is very basic and looks like this:</p>
  
  <pre><code>&lt;?php
  define("DB_HOST", "ls-xxxxxxxxxxxxxxxxxxxxxx.xxxxx.eu-west-2.rds.amazonaws.com");
  define("DB_NAME", "xxxxxxx");
  define("DB_USER", "xxxxxxx");
  define("DB_PASS", "xxxxxxx");
  $db= mysqli_connect(DB_HOST,DB_USER,DB_PASS,DB_NAME,3306);
  </code></pre>
  
  <p>Here's what I've tried so far:</p>
  
  <ul>
  <li>I've checked <code>$_SERVER['SERVER_ADDR']</code> and found that it was my Lightsail instance's private IP address.</li>
  <li>I've tried with and without <code>Public mode</code> turned on in the database's <code>Networking</code> tab</li>
  <li>I've been able to connect to it successfully using MySQL Workbench</li>
  <li>I've tried turning on <code>VPC Peering</code> for my chosen region in the Account section of Lightsail</li>
  </ul>
  
  <p>What am I doing wrong?</p>