title: Can't connect Google Cloud SQL(2nd) from GCE (Google Compute Engine)
body: <p>I can't connect Google Cloud SQL from GCE even I added public IP (external IP) of my GCE instance as a authorized network. It works when I add "0.0.0.0" into authorized network. Obviously I don't want to do that. The authorized network setting may be the cause. But I can't find out it. Does anyone know about this.</p>
  
  <p>I'm using Google Cloud SQL version 2 beta. I am trying to connect from GCP cloud console. Although it may be not necessary, I changed external IP setting from ephemeral to static but it didn't work.</p>
  
  <pre><code>mysql -u root -p -h xxxx &lt;--- I can login normally if I add "0.0.0.0" into authorized network. 
  </code></pre>
  
  <p>I've double checked this same question..</p>
  
  <blockquote>
    <p><a href="https://stackoverflow.com/questions/28908224/linking-google-compute-engine-and-google-cloud-sql">Linking Google Compute Engine and Google Cloud SQL</a></p>
  </blockquote>
  
  <pre><code>1. Ensure your Cloud SQL instance has an IPv4 address.
  2. Find out the public IP address of your GCE instance and add it as an authorized network on your Cloud SQL instance.
  3. Add a MySQL username and password for your instance with remote access.
  4. When connecting from GCE use you standard MySQL connection system (e.g. mysqli_connect) with the username and password you just set up, connecting to the IPv4 address of your Cloud SQL instance.
  </code></pre>
  
  <hr>
  
  <p>Edit 1</p>
  
  <p>I noticed this description.</p>
  
  <blockquote>
    <p>Note: Connecting to Cloud SQL from Compute Engine using the Cloud SQL Proxy is currently available only for Cloud SQL Second Generation instances.</p>
  </blockquote>
  
  <p><a href="https://cloud.google.com/sql/docs/compute-engine-access" rel="nofollow noreferrer">https://cloud.google.com/sql/docs/compute-engine-access</a></p>
  
  <p>Does it mean that I have to use the Proxy..?</p>
  
  <hr>
  
  <p>Edit 2</p>
  
  <pre><code>$ mysql -u root -p -h (Cloud SQL Instance's IP)
  Enter password: 
  ERROR 2003 (HY000): Can't connect to MySQL server on '(Cloud SQL Instance's IP)' (110)
  </code></pre>
  
  <hr>
  
  <p>Edit 3</p>
  
  <blockquote>
    <p>Does it mean that I have to use the Proxy..?</p>
  </blockquote>
  
  <p>According to the official document as Vadim said, Cloud SQL Proxy seems to be optional but it sounds better for security, flexibility and also the price. (static IP will be charged. However, the proxy setting may be complicated for me..)</p>
  
  <p><a href="https://cloud.google.com/sql/docs/compute-engine-access" rel="nofollow noreferrer">https://cloud.google.com/sql/docs/compute-engine-access</a></p>
  
  <blockquote>
    <p>If you are connecting to a Cloud SQL First Generation instance, then you must use its IP address to connect. However, if you are using a Cloud SQL Second Generation instance, you can also use the Cloud SQL Proxy or the Cloud SQL Proxy Docker image.</p>
  </blockquote>
  
  <hr>
  
  <p>Edit 4</p>
  
  <p>I found the reason... I was stupid... I tried connect from Google Cloud Shell but that was not my gce instance. It works when I try to connect from my gce instance.</p>