English 中文(简体)
用户www-data @ localhost-如何处理?
原标题:Access denied for user www-data @ localhost - how to deal with that?
  • 时间:2011-10-06 07:30:08
  •  标签:
  • php
  • mysql

I face with a strange problem yesterday. I have server running Debian with installed PHP 4.4.4-8 and mysql 5.5.9. That server serves a several websites. For some reason randomly I get that error "Access denied for user www-data @ localhost (using password: NO)" when I try to load the webpage. If I hit refresh the page loads normally, but afer several clicks that message appears again. Username which that page use to connect to mysql server is not www-data.

是否有任何人面临同样的问题?

最佳回答

www-data is the Debianuser that trans apache and php. 如果你在没有有效联系时试图进行询问,那么,php/mysql将尝试使用<代码><unix-user>@ localhost<>/code>,无密码。 此处为(使用密码:NO)。

现在开始这样做的最可能原因(尽管早两年来一直罚款)是,你的包裹已增加到某些连接无法成功的地步(可能是由于最大连接或最大用户——连接;尽管这可能也是由于记忆、read等其它限制所致)。 当出现这种情况时,请打电话到mysql_link,发送错误信息,并填写。 如果你没有发现这一失败,那么,你的下传言(或许是我的sql_query,或我的sql_select_db)将试图连接www-data@ localhost——从而造成你再次看到的问题。

我建议(如@DarkMantis所建议的)证明错误的报告和错误显示:

ini_set( error_reporting , E_ALL|E_STRICT);
ini_set( display_errors , 1);

另外,确保你向我sql_link发出的电话是not<>em>,然后是@的签字;并确保核对收益价值。 它应当研究这样的情况:

$cxn = mysql_connect( localhost , yourusername , yourpassword );
if( $cxn === FALSE ) {  die( mysql connection error:  .mysql_error()); }
问题回答

如同引起错误的提问一样,当有人提出具体要求时发生错误。 这可能意味着,当查询时,你与数据库有正确的用户名/密码链接。

请确保你有明确的联系,使用<代码>或死亡(Msql_error();,在你所有的问答变量中加以消减。

此外,在贵方网站顶端使用以下两条线:

ini_set( error_reporting , E_ALL);
ini_set( display_errors , 1);

这将显示你在您的级别/档案中可能出现的任何微小的实验室错误,而您以前可能没有这样做。

如果你在此之后仍然有问题,请张贴你的公共卫生和社会福利部的守则,我将直接研究。

感谢!

i faced the same problem. The problem was in my config.php! I simply changed the $dbserver from "127.0.0.1" -> "localhost". Now the connection works again!

对于无意识的人,这种错误可能发生在以下情况下:mysql_query()在mysqli_link(<>之后,届时应为mysqli_query()。

1. 使用密码

(MySQLi Object-Oriented)
<?php
$servername = "localhost";
$username = "username";
$password = "password";

// Create connection
$conn = new mysqli($servername, $username, $password);

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

恢复安全模式对我来说是固定的:

Notice: mysql_connect(): SQL safe mode in effect - ignoring host/user/password information in /var/www/html/test.php on line 4

解决这一问题。 我不得不改变使用连接文字的链接。

(MySQLi Object-Oriented)
<?php
$servername = "localhost";
$username = "username";
$password = "password";

// Create connection
$conn = new mysqli($servername, $username, $password);

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




相关问题
SQL SubQuery getting particular column

I noticed that there were some threads with similar questions, and I did look through them but did not really get a convincing answer. Here s my question: The subquery below returns a Table with 3 ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

php return a specific row from query

Is it possible in php to return a specific row of data from a mysql query? None of the fetch statements that I ve found return a 2 dimensional array to access specific rows. I want to be able to ...

Character Encodings in PHP and MySQL

Our website was developed with a meta tag set to... <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> This works fine for M-dashes and special quotes, etc. However, I ...

Pagination Strategies for Complex (slow) Datasets

What are some of the strategies being used for pagination of data sets that involve complex queries? count(*) takes ~1.5 sec so we don t want to hit the DB for every page view. Currently there are ~...

Averaging a total in mySQL

My table looks like person_id | car_id | miles ------------------------------ 1 | 1 | 100 1 | 2 | 200 2 | 3 | 1000 2 | 4 | 500 I need to ...