dougao7801 2019-07-04 16:40
浏览 67
已采纳

PHP超时连接到Cloud SQL实例

Here is my code for PHP for connecting to the database, a Cloud SQL instance for MySQL:

define('DB_SERVER', '192.0.0.1');
define('DB_USERNAME', 'username');
define('DB_PASSWORD', 'password');
define('DB_NAME', 'db');

$db = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME) or die(mysqli_connect_error());

Obviously the DB_SERVER is not the actual IP address, nor are the credentials, but I did put in a dummy one to see if I needed to add anything like cloudsql:/ or jdbc:// like you do in Java.

I did authorize the IP address for the webserver on Cloud SQL, but all it returns is a Connection Timed Out error; What can I do to fix this?

I'm certain that the credentials are correct, and that I can connect from other authorized IP addresses, as I have been able to access from another account & multiple IP addresses through the MySQL workbench.

  • 写回答

1条回答 默认 最新

  • dousi1970 2019-07-06 13:33
    关注

    Solved:

    For anyone using Siteground's services, make sure to add 0.0.0.0/0 as the accepted IP addresses if you're using public IP authorization. Then find what IP's are connected when you refresh the php page by running this right after the page is refreshed:

    SELECT host FROM information_schema.processlist WHERE ID=connection_id();
    

    It should give you multiple IPs, and check them online using an IP locator to see if they match the location of the Siteground's services. Remove 0.0.0.0/0 and add that IP address to Google Cloud SQL.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?