Connecting to a remote MySQL database on Google app engine

前端 未结 4 2147
北荒
北荒 2020-12-20 02:10

I\'m working on an application to run on Google app engine. Normally, I would have to enable billing/pay if am using Google Cloud SQL. So for a start, I decided to connect r

相关标签:
4条回答
  • 2020-12-20 02:12

    This is same issue with me, but Unfortunately I did it.

    This is example of my app.yaml

    runtime: php72
    env_variables:
        LOG_CHANNEL: stackdriver
        ## Put production environment variables here.
        APP_KEY: YOUR_APP_KEY
        APP_STORAGE: /tmp
        VIEW_COMPILED_PATH: /tmp
        SESSION_DRIVER: cookie
        ## Set these environment variables according to your CloudSQL configuration.
        DB_DATABASE: YOUR_DB_NAME
        DB_USERNAME: YOUR_DB_USERNAME
        DB_PASSWORD: YOUR_DB_PASSWORD
        DB_CONNECTION: mysql
        DB_HOST: YOUR_DB_PUBLIC_AP_ADDRESS
        DB_PORT: 3306
    

    If you use remote mysql in cPanel don't forget to add access host in cPanel menu and the Host (% wildcard is allowed) fill usin: %.%.%.% and add.

    And then you can fix this issue…

    0 讨论(0)
  • 2020-12-20 02:19

    What Stuart Langley said also applies to Python.

    You must have bill enabled to use remote sockets. But from my experiment, the MySQLdb included with the App Engine runtime seems not working with external MySQL database.

    You can use the pure python library mysql-connector-python provided by Oracle instead. But be warned, the latency is high (if you open a new connection per request the total latency can be 5 seconds plus). Maybe because the remote socket is not a native implementation but rather a proxy or service under the hook.

    0 讨论(0)
  • 2020-12-20 02:25

    In 1.8.8 we made it possible to use remote sockets from PHP.

    You'll need to make sure your application has billing enabled for remote sockets to be available. Once you do that you should be able to connect to a remote MySQL database from your app engine app.

    0 讨论(0)
  • 2020-12-20 02:36

    Unfortunately, App Engine does not support External calls:

    An App Engine application cannot:

    write to the filesystem. PHP applications can use Google Cloud Storage for storing persistent files. Reading from the filesystem is allowed, and all application files uploaded with the application are available.

    open a socket or access another host directly. An application can use the App Engine URL fetch service to make HTTP and HTTPS requests to other hosts on ports 80 and 443, respectively.

    respond slowly. A web request to an application must be handled within a few seconds. Processes that take a very long time to respond are terminated to avoid overloading the web server.

    make other kinds of system calls.

    0 讨论(0)
提交回复
热议问题