doukangbin9698 2018-10-08 14:25
浏览 59
已采纳

没有代理的相同GCP项目的GCP CloudSQL访问

I'm totally stumped on what I think is probably something easy. Been searching for days on this with no luck as I learn how to use Cloud SQL. There are lots of examples on app engine, but almost none on the simplicity of connecting a GCP Virtual Machine to GCP Cloud SQL. The instructions from Google don't seem to be complete. Here is what I have:

In the same GCP Project I created a Bitnami LAMP VM. In the same project I've created a CloudSQL Instance with a single database, and two tables. My intent is to experiment with accessing CloudSQL via a PHP script from the VM. (Yes I know I could setup an SQL server on the VM, but my intent here is to learn how to access CloudSQL). Note, everything is in the same GCP project, so from what I can understand I should NOT have to use the SQL proxy.

I've enabled the CloudSQL API in the project as well.

<?php
$DB_NAME = "dwelling_winebot";
$DB_USER = "winebot_reader";
$DB_PASS = "winebot_reader";
$tableName = "wines";
$mysqli = new mysqli(null, $DB_USER, $DB_PASS, $DB_NAME,null, "/cloudsql/web-sites-123456:us-central1:winebot");

... More code below

The error I get in the apache error_log is:

[08-Oct-2018 05:00:24 America/Los_Angeles] PHP Warning:  mysqli::__constru
ct(): (HY000/2002): No such file or directory in /opt/bitnami/apache2/htdo
cs/winebot/serverside/inforunner.php on line 25

(Incidentally, line 25 is the $mysqli line and the php filename is inforunner.php that has the php code above )

Notable facts:

  • I CAN see the database instance if I run "gcloud sql instances
    describe winebot"
    • I have created a user named winebot_reader... Saying this I also tried 'root' with a "" password as some documents suggested. No luck.
    • The cloudsql instance name is infact the right project name, zone, and database from the console.
    • I do not seem to have a local /cloudsql folder with socket paths as some documents suggest I should have?
    • According to the console, the CloudSQL API is turned on
    • In the location field of the mysqli call (first parameter) I have tried, null, localhost, 127.0.0.1. All with the same result.

Any help would be greatly appreciated.

  • 写回答

1条回答 默认 最新

  • douwen3965 2018-10-08 15:48
    关注

    use the internal IP instead of a socket, which does not exist.

    see Connecting MySQL Client from Compute Engine for reference.

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

报告相同问题?

悬赏问题

  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败
  • ¥15 ZABBIX6.0L连接数据库报错,如何解决?(操作系统-centos)
  • ¥15 找一位技术过硬的游戏pj程序员
  • ¥15 matlab生成电测深三层曲线模型代码
  • ¥50 随机森林与房贷信用风险模型