PHP MySQLi查询-“权限被拒绝" [英] PHP MySQLi query - "Permission denied"

查看:171
本文介绍了PHP MySQLi查询-“权限被拒绝"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用PHP MySQLi连接到MySQL,有时会执行查询,但出现错误:

Im using PHP MySQLi to connect to MySQL and sometimes doing query i get error:

权限被拒绝"错误代码:2002.

"Permission denied" error code: 2002.

奇怪的是,它发生在不同的查询中并且完全不可预测.例如,它可能在正确执行前两个查询后的第三个查询上发生.

The strange thing is that it happens for different query's and totally unpredictable. For example it might happen on third query after first two executed correctly.

我知道MySQL没问题,因为我将它从一台服务器移到了另一台服务器,并且问题仍然存在. PHP或PHP与MySQL服务器之间的互连(它们位于不同的机器上)很可能是问题

I know it is not problem with MySQL because i moved it from one server to another and problem still persists. Most likely problem with PHP or interconnection between PHP and MySQL servers (they're on different machines)

有人知道吗?


查询如果我重新启动脚本,得到权限被拒绝"的内容的原因-它不是权限问题


query what gets "Permission denied" works if i restart script - its not permissions problem

错误:

[2011年4月23日19:00:02] PHP警告: mysqli :: mysqli()[mysqli.mysqli]: [2002]权限被拒绝(试图 通过连接 tcp://xxx.xxx.xxx.xxx:3306)在 /home/.../第19行的DB.php
[2011年4月23日19:00:02] PHP警告: mysqli :: mysqli()[mysqli.mysqli]: (HY000/2002):拒绝在 /home/.../DB.php,第19行

[23-Apr-2011 19:00:02] PHP Warning: mysqli::mysqli() [mysqli.mysqli]: [2002] Permission denied (trying to connect via tcp://xxx.xxx.xxx.xxx:3306) in /home/.../DB.php on line 19
[23-Apr-2011 19:00:02] PHP Warning: mysqli::mysqli() [mysqli.mysqli]: (HY000/2002): Permission denied in /home/.../DB.php on line 19

推荐答案

我的环境中发生了同样的事情.原因是SELinux.

Same things happened on my environment. And the cause was SELinux.

您也许可以通过从命令行执行php来连接数据库 虽然您可能无法通过在Web服务器上执行.

You might be able to connect the database by executing php from command line while you might not by executing on the web server.

就我而言,我关闭了SELinux.

In my case, I turned off SELinux.

# setenforce 0

或者您必须正确设置SELinux.

Or you have to set up SELinux correctly.

这篇关于PHP MySQLi查询-“权限被拒绝"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆