I have a Google App Engine application that operates perfectly when run locally using localhost:8080, but after I deploy to the cloud using gcloud app deploy, I receive the following error:
Warning: PDO::__construct(): MySQL server has gone away in /base/data/home/apps/s~fileabcd/20190320t221240.123456737151234567/gac_abcd.php on line 7
Warning: PDO::__construct(): Error while reading greeting packet. PID=-1 in /base/data/home/apps/s~fileabcd/20190320t221240.123456737151234567/gac_abcd.php on line 7
Any ideas why this is happening?
I discovered the reason why my Google App Engine (GAE) application functioned properly on localhost, but threw a MySQL server has gone away error after being deployed to [PROJECT-ID].appspot.com.
The reason is because my application was connecting to a Cloud SQL instance in a different project, and in order to do this you must grant the default appengine service account ([PROJECT-ID]#appspot.gserviceaccount.com) one of the following IAM roles:
Cloud SQL Client
Cloud SQL Editor
Cloud SQL Admin
After I added the App Engine default service account as a Cloud SQL Client Role in the project containing the Cloud SQL instance, everything worked perfectly.
From the Cloud SQL documentation.
Related
I'm attempting to connect a Flask App Engine instance to a Cloud SQL instance and the connection works when I run things locally but doesn't work when I deploy it using gcloud app deploy. I'm using flask_sqlalchemy to connect to the database with the following URI string
app.config["SQLALCHEMY_DATABASE_URI"]= f"postgresql://postgres:{PASSWORD}#{PUBLIC_IP_ADDRESS}:5432/{DBNAME}"
However this results in a timeout error that looks like this:
OperationalError: (psycopg2.OperationalError) could not connect to server: Connection timed out
Try taking a look at these pages:
Connecting from App Engine standard environment to Cloud SQL
Connecting from App Engine flexible environment to Cloud SQL
There are instructions for both Private and Public IP.
You may be also interesting this demo app:
https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/cloud-sql/postgres/sqlalchemy
I have developed an application in asp.net core EF, with MySql DB. Application is deployed on Google Cloud App Engine. I am trying Connecting Google Cloud App Engine application to Cloud MySql under same cloud project. Locally i am able to connect this database, but when deployed on google cloud i am getting error
MySqlException: Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.
MySql.Data.Common.StreamCreator.GetTcpStream(MySqlConnectionStringBuilder settings)
MySqlException: Unable to connect to any of the specified MySQL hosts.**
MySql.Data.MySqlClient.NativeDriver.Open()
I am using below connecting string
"DefaultConnection": "host=33.444.**.**;port=3306;database=mYdb;user=root;password=pASS"
img
Take a look at the "Connecting from App Engine" page here on the Cloud SQL docs. You need to enable the Cloud SQL server in your app.yaml, and then connect via 127.0.0.1:5432.
I have set up 2 projects in my Google Cloud console. The following are the two projects that I have set up in my console.
1. Cloud SQL + App Engine
2. App Engine (New)
So the idea is App Engine (1) is running the same database as App Engine (2). I have already set up the IAM Permission Page and IAM Admin and Project Page.
I have given both projects as Project Editor role too, but still my (2) still can't connect to my (1) database.
Any help please?
Granting access to an application does not automatically enable a database user account to connect to the instance.
You may connect through a proxy, in which case you should follow these steps:
Enable the API
Install the proxy client on your local machine
Determine how you will authenticate the proxy
If required by your authentication method, create a service account
Determine how you will specify your instances for the proxy
Start the proxy
Update your application to connect to Cloud SQL using the proxy
You can find related details on the Connecting to Cloud SQL from External Applications.
This documents provides steps that cover configuring access for IP connections as well.
If you connect from within the app engine environment, you may have a look at Connecting from App Engine.
I backed up my Cloud SQL V1 DB to a bucket and restored to a new 2nd-gen instance. Connecting via the console works fine. I can select, look at procs etc. Connecting to it from my Java GAE app doesn't. The GAE app and the Cloud SQL DB are in the same project.
I get these values in the logs:
GAE log:
java.sql.SQLInvalidAuthorizationSpecException: Not authorized to access instance: xxxx
SQL log:
[Warning] User 'root'#'%' was assigned access 0x1fffffff but was allowed to have only 0x1fff7dff.
Any tips?
Make sure your JDBC URL uses the jdbc:google:mysql:// prefix and not the old/deprecated jdbc:google:rdbms:// prefix.
While jdbc:google:rdbms:// continues to work for First Generation instances, it won't work when connecting to Second Generation instances. jdbc:google:mysql:// will work for both.
I am unable to connect to Cloud SQL from Google App Engine. I am not sure what the problem is but I came across a note from an instruction stating this is a performance Cloud SQL in alpha stage and connection from Google App Engine are not excepted. Is this the problem I am unable to connect to Cloud SQL? Can anyone explain me the the note? The screenshot of the note is below
Connecting from App Engine is not yet supported for Second Generation instances. You will need to create a First Generation instance if you must connect from App Engine.