title: Google Cloud Platform SQL instance connection to python app
body: <p>I am deploying a python3.8 app based on <a href="https://flask.palletsprojects.com/" rel="nofollow noreferrer">Flask</a> on <a href="https://cloud.google.com/" rel="nofollow noreferrer">Google Cloud Platform</a>.</p>
  <p>I managed to create and SQL instance connected to it and also to interact with such instance (allowing my local IP inbound connection to the instance) launching the app from my local machine directly (following <a href="https://www.geeksforgeeks.org/setting-up-google-cloud-sql-with-flask/" rel="nofollow noreferrer">this guide</a>) after initializing the DB with:</p>
  <pre><code>flask db init
  flask db migrate
  flask db upgrade
  </code></pre>
  <p>The configuration string that allows me to connect my local machine to SQL instance is (in <code>config.py</code>):</p>
  <pre><code>SQLALCHEMY_DATABASE_URI = f&quot;mysql+mysqldb://root:{PASSWORD}@{PUBLIC_IP_ADDRESS}/{DBNAME}?unix_socket=/cloudsql/{PROJECT_ID}:{INSTANCE_NAME}&quot;
  </code></pre>
  <p>Now, if I deploy the app with this line in <code>config.py</code> and try to interact with the DB from my GCP app page it fails to connect to the DB. It looks like it tries to connect as an external app (as my local machine does) and gets rejected (as I never allowed inbound connection for the app engine instance, cause it has no static IP).</p>
  <p>I suppose the SQL instance is somehow already connected to my app and I could access it with some local link, does anybody knows how?</p>