Reputation: 12378
Given is a PHP-Application running on Google App Engine, that needs a connection to GCloud SQL Instance with MySql in 2. Generation.
I'm curious if i should use the IP-Address for any mysql-connection as stated in official Google docs or if we can use something like a hostname to prevent interruptions if Google might change the IP-address.
What i can see so far in google cloud console is an instance-name like
my-example-instance:europe-west3:databasename
.
But since they use colons in their names we aren't able to use this as a host-name (according to RFC 952 colons aren't valid characters for hostnames if i understood it correctly).
My questions:
Is it reliable to use ip-addresses for mysql-connection within GCloud applications (when an Application on Google App Engine connects to GCloud SQL Instance)?
If not, can we get a stable, working hostname instead?
If not, how is it done properly?
Upvotes: 0
Views: 737
Reputation: 1576
In general, when working with GCP, your best bet is to follow the official docs. This will prevent you from running into unsupported cases and will make it easy for you to get assistance and support.
For a PHP-Application running on Google App Engine the recommended method is to use the Instance connection name which has the next format (note this isn’t a hostname):
project_id:region:cloud_sql_instance_name
For Detailed instructions using App Engine Standard you can refer to: https://cloud.google.com/appengine/docs/standard/php/cloud-sql/using-cloud-sql-mysql
For App Engine Flex you can refer to: https://cloud.google.com/appengine/docs/flexible/php/using-cloud-sql
To wrap up and address your questions:
It is reliable (your Cloud SQL ip-address won’t change upon restart), it’s not the recommended approach for App Engine Applications, though.
I don’t think so.
Use the instance connection named which is not a hostname.
Upvotes: 1