I am trying to connect to an instance of Google Cloud SQL that I created, but every attempt to connect has either resulted with an error message saying I could not connect or did not have access. I have used a cloud proxy connection, a private IP connection, and a Cloud shell connection.
I've used the cloudsql git repository as reference (https://github.com/GoogleCloudPlatform/python-docs-samples/tree/master/appengine/standard/cloudsql)
I have only changed these files in regard to my specific project and instance.
to gather the info about the connection:
CLOUDSQL_CONNECTION_NAME = os.environ.get('CLOUDSQL_CONNECTION_NAME')
CLOUDSQL_USER = os.environ.get('CLOUDSQL_USER')
CLOUDSQL_PASSWORD = os.environ.get('CLOUDSQL_PASSWORD')
to set the connection (included on git):
if os.getenv('SERVER_SOFTWARE', '').startswith('Google App Engine/'):
# Connect using the unix socket located at
# /cloudsql/cloudsql-connection-name.
cloudsql_unix_socket = os.path.join(
'/cloudsql', CLOUDSQL_CONNECTION_NAME)
db = MySQLdb.connect(
unix_socket=cloudsql_unix_socket,
user=CLOUDSQL_USER,
passwd=CLOUDSQL_PASSWORD)
else:
db = MySQLdb.connect(
host='127.0.0.1', user=CLOUDSQL_USER, passwd=CLOUDSQL_PASSWORD)
The errors I am receiving:
pymysql.err.OperationalError: (1045, "Access denied for user ''@'localhost' (using password: YES)")
and
(pymysql.err.OperationalError) (2003, "Can't connect to MySQL server on 'localhost' ([Errno 2] No such file or directory)")
I've tried just about everything. This is only one example of the many routes I have taken. Any advice or guidance would be greatly appreciated.
mysqlcommand-line tool to test. Then move to Python code. - John Hanley