简体   繁体   English

(Azure) MySQL:MySQL 服务器已经消失

[英](Azure) MySQL: MySQL Server Has Gone Away

Following the guide on Azure, configuring the firewall settings , I am still unable to access my MySQL database.按照Azure 上指南, 配置防火墙设置,我仍然无法访问我的 MySQL 数据库。 I get the following from ALL servers, even if the IP address is whitelisted:即使 IP 地址已列入白名单,我也会从所有服务器获得以下信息:

PHP Warning: PDO::__construct(): MySQL server has gone away in C:\\Users\\admin\\app\\dbtest.php on line 3 PHP Warning: PDO::__construct(): Error while reading greeting packet. PHP 警告:PDO::__construct():MySQL 服务器在 C:\\Users\\admin\\app\\dbtest.php 中第 3 行消失了 PHP 警告:PDO::__construct():读取问候包时出错。 PID=11692 in C:\\Users\\admin\\app\\dbtest.php on line 3 PID=11692 在 C:\\Users\\admin\\app\\dbtest.php 第 3 行

Warning: PDO::__construct(): MySQL server has gone away in C:\\Users\\admin\\app\\dbtest.php on line 3警告:PDO::__construct(): MySQL 服务器在 C:\\Users\\admin\\app\\dbtest.php 中第 3 行消失了

Warning: PDO::__construct(): Error while reading greeting packet.警告:PDO::__construct():读取问候包时出错。 PID=11692 in C:\\Users\\admin\\app\\dbtest.php on line 3 Error connecting to SQL Server.PDOException Object ( [message:protected] => SQLSTATE[HY000] [2006] MySQL server has gone away [string:Exception:private] => [code:protected] => 2006 [file:protected] => C:\\Users\\admin\\app\\dbtest.php [line:protected] => 3 [trace:Exception:private] => Array ( [0] => Array ( [file] => C:\\Users\\admin\\app\\dbtest.php [line] => 3 [function] => __construct [class] => PDO [type] => -> [args] => Array ( [0] => mysql:dbname=mydb;host=app.database.windows.net;port=1433 2 => admin 2 => pass ) ) ) [previous:Exception:private] => [errorInfo] => ) 1 Process finished with exit code 0 PID=11692 in C:\\Users\\admin\\app\\dbtest.php on line 3 Error connected to SQL Server.PDOException Object ( [message:protected] => SQLSTATE[HY000] [2006] MySQL 服务器已经消失 [string:异常:私有] => [代码:受保护] => 2006 [文件:受保护] => C:\\Users\\admin\\app\\dbtest.php [line:protected] => 3 [trace:Exception:private] => Array ( [0] => Array ( [file] => C:\\Users\\admin\\app\\dbtest.php [line] => 3 [function] => __construct [class] => PDO [type] => - > [args] => Array ( [0] => mysql:dbname=mydb;host=app.database.windows.net;port=1433 2 => admin 2 => pass ) ) ) [previous:Exception:private] => [errorInfo] => ) 1 进程完成,退出代码为 0

Here is my PHP script to connect:这是我要连接的 PHP 脚本:

<?php
try {
    $conn = new PDO("mysql:dbname=db;host=app.database.windows.net;port=1433", "admin", "pass");

    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch (PDOException $e) {
    print("Error connecting to SQL Server.");
    die(print_r($e));
}

What are general connection settings required to connect to an Azure MySQL database without the connection timing out?在没有连接超时的情况下连接到 Azure MySQL 数据库需要哪些常规连接设置?

The database endpoint in such format app.database.windows.net;port=1433 is the endpoint of Azure SQL which provides the SQL Server service.格式为app.database.windows.net;port=1433的数据库端点是提供 SQL Server 服务的 Azure SQL 的端点。 Not MySQL.不是 MySQL。 Please try to install the SQL Server driver for windows at https://www.microsoft.com/en-us/download/details.aspx?id=20098 .请尝试在https://www.microsoft.com/en-us/download/details.aspx?id=20098上安装适用于 Windows 的 SQL Server 驱动程序。 And then try to use new PDO( "sqlsrv:server=$serverName ; Database=AdventureWorks", "{user}", "{pass}");然后尝试使用new PDO( "sqlsrv:server=$serverName ; Database=AdventureWorks", "{user}", "{pass}"); to connect to Azure SQL.连接到 Azure SQL。

If you want to use MySQL BaaS on Azure, you can refer to https://azure.microsoft.com/en-us/documentation/articles/store-php-create-mysql-database/ for detailed steps.如果你想在 Azure 上使用 MySQL BaaS,你可以参考https://azure.microsoft.com/en-us/documentation/articles/store-php-create-mysql-database/详细步骤。

Any further concern, please feel free to let me know.任何进一步的问题,请随时告诉我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM