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.

  1. specify public (external) ip address host parameter, rather unix_socket.
  2. replace mysqldb pymysql. in particular, want copy pymysql directory github repo application directory. using pymysql means don't need add mysqldb libraries: section of app.yaml.
  3. 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'): 
  4. 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

Popular posts from this blog

Hatching array of circles in AutoCAD using c# -

ios - UITEXTFIELD InputView Uipicker not working in swift -

Python Pig Latin Translator -