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")')