MySQL 连接在同一查询上失败。尝试与默认用户重新连接
我在同一查询中收到以下错误: 警告:mysql_query():用户“www-data”@“localhost”访问被拒绝(使用密码:NO)
该错误仅在从任何特定 IP 第一次尝试时发生。刷新页面后,脚本运行正常。更具体地说,我将在一个位置从浏览器运行它,它会出错。如果我刷新页面,问题就解决了。直到我从另一个位置尝试。
据我所知,它失去了与数据库服务器的连接并尝试使用默认用户名重新连接。让我困惑的是它每次都在同一个查询上失败。我们将此称为查询_X。多个查询在 query_X 之前运行,包括选择、插入和更新。 Query_X 如下所示:
UPDATE game_users
SET status_cd=$tmp_status,
expire_date=date_add('$currentExpire', interval $l_license_duration_days day)
WHERE game_user_id=$l_game_user_id
作为示例,传递的变量为:
$tmp_status = 1;
$currentExpire = '2011-12-05';
$l_license_duration_days = 30;
$l_game_user_id = 1;
该查询导致连接失败的原因是什么?为什么刷新页面可以解决问题?
仅供参考,我正在使用持久连接。
编辑:我刚刚从昨晚尝试过的 IP 再次尝试。我再次收到错误。这是第一次运行脚本时的情况。我第二次运行该页面后,效果很好。
编辑:第一次在特定浏览器上运行时也会出错,即使它在同一IP上,即在firefox上出错一次然后就好了,在chrome上出错一次然后就没事了,等等。
编辑:我已将其范围缩小到在 query_X 之前发生的 mail() 函数。我仍然不知道为什么邮件功能会关闭 mySQL 连接。我决定将邮件功能(可以正常工作并发送电子邮件)放在 php 文件的末尾,无论如何我都会在其中关闭连接。这是一个 hack,但我已经在这上面花了太多时间了。
I am getting the following error on the same query:
Warning: mysql_query(): Access denied for user 'www-data'@'localhost' (using password: NO)
The error only occurs on the first try from any particular IP. After I refresh the page, the script runs fine. To be more specific, I will run it from a browser in one location, and it will error. If I refresh the page, the problem is fixed. That is until I try from another location.
From what I gather, its losing the connection to the database server and trying to reconnect with the default username. What's confusing me is that it fails on the same query each time. Let's call this query_X. Multiple queries run before query_X including selects, inserts, and updates. Query_X looks like this:
UPDATE game_users
SET status_cd=$tmp_status,
expire_date=date_add('$currentExpire', interval $l_license_duration_days day)
WHERE game_user_id=$l_game_user_id
As an example, the variables being passed are:
$tmp_status = 1;
$currentExpire = '2011-12-05';
$l_license_duration_days = 30;
$l_game_user_id = 1;
What is it about this query that makes the connection fail, and why does refreshing the page fix the problem?
Fyi, I'm using persistent connect.
Edit: I just tried again from an ip that I tried last night. And I received the error again. That is on the first run of the script. After I ran the page a second time, it worked fine.
Edit: It will also error the first time it's run on a particular browser, even if it is on the same IP, i.e. it will error once on firefox and then be fine, error on chrome once and then be fine, etc.
Edit: I've narrowed it down to a mail() function that was happening just before query_X. I still don't know why the mail function is closing the mySQL connection. I've decided to put the mail function (which works properly and sends the email) at the end of the php file, where I would close the connection anyways. It's a hack, but I've spent too much time on this already.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)