Closed hessjcg closed 1 month ago
The dialer may be configured to use a DNS name to look up the instance name instead of configuring the connector with the instance name directly.
Add a DNS TXT record for the Cloud SQL instance to a private DNS server or a private Google Cloud DNS Zone used by your application. For example:
TXT
prod-db.mycompany.example.com
my-project:region:my-instance
Configure the dialer with the cloudsqlconn.WithDNSResolver() option.
cloudsqlconn.WithDNSResolver()
Open a database connection using the DNS name:
db, err := sql.Open( "cloudsql-mysql", "myuser:mypass@cloudsql-mysql(prod-db.mycompany.example.com)/mydb", )
Part of #842
The dialer may be configured to use a DNS name to look up the instance name instead of configuring the connector with the instance name directly.
Add a DNS TXT record for the Cloud SQL instance to a private DNS server or a private Google Cloud DNS Zone used by your application. For example:
TXT
prod-db.mycompany.example.com
– This is the domain name used by the applicationmy-project:region:my-instance
– This is the instance connection nameConfigure the dialer with the
cloudsqlconn.WithDNSResolver()
option.Open a database connection using the DNS name:
Part of #842