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 微信会员卡等级和折扣规则
  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分