Reputation: 2339
I am trying to use cloud SQL / mysql instance for my APPEngine account. The app is an python django-2.1.5 appengine app. I have created an instance of MYSQL in the google cloud.
I have added the following in my app.yaml file copied from the SQL instance details:
beta_settings:
cloud_sql_instances: <INSTANCE_CONNECTION_NAME>=tcp:<TCP_PORT>
I have given rights for my appengine project xxx-app's owner xxx-[email protected]
the Cloud SQL Client
rights. I have created a DB user account specific for the app XYZ
which can connect to all hosts (* option)
My connection details in settings.py are the following:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'my-db',
'USER': 'appengine',
'PASSWORD': 'xxx',
'HOST': '111.111.11.11', # used actual ip
'PORT': '3306'
}
}
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'HOST': '/cloudsql/<your-project-id>:<your-cloud-sql-instance>',
'NAME': '<your-database-name>',
'USER': 'root',
}
}
Add Network
of my local IP and then try to connect the local connects. THe app runs fine locally after adding the network of local IP Address using CIDR notation.My problems:
OperationalError: (2003, "Can't connect to MySQL server on '0.0.0.0' ([Errno 111] Connection refused)")
Upvotes: 1
Views: 617
Reputation: 21
I've encountered this issue before and after hours of scratching my head, all I needed to do was enable "Cloud SQL Admin API" and the deployed site connected to the database. This also sets permissions on your GAE service account for cloud proxy to connect to your GAE service.
Upvotes: 1
Reputation: 3565
App Engine doesn't have any guarantees regarding IP address of a particular instance, and may change at any time. Since it is a Serverless platform, it abstracts away the infrastructure to allow you to focus on your app.
There are two options when using App Engine Flex: Unix domain socket and TCP port. Which one App Engine provides for you depends on how you specify it in your app.yaml:
cloud_sql_instances: <INSTANCE_CONNECTION_NAME>
provides a Unix socket at
/cloudsql/<INSTANCE_CONNECTION_NAME>
cloud_sql_instances: <INSTANCE_CONNECTION_NAME>=tcp:<TCP_PORT>
provides a local tcp port (127.0.0.1:<TCP_PORT>
).You can find more information about this on the Connecting from App Engine page.
Upvotes: 2