Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP MySQLi query - "Permission denied" [duplicate]

Tags:

php

mysql

mysqli

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

like image 344
RolandasR Avatar asked Dec 02 '22 02:12

RolandasR


1 Answers

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.

like image 81
karakani Avatar answered Dec 04 '22 16:12

karakani