简体   繁体   中英

PHP MySQLi query - “Permission denied”

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

"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.

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)

Anyone got ideas?

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

ERROR:

[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

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

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

In my case, I turned off SELinux.

# setenforce 0

Or you have to set up SELinux correctly.

我认为数据库用户没有足够的权限对​​特定的mysql表进行特定的操作。

This isn't a permissions error. The client isn't able to get as far as connecting to the database, let alone trying to authenticate the user.

I suspect these problems will be being caused by either network problems (preventing the client/server machines from talking to each other) or the MySQL server process not running on the remote host.

The error code is documented here: http://dev.mysql.com/doc/refman/5.5/en/can-not-connect-to-server.html

检查您通过其连接的用户的权限

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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