简体   繁体   中英

connect to remote mysql server from google cloud

I have a google cloud machine which has an ubuntu Os, I have MySQL database on another server, I opened the remote connection on my SQL server, and I connect to my database from any machine else from my google cloud machine I can not, it taking long time then I have a timeout connection problem. I think the problem is from firewall rules, so I applied this command to create rule that allow 3306 port

cloud compute firewall-rules create "mysql-remote-access" --allow tcp:3306 --source-tags "mysql-client" --target-tags "mysql-server"

but still, I can not connect to a remote MySQL server
from where can I enable it, thank you

I think your firewall rules is not correct. This one should solve the issue

gcloud compute firewall-rules create "mysql-remote-access" \
--direction=EGRESS --action=ALLOW --rules=tcp:3306 \
--destination-ranges=xxx.xxx.xxx.xxx/32 --target-tags=mysql-client

Short description: You allow the EGRESS traffic on port 3306 to the destination xxx.xxx.xxx.xxx for the traffic coming from the VM with the tag "mysql-client"

By default all the outgoing communication are allowed , but you might have a rule with higher priority that prevents this

Implied allow egress rule. An egress rule whose action is allow, destination is 0.0.0.0/0, and priority is the lowest possible (65535) lets any instance send traffic to any destination, except for traffic blocked by Google Cloud.

It the rule doesn't work, share all your existing firewall rules.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM