Drupal 安装无法连接到 MySQL 服务器,但它在那里 [英] Drupal Installation can't connect to MySQL server but it's there

查看:20
本文介绍了Drupal 安装无法连接到 MySQL 服务器,但它在那里的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在安装 drupal 7 时遇到以下错误:

I'm getting the following error installing drupal 7:

无法连接到您的数据库服务器.服务器报告以下消息:SQLSTATE[HY000] [2003] Can't connect to MySQL server on 'myservername' (13).

Failed to connect to your database server. The server reports the following message: SQLSTATE[HY000] [2003] Can't connect to MySQL server on 'myservername' (13).

我在一台 Windows 服务器上运行 MySQL,在另一台 Linux 上运行 httpd.MySQL 运行良好,在 httpd 服务器上我可以很好地连接到 MySQL,如下所示:

I am running MySQL on one windows server and httpd on another linux. MySQL is running just fine and on the httpd server I can connect just fine to the MySQL, as follows:

mysql -h dbserver -p --port=3001 -u drupal

mysql -h dbserver -p --port=3001 -u drupal

同样,我可以运行 mysqli 和 pdo,并且从我的 httpd 连接也很好:

Similarly I can run mysqli and pdo and it connection just fine too from my httpd:

<?php
$servername = "dbserver";
$username = "drupal";
$password = "xxx";
$dbname = "drupal";
$port = 3001;

$conn = new mysqli($servername, $username, $password, $dbname, $port);

if ($conn->connect_error) {
     die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
$conn->close();

try {
    $conn = new PDO("mysql:host=$servername;dbname=$dbname;port=$port", $username, $password);
    // set the PDO error mode to exception
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    echo "Connected successfully";
    }
catch(PDOException $e)
    {
    echo "Connection failed: " . $e->getMessage();
    }
$conn=null;
 ?>

所以我的 Web 服务器或 php 或 mysql 上没有任何问题.它只是通过安装失败.我已经进入高级并输入了所有正确的详细信息.

So there is nothing wrong on my web server or php or mysql. It's just through the installation that it fails. I've been in the advanced and entered all the correct details.

有什么想法吗?我看了看,没有 apache 日志,我无法弄清楚如何在安装期间增加错误报告或找到它在哪里进行数据库连接检查..

Any idea? I looked and there was no apache log and I couldn't figure out how to increase error reporting during install or find exactly where it does the database connection check..

谢谢.

推荐答案

你能确认你已经映射了 dbserver 的 ip.转到终端并输入:ping dbserver",然后发布结果.

Can you confirm you have dbserver's ip mapped. Go to terminal and type : "ping dbserver" and please post result.

已这种情况是由 linux 发行版的安全策略引起的,其中设置了 apache 服务器,不允许它连接到远程 mysql 实例.为了解决这种情况,请转到终端并输入 sudo setenforce 0,这样 linux 就不会强制执行如此严格的网络服务器行为.

EDITED: This situation was caused by a security policy of the linux distro where the apache server is setup that doesn't allow it to connect to remote mysql instances. For solving this situation go to terminal and type sudo setenforce 0, that way linux won't enforce such strict webserver behaviour.

这篇关于Drupal 安装无法连接到 MySQL 服务器,但它在那里的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆