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

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

问题描述

安装drupal 7时出现以下错误:

I'm getting the following error installing drupal 7:

无法连接到数据库服务器。服务器报告以下消息:SQLSTATE [HY000] [2003]无法连接到 myservername(13)上的MySQL服务器。

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).

我正在一个MySQL上运行MySQL Windows Server和另一个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将不会强制执行这种严格的Web服务器行为。

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天全站免登陆