1

I've configured SQL second gen. instance and App Engine application (Python 2.7) in one project. I've made necessary settings according to that page.

app.yaml

runtime: python27
api_version: 1
threadsafe: true
env_variables:
    CLOUDSQL_CONNECTION_NAME: coral-heuristic-215610:us-central1:db-basic-1
    CLOUDSQL_USER: root
    CLOUDSQL_PASSWORD: xxxxxxxxx     
beta_settings:
    cloud_sql_instances: coral-heuristic-215610:us-central1:db-basic-1
libraries:
- name: lxml
  version: latest
- name: MySQLdb
  version: latest
handlers:   
- url: /main
  script: main.app

Now as I try to connect from the app (inside Cloud Shell), the error:

OperationalError: (2002, 'Can\'t connect to local MySQL server through socket \'/var/run/mysqld/mysqld.sock\' (2 "No such file or directory")')

Direct connection works:

$ gcloud sql connect db-basic-1 --user=root

was successful...

MySQL [correction_dict]> SHOW PROCESSLIST;                                                                                                     
+--------+------+----------------------+-----------------+---------+------+----------+------------------+
| Id     | User | Host                 | db              | Command | Time | State    | Info             |
+--------+------+----------------------+-----------------+---------+------+----------+------------------+
|      9 | root | localhost            | NULL            | Sleep   |    4 |          | NULL             |
|     10 | root | localhost            | NULL            | Sleep   |    4 |          | NULL             |
| 112306 | root | 35.204.173.246:59210 | correction_dict | Query   |    0 | starting | SHOW PROCESSLIST |
| 112357 | root | localhost            | NULL            | Sleep   |    4 |          | NULL             |
| 112368 | root | localhost            | NULL            | Sleep   |    0 |          | NULL             |
+--------+------+----------------------+-----------------+---------+------+----------+------------------+

I've authorized IP to connect to the Cloud SQL instance: The IP are authorized to connect Cloud SQL instance.

Any hints, help?

1 Answer 1

1

Google AppEngine Standard provides a unix socket at /cloudsql/[INSTANCE_CONNECTION_NAME] that automatically connects you to your CloudSQL instance. All you need to do is connect to it at that address. For the MySQLDb library, that looks like this:

    db = MySQLdb.connect(
        unix_socket=cloudsql_unix_socket,
        user=CLOUDSQL_USER,
        passwd=CLOUDSQL_PASSWORD)

(If you are running AppEngine Flexible, connecting is different and can be found here)

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.