简体   繁体   English

使用Wordpress建立数据库连接时出错

[英]Error establishing a database connection using Wordpress

I have problem with my Wordpress site, it was working normally, Suddenly this message start to appear 我的Wordpress网站有问题,它工作正常,突然此消息开始出现

Error establishing a database connection Wordpress 建立数据库连接Wordpress时出错

I tried the following things (no one is working and I still have the same problem till now) 我尝试了以下操作(没有人在工作,直到现在我仍然遇到相同的问题)

I checked my wp_config.php for db name and credential and every thing is fine and I tried to repair db by adding WP_ALLOW_REPAIR and this scripts shows that every thing is okay. 我检查了wp_config.php的数据库名称和凭据,一切正常,我尝试通过添加WP_ALLOW_REPAIR来修复数据库,此脚本表明一切正常。

I added test file to my website to see if the db credentials is correct like following 我将测试文件添加到我的网站以查看数据库凭据是否正确,如下所示

<?php
$link = mysql_connect('localhost', 'myUserName', 'myPassword');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>

and it's print Connected successfully 并打印成功

I tried to disable plugins by changing the name of the plugins folder, but same problem. 我试图通过更改plugins文件夹的名称来禁用插件,但是同样的问题。

Try to change your test file to use the wp-config file. 尝试将您的测试文件更改为使用wp-config文件。

     <?php
     //PATH TO YOUR FILE
     require_once('path/to/wp-config.php');
     //using wp-config variables 
     $link = mysql_connect(DB_HOST, DB_USER, DB_PASSWORD);
     if (!$link) {
          die('Could not connect: ' . mysql_error());
     }
     echo 'Connected successfully';
     mysql_close($link);
     ?>

If this is working you dont have a code issue - you have a server/connectivity issue. 如果此方法有效,则不会出现代码问题-您会遇到服务器/连接问题。

Your test demonstrates that you can successfully connect to the MySQL with the user:pass to localhost. 测试表明,您可以使用user:pass到localhost成功连接到MySQL。 But are you sure that the user can use the specific database? 但是,您确定用户可以使用特定的数据库吗? Try to add mysql_select_db( $link, 'database_name' ) to your test code, something like this: 尝试将mysql_select_db($ link,'database_name')添加到测试代码中,如下所示:

<?php
$link = mysql_connect('localhost', 'myUserName', 'myPassword');
if (!$link) {
die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';

$use = mysql_select_db( $link, 'myDatabaseName' );

if( $use )
{
    echo "\n" .'Database selected!';
}

mysql_close($link);
?>

This is just a suggestion to be sure that everything is working fine. 这只是建议,以确保一切正常。 As @Nimrod007 said: if everything now is working, the problem is not in the code and could be some server/connectivity issue. 正如@ Nimrod007所说:如果现在一切正常,则问题不在代码中,可能是服务器/连接性问题。

1st: Maybe MAX_CONNECTION_LIMIT is the problem. 1日:也许是MAX_CONNECTION_LIMIT。 If already max connection open. 如果已经打开最大连接。 new connection not accepted. 不接受新的连接。 So ur WP Site and other database failed to connect to MYSQL SERVER. 因此,您的WP网站和其他数据库无法连接到MYSQL SERVER。

so you will get Error establishing a database connection error. 因此您将在建立数据库连接错误时遇到错误。

2nd: Uses of RAM. 第二:使用RAM。 if your RAM IS FULL. 如果您的RAM已满。 Mysql Server failed to start. Mysql Server无法启动。

check mysql error logs. 检查mysql错误日志。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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