I have a Node app which uses MySQL, connecting via a config json:
{
"client": "mysql",
"connection": {
"host": "something",
"user": "something",
"password": "something",
"database": "daimonion-db",
"debug": false
}
}
I've created a Google Cloud Platform SQL instance. I'm seeing an IP address and instance connection name.
I've also deployed the Node app to Google Cloud App Engine in a flexible environment.
How do I connect the Node app to the SQL instance? I'm seeing this explanation: https://cloud.google.com/sql/docs/mysql/connect-app-engine which tells me to add a settings string to my app.yaml to connect with either a Unix domain socket or TCP connection, but how do I connect to these from my Node app?
include
beta_settings
toapp.yaml
to enable cloud proxy on the instance in production, and specify the UNIX socketsocketPath
inconfig
, so your flex app can connect to the instance via proxy.socketPath
should be inconfig
only if the app is running in production on App Engine. For local development, the TCP socket is used with the proxy client, that you need to install and start with the following commands:here's an example of Node app that connects and queries a Cloud MySQL instance using the proxy. The
if
statement permits the app to switch configuration dev-local/prod-appengine automatically, using environment variables .app.yaml
package.json
server.js
There are two ways to connect
Cloud SQL
instance from local desktop:Example for
postgresql
Using public IP and
psql
tool: https://cloud.google.com/sql/docs/postgres/connect-admin-ipa. Add your external IP to
Cloud SQL
-CONNECTIONS
-Authorized networks
b. Modify your
connection.host
toCloud SQL
instance public IPUsing
cloud_sql_proxy
tool andINSTANCE_CONNECTION_NAME
: https://cloud.google.com/sql/docs/postgres/connect-admin-proxy