Magento 实例指向错误的数据库

发布于 2024-10-09 00:38:01 字数 461 浏览 0 评论 0原文

有人遇到过这个问题吗? local.xml已被修改。 core_config_data 表已针对不安全和安全 url 以及 cookie 域进行了修改。缓存目录已被清除,会话值已被清除,日志表已被截断。

它受到版本控制和颠覆。 还运行 find 来查找可能获取生产数据库 IP 的位置。

find ~/path/to/application -type f -print0 | xargs -0 grep -l "IP Of incorrect DB"

但仍然在数据库上抛出错误

SQLSTATE[HY000] [2003] Can't connect to MySQL server on 'IP of incorrect DB' (4)

非常困惑,我一生都无法找到可能将生​​产数据库的 IP

local.xml 指向开发地址的位置。

Anyone ever have this problem?
local.xml has been modified. core_config_data table has been modified for unsecure and secure url as well as cookie domain. Cache dirs have been wiped clean, session values have been cleared, log tables have been truncated.

it is under version control with subversion.
have also run find to locate where it could possibly be getting the production DB IP.

find ~/path/to/application -type f -print0 | xargs -0 grep -l "IP Of incorrect DB"

yet still throwing an error on DB

SQLSTATE[HY000] [2003] Can't connect to MySQL server on 'IP of incorrect DB' (4)

Extremely baffled and can not for the life of me locate where it would possibly be getting the production DB's IP

local.xml points to development address.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

各空 2024-10-16 00:38:01

您可能想要检查 magento/var/ 目录以及所有子目录是否可由 Web 服务器写入。如果这些目录不可写,Magento 使用 /tmp/ ,这可能会导致奇怪的效果,甚至与其他 Magento 站点发生冲突。

You might want to check that the magento/var/ directory, as well as all subdirectories, are writable by the web server. If those directories are not writable Magento uses /tmp/ which can cause strange effects and even conflict with other Magento sites.

灯角 2024-10-16 00:38:01

确保您正在编辑您认为正在编辑的配置文件。看一下下面的代码

#File: app/code/core/Mage/Core/Model/Config.php

public function loadBase()
{
    $etcDir = $this->getOptions()->getEtcDir();
    $files = glob($etcDir.DS.'*.xml');
    $this->loadFile(current($files));
    while ($file = next($files)) {
        $merge = clone $this->_prototype;
        $merge->loadFile($file);
        $this->extend($merge);
    }
    if (in_array($etcDir.DS.'local.xml', $files)) {
        $this->_isLocalConfigLoaded = true;
    }
    return $this;
}

这是将 local.xml 文件合并到配置树的代码。添加一些调试代码

public function loadBase()
{
    var_dump('Called ' . __METHOD__);   //ensure we're being called    
    $etcDir = $this->getOptions()->getEtcDir();
    $files = glob($etcDir.DS.'*.xml');
    $this->loadFile(current($files));
    while ($file = next($files)) {
        var_dump($file);                    //dump the file path being loaded to the browser
        $merge = clone $this->_prototype;
        $merge->loadFile($file);
        $this->extend($merge);
    }
    if (in_array($etcDir.DS.'local.xml', $files)) {
        $this->_isLocalConfigLoaded = true;
    }
    exit;                                   //bail out early
    return $this;
}

在浏览器中加载您的站点,并观察通过 var_dump 输出的路径。确保正在加载的文件是您认为正在加载的文件。请记住,它看起来像是 etc 文件夹中的每个 XML 文件都已加载并合并。

如果路径符合您的预期,接下来添加一些调试代码以输出 XML 文件的内容) 正在加载。

public function loadBase()
{
    var_dump('Called ' . __METHOD__ . '');  //ensure we're being called    
    $etcDir = $this->getOptions()->getEtcDir();
    $files = glob($etcDir.DS.'*.xml');
    $this->loadFile(current($files));
    while ($file = next($files)) {
        header('Content-Type: text/plain'); //so the browser renders it as plain text
        echo file_get_contents($file);      //dump the contents of the file being loaded to the browser
        $merge = clone $this->_prototype;
        $merge->loadFile($file);
        $this->extend($merge);
    }
    if (in_array($etcDir.DS.'local.xml', $files)) {
        $this->_isLocalConfigLoaded = true;
    }
    exit;                                   //bail out early
    return $this;
}

如果这些文件中的数据库信息是正确的,那么您的系统已经被定制和/或以某种方式被黑客攻击,有代码调用另一个数据库服务器。

如果是这种情况,您需要安装 xDebug 之类的东西才能获得一些不错的错误报告。这将使您找到引发错误的确切代码,此时您可以追溯到它获取连接信息的位置。

祝你好运。

Make sure you're editing the config file you think you're editing. Take a look at the following code

#File: app/code/core/Mage/Core/Model/Config.php

public function loadBase()
{
    $etcDir = $this->getOptions()->getEtcDir();
    $files = glob($etcDir.DS.'*.xml');
    $this->loadFile(current($files));
    while ($file = next($files)) {
        $merge = clone $this->_prototype;
        $merge->loadFile($file);
        $this->extend($merge);
    }
    if (in_array($etcDir.DS.'local.xml', $files)) {
        $this->_isLocalConfigLoaded = true;
    }
    return $this;
}

This is the code that merges in your local.xml file to the configuration tree. Add some debugging code

public function loadBase()
{
    var_dump('Called ' . __METHOD__);   //ensure we're being called    
    $etcDir = $this->getOptions()->getEtcDir();
    $files = glob($etcDir.DS.'*.xml');
    $this->loadFile(current($files));
    while ($file = next($files)) {
        var_dump($file);                    //dump the file path being loaded to the browser
        $merge = clone $this->_prototype;
        $merge->loadFile($file);
        $this->extend($merge);
    }
    if (in_array($etcDir.DS.'local.xml', $files)) {
        $this->_isLocalConfigLoaded = true;
    }
    exit;                                   //bail out early
    return $this;
}

Load your site in a browser, and observe the paths being output via var_dump. Make sure that the file(s) being loaded are the ones you think are being loaded. Keep in mind that it looks like every XML file from the etc folder is loaded and merged in.

If the paths are what you expect, next add some debugging code to output the contents of the XML file(s) being loaded.

public function loadBase()
{
    var_dump('Called ' . __METHOD__ . '');  //ensure we're being called    
    $etcDir = $this->getOptions()->getEtcDir();
    $files = glob($etcDir.DS.'*.xml');
    $this->loadFile(current($files));
    while ($file = next($files)) {
        header('Content-Type: text/plain'); //so the browser renders it as plain text
        echo file_get_contents($file);      //dump the contents of the file being loaded to the browser
        $merge = clone $this->_prototype;
        $merge->loadFile($file);
        $this->extend($merge);
    }
    if (in_array($etcDir.DS.'local.xml', $files)) {
        $this->_isLocalConfigLoaded = true;
    }
    exit;                                   //bail out early
    return $this;
}

If the database information is correct in these files, then your system has been customized and/or hacked in some way that there's code calling out to another database server.

If that's the case you'll need to install something like xDebug to get some decent error reporting. This will let you find the exact code that's throwing the error, at which point you can trace it back to where it's getting it's connection information.

Good luck.

温柔戏命师 2024-10-16 00:38:01

当我遇到类似问题时刚刚遇到了这个。按照 Alan Storm 转储配置文件名的建议,发现了问题。在从另一个实例复制数据库和配置文件之前,我已经进行了全新安装,并将现有的 local.xml 重命名为 localorig.xml。这是在 local.xml 之后加载的,并将数据库配置字段设置回错误的值。

寓意:如果您要备份同一文件夹中的任何配置文件,请更改扩展名。

谢谢艾伦。

Just came across this when I had a similar issue. Followed Alan Storm's suggestion of dumping the config file names and found the problem. I had done a fresh install before copying the db and config files in from another instance, and had renamed the existing local.xml to localorig.xml. This was being loaded after local.xml and setting the db configuration fields back to the wrong values.

Moral: if you're backing up any of the config files in the same folder, change the extension.

Thanks Alan.

巡山小妖精 2024-10-16 00:38:01

尝试安装 Alan Storm 的 Configviewer 并检查生成的 XML 以确认连接详细信息指向 local.xml< /代码> 规格。其中一个模块可能正在使用非默认资源或其他一些奇怪的情况。

您能否在问题中发布一些堆栈跟踪(如果需要,请进行混淆)以显示哪个模块正在调用该错误的数据库?

Try installing Alan Storm's Configviewer and check the generated XML to confirm the connection details point to the local.xml specifications. It's possible that one of the modules is using a non-default resource or some other oddity.

Can you post some of the stack trace in your question (obfuscated if you need) to show which module is calling that erroneous DB?

风铃鹿 2024-10-16 00:38:01

我刚才也遇到了类似的问题。不过,我仔细检查了 local.xml 文件,这绝对是正确的。 Magento 仍在使用旧用户访问数据库。

问题立即得到解决rm -rf var/cache/* - 一旦完成,网站就出现了。

看起来Magento正在缓存区域中缓存local.xml的内容。不太有帮助。

显然,还建议仔细检查 local.xml 文件,但在本例中它是 100% 正确的。

I had a similar problem just now. I double checked the local.xml file and that was definitely correct, however. Magento was still using an old user to access the database.

The problem was instantly resolved with: rm -rf var/cache/* - immediately this was done, the site came up.

It appears that Magento is caching the contents of local.xml in the cache area. Not so helpful.

Obviously, also recommend double checking the local.xml file but in this case it was 100% correct.

烟花易冷人易散 2024-10-16 00:38:01

只是想尽力提供帮助。你能检查一下你的apache配置吗?像“apache2 -S”这样的东西可以查看使用了哪些虚拟主机(尤其要注意第一个默认虚拟主机)。
您可以测试所有虚拟主机(如果您使用虚拟主机)是否正在使用正确的 documentRoot。您的开发服务器上没有源代码的其他副本吗?

我的意思是,您确定您在浏览器上使用的网址上运行了正确的 magento 实例吗?以同样的方式,您确定安装中使用的缓存目录 - 自清除以来您是否看到这些目录有任何变化?

Just to try to help. Can you check your apache configuration? Something like "apache2 -S" to see which virtualhosts are used (and note especially the first default one).
You could test that all your virtualhosts (if you work with virtualhosts) are using the right documentRoot. Don't you have an other copy of the sources on your dev server?

I mean are you sure you get the right magento instance running on the url you're using on your browser? In the same way are you sure of the cache directories used on your installation - do you see any change in theses directories since the wipe out?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文