MySQL随机无法连接消息


MySQL random unable to connect messages

我有一个Apache服务器,它连接到MySQL数据库服务器。我得到很多错误信息说:

PHP警告:mysqli::mysqli(): (HY000/2003): cannot connect to MySQL server on '10.0.0.13'

但是大多数时候,连接没有问题,我可以毫无问题地连接到telnet 10.0.0.13 3306。我怎么知道问题是什么?

源代码是php脚本,大多数时候它运行没有任何问题。以下是我的连接方式:

error_reporting(E_ALL ^ E_NOTICE);
ini_set('display_errors','On');
date_default_timezone_set ('Europe/Copenhagen');
Header('Content-type: text/xml');
$conn = new mysqli('10.0.0.13','webuser', 'xxxxxx', "np_indexes");

有什么建议吗?

连接关闭正确吗?

$sql = "call spGetOrderDepthBySymbol('$stock', 0)";
    $result = $conn->query($sql);
    while($row = $result->fetch_assoc()) { ?>
        <row>
            <type static="true"></type>
            <shares flash="true"><?= $row['shares']<>"" ? number_format($row['shares'], 0, ',', '.') : '-' ?></shares>
            <price flash="true"><?= $row['price']<>"" ? number_format($row['price'], 2, ',', '.') : '-' ?></price>
        </row>
    <? }
    ?>
    <spacer static="true"></spacer>
    <? 
    $conn->next_result();
    $sql = "call spGetOrderDepthBySymbol('$stock', 1)";
    $result = $conn->query($sql);
    while($row = $result->fetch_assoc()) { ?>
        <row>
            <type static="true"></type>
            <shares flash="true"><?= $row['shares']<>"" ? number_format($row['shares'], 0, ',', '.') : '-' ?></shares>
            <price flash="true"><?= $row['price']<>"" ? number_format($row['price'], 2, ',', '.') : '-' ?></price>
        </row>
    <? } 
    mysql_close($result);
    ?>

也许这就是你的情况。看到

解为:login as root and do setsebool -P httpd_can_network_connect=1

如果您的MySQL服务器在Windows上工作-阅读本节:http://dev.mysql.com/doc/refman/5.1/en/can-not-connect-to-server.html#can-not-connect-to-server-on-windows