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 VS2022+WDK驱动开发环境
  • ¥30 关于#java#的问题,请各位专家解答!
  • ¥30 vue+element根据数据循环生成多个table,如何实现最后一列 平均分合并
  • ¥20 pcf8563时钟芯片不启振
  • ¥20 pip2.40更新pip2.43时报错
  • ¥15 换yum源但仍然用不了httpd
  • ¥50 C# 使用DEVMOD设置打印机首选项
  • ¥15 麒麟V10 arm安装gdal
  • ¥20 OPENVPN连接问题
  • ¥15 flask实现搜索框访问数据库