使用 TCP 从 App Engine 自定义环境连接到 Google Cloud SQL 时出错
Error connecting to Google Cloud SQL from App Engine custom environment using TCP
我正在尝试从 App Engine 中的自定义运行时环境连接到 google sql 云实例。
当我按照 doc 使用 unix 域套接字进行连接时,它起作用了。问题是当我尝试使用 TCP 连接进行连接时。它显示:
Warning: mysqli_connect(): (HY000/2002): Connection refused in
/var/www/html/index.php on line 3
Connect error: Connection refused
这是我的 app.yaml 文件:
runtime: custom
env: flex
beta_settings:
cloud_sql_instances: testing-mvalcam:europe-west1:testdb=tcp:3306
resources:
cpu: 1
memory_gb: 0.5
disk_size_gb: 10
Dockerfile:
FROM php:7.0-apache
ENV PORT 8080
CMD sed -i "s/80/$PORT/g" /etc/apache2/sites-available/000-default.conf /etc/apache2/ports.conf && docker-php-entrypoint apache2-foreground
RUN docker-php-ext-install mysqli
RUN a2enmod rewrite
COPY ./src /var/www/html
EXPOSE $PORT
和index.php:
<?php
$link = mysqli_connect('127.0.0.1', 'root', 'root', 'test');
if (!$link){
die('Connect error: '. mysqli_connect_error());
}
echo 'successfully connected';
mysqli_close($link);
?>
我做错了什么?
如您正在使用的 documentation 所示(请记住单击此页面上的“TCP 连接”选项卡),在 app.yaml 与云 SQL 相关的部分需要有关数据库服务器正在使用的 TCP 端口的实例信息。
IP 地址“172.17.0.1”与网络服务器 运行 所在的 docker 容器相关,您可以在该 in this documentation.[=13= 上获得更多上下文]
如果您在 Dockerfile
的情况下进行部署,则您正在使用的文档页面可能缺少调整用例的内容。在下面的 documentation 中,您可以阅读有关 App Engine 灵活运行时的更多信息。
我正在尝试从 App Engine 中的自定义运行时环境连接到 google sql 云实例。
当我按照 doc 使用 unix 域套接字进行连接时,它起作用了。问题是当我尝试使用 TCP 连接进行连接时。它显示:
Warning: mysqli_connect(): (HY000/2002): Connection refused in
/var/www/html/index.php on line 3
Connect error: Connection refused
这是我的 app.yaml 文件:
runtime: custom
env: flex
beta_settings:
cloud_sql_instances: testing-mvalcam:europe-west1:testdb=tcp:3306
resources:
cpu: 1
memory_gb: 0.5
disk_size_gb: 10
Dockerfile:
FROM php:7.0-apache
ENV PORT 8080
CMD sed -i "s/80/$PORT/g" /etc/apache2/sites-available/000-default.conf /etc/apache2/ports.conf && docker-php-entrypoint apache2-foreground
RUN docker-php-ext-install mysqli
RUN a2enmod rewrite
COPY ./src /var/www/html
EXPOSE $PORT
和index.php:
<?php
$link = mysqli_connect('127.0.0.1', 'root', 'root', 'test');
if (!$link){
die('Connect error: '. mysqli_connect_error());
}
echo 'successfully connected';
mysqli_close($link);
?>
我做错了什么?
如您正在使用的 documentation 所示(请记住单击此页面上的“TCP 连接”选项卡),在 app.yaml 与云 SQL 相关的部分需要有关数据库服务器正在使用的 TCP 端口的实例信息。
IP 地址“172.17.0.1”与网络服务器 运行 所在的 docker 容器相关,您可以在该 in this documentation.[=13= 上获得更多上下文]
如果您在 Dockerfile
的情况下进行部署,则您正在使用的文档页面可能缺少调整用例的内容。在下面的 documentation 中,您可以阅读有关 App Engine 灵活运行时的更多信息。