用户'www-data'@'localhost的访问被拒绝-如何处理? [英] Access denied for user 'www-data'@'localhost - how to deal with that?
问题描述
昨天我遇到一个奇怪的问题.我的服务器运行的是Debian,安装了PHP 4.4.4-8和mysql 5.5.9.该服务器为多个网站提供服务. 出于某种原因,当我尝试加载网页时,随机出现错误用户'www-data'@'localhost'的访问被拒绝(使用密码:否)". 如果单击刷新,页面将正常加载,但单击几次后,该消息将再次出现.该页面用于连接到mysql服务器的用户名不是www-data.
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.
有人遇到过类似的问题吗?
Does anyone has faced similar problem ?
推荐答案
www-data
是运行apache和php的Debian用户.如果您在没有有效连接的情况下尝试查询,则php/mysql将尝试使用<unix-user>@localhost
创建无密码的连接.这是www-data@localhost (using password:NO)
的来源.
www-data
is the Debian user that runs apache and php. If you attempt a query when you don't have a valid connection, php/mysql will attempt to create a connection using <unix-user>@localhost
with no password. This is where www-data@localhost (using password:NO)
is coming from.
这种情况现在开始发生的最可能原因(尽管它已经运行了两年很好)是您的数据库负载已增加到某些连接无法成功的地步(可能是由于max_connections造成的,或者max_user_connections;尽管这也可能是由其他限制(例如内存,线程等)引起的.发生这种情况时,您对mysql_connect
的调用将发出错误消息,并返回FALSE
.如果您未能检测到此失败,则您的下一个mysql调用(可能是mysql_query或mysql_select_db)将尝试连接到www-data @ localhost,从而引起您所遇到的问题.
The most likely reason that this has started happening now (though it has been running fine for 2-years prior) is that your db load has increased to the point where some connections are unable to succeed (probably due to max_connections, or max_user_connections; though this can also result from other limits like memory, threads, etc). When this happens, your call to mysql_connect
will emit an error message, and return FALSE
. If you fail to detect this failure, then your next mysql call (probably mysql_query, or mysql_select_db) will attempt the connection to www-data@localhost -- thus causing the problem you're seeing.
我建议启用错误报告和错误显示(如@DarkMantis建议):
I suggest enabling error reporting, and error display (as suggested by @DarkMantis) :
ini_set('error_reporting', E_ALL|E_STRICT);
ini_set('display_errors', 1);
另外,请确保对mysql_connect的调用是 not ,并以@
符号开头;并确保检查返回值.它应该看起来像这样:
Also, be sure that your call to mysql_connect is not preceded by a @
sign; and make sure to check the return value. It should look something like this:
$cxn = mysql_connect('localhost','yourusername','yourpassword');
if( $cxn === FALSE ) { die('mysql connection error: '.mysql_error()); }
这篇关于用户'www-data'@'localhost的访问被拒绝-如何处理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!