1

I successfully created a Compute Engine VM instance, and installed MySQL on it using this guide: https://cloud.google.com/solutions/setup-mysql

Now I want to connect to it from App Engine and from my home too if possible. Using this guide: https://cloud.google.com/appengine/docs/standard/python/connecting-vpc I created the connector, giving it the suggested 10.8.0.0/28 IP address.

In my app engine's app.yaml I inserted: vpc_access_connector: name: projects/locationconnection/locations/europe-west3/connectors/vpcaccess

The VM instance shows an internal IP of 10.156.0.2 and an external IP of 34.89.141.17

I am trying to connect from PHP using this line: new mysqli($servername, $username, $password, $dbname, 3306, null); but I get different errors.

When connecting to 34.89.141.17 from my home: mysqli::__construct(): (HY000/2002): No connection could be made because the target machine actively refused it. (I even created a Firewall rule to allow all traffic from my home IP)

When connecting to 10.8.0.0 from app engine: 2002: Connection timed out

When connecting to 10.156.0.2 from app engine: 2002: Connection refused

How can I make a connection?

0

On the guide How to Set Up MySQL on Google Compute Engine shows how to setup Mysql but keep in mind Mysql has its own configuration. By the errors you mentioned the issue it's about Mysql allowing external connections. When you add a user and grant privileges to them (or with existing users) you need to specify the host or network range from which that user it's allow to connect. For example this line GRANT ALL PRIVILEGES ON *.* TO 'root'@'%' IDENTIFIED BY 'password'; grant all permissions to the root user and allow connections from root user from all host (the '%' after the @ it's a wildcard that means from all host). You can use the wildcard like this for private network 10.156.0.% The host apply for public IP's or for IP's from your private network. Check this site for more information How To Allow Remote Connections To MySQL. Keep in mind the security risk for a wide open allow host policy.

3
  • The solution was in the linked article, changing the bind-address to 0.0.0.0 in the MySQL config file made it work. I still don't know about connecting externally (if it is possible at all), but I am accepting this answer. – Balint Fodor Sep 1 '20 at 16:19
  • Yes, it's is possible, you have two options: Allow 0.0.0.0 in Mysql configuration, on the firewall add a rule allow 0.0.0.0, and run the Grant privileges statement with the host (the value after the @) with the wildcard '%'. The second option it's set your public IP (You can check your current Public IP on this link) on the Grant statement, on the Mysql configuration Allow keep 0.0.0.0 and on the firewall set a rule with your Public IP. Keep in mind the ISP rotate the Public IP. – DavidC Sep 1 '20 at 18:32
  • Thanks, I had in fact done these steps, and now that I tested it again, I am able to connect from home. – Balint Fodor Sep 1 '20 at 18:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.