python 2.7 - Connecting with mysql server running on Compute Engine instance from GAE -
how communicate mysql server running on compute engine instance google app engine? using google app engine frontend. want host our database on mysql server running on compute engine. there way achieve this?
we have gone through this: https://cloud.google.com/solutions/mysql-remote-access
code snippet:
if (os.getenv('server_software') , os.getenv('server_software').startswith('google app engine/')): db=mysqldb.connect(host="internalip", port=3306, db='test_database', user='root',passwd="db_password") else: db = mysqldb.connect(host='127.0.0.1', port=3306, db='test_database', user='root', charset='utf8') cursor = db.cursor() logging.info("hey there looks connected")
igor's comment above hints at how working; i've managed produce working app, following changes documented solution.
- specify public (external) ip address
host
parameter, ratherunix_socket
. - replace mysqldb
pymysql
. in particular, want copypymysql
directory github repo application directory. usingpymysql
means don't need addmysqldb
libraries:
section of app.yaml. in
connections.py
, around line 52, change following line:if _py_version == (2, 7) , not ironpython
to
if _py_version == (2, 7) , not ironpython , not os.getenv('server_software', '').startswith('google app engine'):
you may need change mysql permission grants in mysql allow access the app engine source ip addresses.
the reason workaround needed app engine sockets library not implement of async io primitives used _socketio
wrapper in pymysql
. @ same time, mysqldb
module shipped app engine wraps c library not know how use app engine sockets
library (and not have socket support compiled in).
i'll see if latter combination can addressed, in meantime, above 3 steps should provide workaround can used connect either own mysql or version 2 of cloud sql.
Comments
Post a Comment