Search code examples
phpgoogle-app-enginegoogle-cloud-sql

Could not connect to Google cloud SQL. Using PHP Google SDK


I did read this tutorial https://developers.google.com/appengine/docs/php/cloud-sql/ I had created a Instance with name schoolnbd and my project id is myapplication-2013 After reading the tutorial I tried the code below

<?php
$dhost=":/cloudsql/myapplication-2013:schoolnbd";
$duser="root";
$dpassword="xxxyyy";
$database="schoolnbd";
$connection=mysql_connect($dhost, $duser, $dpassword) or die("Could not Connect to SQL Server Suleman");
$db=mysql_select_db($database, $connection) or die(" Check the Database Name from Config.php , wrong database entered ");
?>

But it is showing “Could not Connect to SQL Server Suleman”. I had created one user by name suleman and made several changes , but still it is not connecting to SQL server, i am seeing same message. I had tried doing many changes such as

try 1

$dhost=":/cloudsql/myapplication-2013:schoolnbd";
$duser="suleman";

try 2

$dhost="localhost";
$duser="root";

try 3

$dhost=":/myapplication-2013:schoolnbd";
$duser="root";

try 4

$dhost=":/cloudsql/myapplication-2013:myapplication-2013:schoolnbd";
$duser="root";

try 5

$dhost=":/cloudsql/myapplication-2013:myapplication-2013:schoolnbd";
$duser="suleman";

Error from the error log is it is Showing mysql_connect(): Access denied for user 'root'@'localhost' (using password: YES) in /base/data/home/apps/s~myapplication-2013/1.371632998623546850/test.php on line 6

when I am using

$dhost=":/cloudsql/myapplication-2013:schoolnbd";
$duser="root";

Solution

  • i also faced the same problem, try without using password, it like this it will most probably work

    $dhost=":/cloudsql/myapplication-2013:schoolnbd";
    $duser="root";
    $dpassword="";
    

    but keep in mind , if you had set your root password then you should update root password, by typing this in console.

    SET PASSWORD FOR 'root' = PASSWORD('');