简体   繁体   中英

(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. I get the following from ALL servers, even if the IP address is whitelisted:

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. PID=11692 in C:\\Users\\admin\\app\\dbtest.php on line 3

Warning: PDO::__construct(): MySQL server has gone away in C:\\Users\\admin\\app\\dbtest.php on line 3

Warning: PDO::__construct(): Error while reading greeting packet. 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

Here is my PHP script to connect:

<?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?

The database endpoint in such format app.database.windows.net;port=1433 is the endpoint of Azure SQL which provides the SQL Server service. Not MySQL. Please try to install the SQL Server driver for windows at https://www.microsoft.com/en-us/download/details.aspx?id=20098 . And then try to use new PDO( "sqlsrv:server=$serverName ; Database=AdventureWorks", "{user}", "{pass}"); to connect to 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.

Any further concern, please feel free to let me know.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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