Home:ALL Converter>Python's sqlalchemy on Google CLoud SQL

Python's sqlalchemy on Google CLoud SQL

Ask Time:2018-11-09T16:19:12         Author:James Pinkerton

Json Formatter

I'm attempting to connect to a Google Cloud SQL instance with sqlalchemy in order to use the Pandas to_sql function. My instance has an internal IP Address.

I got the following to work:

import MySQLdb

def get_con():
    return MySQLdb.connect(host='<IP Address>', user='root')

However when I use sqlalchemy:

import sqlalchemy

def get_con():
    s = 'mysql://root@<IP Address>'
    engine = sqlalchemy.create_engine(s)
    return engine.connect()

I get the following error:

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

Author:James Pinkerton,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/53222061/pythons-sqlalchemy-on-google-cloud-sql
yy