Cloud SQL Proxy error - An attempt was made to access a socket in a way forbidden by its access permissions
Asked Answered
P

7

14

This is the error that comes up when I try to use Cloud SQL Proxy to configure access to Google Cloud SQL in windows - "listen tcp 127.0.0.1:3306: bind: An attempt was made to access a socket in a way forbidden by its access permissions."

This is the format of the command I'm using "cloud_sql_proxy.exe -dir=/cloudsql -instances=my-project:us-central1:sql-instance=tcp:3306 mysql -u --host " - as is described in the docs.

Can someone please let me know what's actually causing this ?

Puett answered 18/3, 2016 at 13:19 Comment(0)
D
31

The SQL Server engages the 3306 port locally. Therefore you cannot bind to it while it's running. Stop the SQL Server to bind the CloudSQL Proxy to it.

Incase of Windows 10: Go to Task Manager -> Services -> MySQL57

Right click and stop that task. Once you have done that try running the same command again. It'll work and show as output

Listening on 127.0.0.1:3306 for <instance-name>
Dinesen answered 4/4, 2018 at 15:59 Comment(4)
Almost half a decade later and worked like a charm. Thanks, Maverick!Min
saved my life, in case someone uses postgresql the same procedure applies to the postgresql processHelium
Doesn't work for me.Carboloy
deploying to app engine with postgres and trying to do local connect via cloud sql proxy for dev came across same issue, as mentioned above worked for postgress as well!!!! description of service to shut down was = postgresql-x64-15. gluck!Tiffany
S
17

It sounds like another process is already using 3306. Can you try specifying a different port? e.g. -instances=my-project:us-central1:sql-instance=tcp:3307

Stook answered 18/3, 2016 at 16:22 Comment(4)
Sorry for the earlier comment, it didn't work. I'm getting this error - "ERROR 2003 (HY000): Can't connect to MySQL server on 'ip-addr' (10060)".Puett
This is what I get on the windows command prompt when I run Cloud SQL proxy - <br/> 2016/03/19 13:55:52 listenInstance: "my-project:us-central1:sql-instance=tcp:3307" <br/> 2016/03/19 13:55:52 Open socket for "my-project:us-central1:sql-instance" at "localhost:3307" <br/> 2016/03/19 13:55:52 Socket prefix: c:\cloudsql <br/> And the cursor just keeps blinking....Puett
What version of Windows? Are you using the pre-compiled version of the Proxy from the website or are you building it yourself?Stook
OS - Windows 7 64 Bit. I'm using the pre-compiled 64-bit versiionPuett
E
1

As per the google docs use this command on windows cmd or google sdk shell cloud_sql_proxy.cmd -instances=<INSTANCE_CONNECTION_NAME>=tcp:3306 -credential_file=<PATH_TO_KEY_FILE> (make sure to declare cloud_sql_proxy.cmd as environment variable)where in your case

  • INSTANCE_CONNECTION_NAME = my-project:us-central1:sql-instance
  • PATH_TO_KEY_FILE = create a service account in IAM panel and save the json file copy its path and paste it here.

if this doesnt work try connecting tcp to 3307 as mentioned in above post.

Ecdysiast answered 27/6, 2017 at 20:39 Comment(0)
K
0

I my case I was using docker image with the same port installed in my local machine so the local mysql is not allowing to access the port because is already been used and running. I Uninstall local mysql .now its working fine

Kyoko answered 4/5, 2021 at 6:5 Comment(0)
K
0

you need a token to sql cloud you van generate the token here google service token generator and then take the token it will generate and put it here while INSTANCE_CONNECTION_NAME is can be taken from the the sql instanse overview page in google cloud console

cloud_sql_proxy -token=ACCESS_TOKEN
-instances=INSTANCE_CONNECTION_NAME=tcp:PORT_NUMBER

see in docs for more details sql proxy auth more way to connect

to me it solve the 400 bad request problem

Response: {
 "error": "invalid_grant",
  "error_description": "Bad Request"
}

pay attention - if you use this way to connect you must allow unsafe connecteion in the sql instanse config page

Kwang answered 21/2, 2022 at 16:16 Comment(0)
W
0

Go to Task Manager -> Services -> MySQL57 stop your Mysql or your Postgres instances retry again .It should work.

Weep answered 17/2, 2023 at 8:3 Comment(0)
C
0

I'm using Windows 10

It works after I stopped all my local Postgres Services in Services Management

enter image description here

Cand answered 18/8, 2023 at 3:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.