"Can't connect to MySQL server on 'localhost' ([Errno 111] Connection refused)")

5,203 views
Skip to first unread message

Dmitry Margolin

unread,
Apr 7, 2021, 11:45:36 AM4/7/21
to Google Cloud SQL discuss
My application is running.
I can run it and connect locally when point to ip on CloudSql
SQLALCHEMY_DATABASE_URI = "mysql+pymysql://{}:{}@{}/{}".format(db_user,db_pass,db_host,db_name)

When I change it and run it on server:
SQLALCHEMY_DATABASE_URI = "mysql+pymysql:///unix_socket=/{}/{}".format(db_user,db_pass,db_name,db_socket_dir,cloud_sql_connection_name)

I got:

sqlalchemy.exc.OperationalError: (pymysql.err.OperationalError) (2003, "Can't connect to MySQL server on 'localhost' ([Errno 111] Connection refused)")

wokmou

unread,
Apr 9, 2021, 9:04:55 PM4/9/21
to Google Cloud SQL discuss
Looking at some public forums [1][2] , I found some valid reasons why you may experiencing this error.  Mostly related to your MySQL server only listening the localhost interface or db user’s privileges. 

Reply all
Reply to author
Forward
0 new messages