I have a simple test script to ensure I can connect to and read/write using GCF to Google Cloud SQL instance.
def update_db(request):
import sqlalchemy
# connect to GCP SQL db
user = 'root'
pw = 'XXX'
conn_name = 'hb-project-319121:us-east4:hb-data'
db_name = 'Homebase'
url = 'mysql+pymysql://{}:{}@/{}?unix_socket=/cloudsql/{}'.format(user,pw,db_name,conn_name)
engine = sqlalchemy.create_engine(url,pool_size=1,max_overflow=0)
# Returns
return f'Success'
This is successful but when I try to add a connection:
conn = engine.connect()
I get the following error:
pymysql.err.OperationalError: (1045, "Access denied for user 'root'@'cloudsqlproxy~' (using password: YES)")
Seems odd that engine can be created but no connection can be made to it? Worth noting that any kind of execute using the engine, e.g. engine.execute('select * from table limit 3') will also lead to the error above.
Any thoughts are appreciated. Thanks for your time
Cheers, Dave