1

I cannot connect to MySQL from Google cloud compute engine to MySQL storage. When I go to 172.146.221.156/test.php on browser showing an error message like this

Warning: mysqli_connect(): (HY000/2002): Permission denied in /var/www/html/test.php on line 21 Connect Error (2002'

My config file is:

<?php
$conn = mysqli_connect("176.154.226.114", "root", "password");
if (!$conn) 
{
    die('Connect Error (' .mysqli_connect_errno());
}
?>

What am I doing wrong?

NoNaMe
  • 6,020
  • 30
  • 82
  • 110
  • Possible duplicate of [Connect DATABASE Error TYPE: 2002: Permission denied](https://stackoverflow.com/questions/41178774/connect-database-error-type-2002-permission-denied) – taiff Jul 27 '18 at 06:52

3 Answers3

0

Have you setup security in your Cloud SQL instance? The ip of the compute engine instance should be whitelisted in your cloud sql instance. You can find it under Access control --> Authorized networks

  • Yes. My public is in white listed. Now i am facing another issue. I can connect with mysql_connect(). But i cannot connect with mysqli_connect(). What will be the reason?? Does anyone know how? – Dinesh Dhananjayan Nov 26 '15 at 10:34
-1

I'm running on CentOS 7 and ran into the same problem until I found the following post: Connect DATABASE Error TYPE: 2002: Permission denied

Basically setsebool -P httpd_can_network_connect_db 1

That solved my problem without disabling SELinux.

Hope it helps.

taiff
  • 89
  • 8
-1

in your google cloud => go to sql=> click on your instance => connections => Public IP add 0.0.0.0/0 as an allowed network then save.

or write in google my ip and add it if you want only you have a remotely access.