问题描述
Hie成员
所以我试图从外部站点连接到Google Cloud sql
Hie members
so I was trying to connect to Google cloud sql from an external site
我已在Instance->访问控制->授权中授权了Google Cloud中服务器的IP地址
I authorized the ip of the server in google cloud at Instance -> Access Control -> Authorization
并且实例也被分配了IP,比如说"X.X.X.X",并且还使用用户名"username"和密码"password"创建了一个用户
and the instance also has been assigned an IP lets say 'X.X.X.X',and a user also has been created with User name 'username' and password 'password'
现在,我用于连接Google Cloud sql的连接代码如下
now the connection code for connecting google cloud sql I used is as follows
$db = new pdo('mysql:host=X.X.X.X;dbname=db','username','password');
,我尝试打开页面,但出现以下错误
and I tried opening the page and I am getting the following error
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY000] [2002] Connection timed out' in /home/kannadakavana/public_html/test.php:17 Stack trace: #0 /home/kannadakavana/public_html/test.php(17): PDO->__construct('mysql:host=X....', 'username', '') #1 {main} thrown in /home/kannadakavana/public_html/test.php on line 17
我在做什么错了?
推荐答案
默认情况下,Cloud SQL实例未启用IPv4.
By default Cloud SQL instances does not have IPv4 enable.
您启用了IPv4地址吗?在访问控制> IP地址选项卡下.
Did you enable IPv4 address? It is under Access Control > IP address tab.
这篇关于尝试连接到Google Cloud SQL时出现消息"SQLSTATE [HY000] [2002]连接超时"的PDOException的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!