PDOException'带有消息 'SQLSTATE[HY000] [2002] 连接超时'尝试连接到谷歌云 sql 时 [英] PDOException' with message 'SQLSTATE[HY000] [2002] Connection timed out' when trying to connect to google cloud sql

查看:74
本文介绍了PDOException'带有消息 'SQLSTATE[HY000] [2002] 连接超时'尝试连接到谷歌云 sql 时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

各位会员
所以我试图从外部站点连接到谷歌云 sql

Hie members
so I was trying to connect to Google cloud sql from an external site

我在 Instance -> Access Control -> Authorization 处授权了 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.

这篇关于PDOException'带有消息 'SQLSTATE[HY000] [2002] 连接超时'尝试连接到谷歌云 sql 时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆