I'm running a RedHat 6.2 Amazon EC2 instance using stock Apache and IUS PHP53u+MySQL (+mbstring, +mysqli, +mcrypt), and phpMyAdmin from git. All configuration is near-vanilla, assuming the described installation procedure.

I've been trying to import SQL files into the database using phpMyAdmin to read them from a directory on my server. phpMyAdmin lists the files fine in the drop down, but returns a "File could not be read" error when actually trying to import. Furthermore, when trying to execute file_get_contents(); on the file, it also returns a "failed to open stream: Permission denied" error.

In fact, when my brother was attempting to import the SQL files using MySQL "SOURCE" as an authenticated MySQL user with ALL PRIVILEGES, he was getting an error reading the file. It seems that we are unable to read/import these files with ANY method other than root under SSH (although I can't say I've tried every possible method). I have never had this issue under regular CentOS (5, 6, 6.2) installations with the same LAMP stack configuration.

Some things I've tried after searching Google and StackExchange:

  • CHMOD 0777 both directory and files,
  • CHOWN root, apache (only two users I can think of that PHP would use),
  • Importing SQL files with total size under both upload_max_filesize and post_max_size,
  • PHP open_basedir commented out, or = "/var/www" (my sites are using Apache VirtualHosts within that directory, and all the SQL files are deep within that directory),
  • PHP safe mode is OFF (it was never ON)

At the moment I have solved this issue with the smaller files by using the FILE UPLOAD method directly to phpMyAdmin, but this will not be suitable for uploading my 200+ MiB SQL files as I don't have a stable Internet connection.

Any light you could shed on this situation would be greatly appreciated. I'm fair with Linux, and for the things that do stump me, Google usually has an answer. Not this time, though!

  • Until you figure out what is wrong, you should be able to import your SQL files using SSH: mysql -u USERNAME -p DATABASE < yoursqlfile.sql – cyberx86 Mar 25 '12 at 18:36

Grant FILE privilege to your mysql user that is importing the file, if the file is readable by the mysql user already.


Is SELinux enabled ? Unless your security requirement mandates it, disable it. To find out, check contents of /etc/sysconfig/selinux.


We used cyberx86's advice (which I should've remembered from basic SQL administration days) worked great for the meantime, but I terminated the instance (and opted for Amazon Linux rather than RedHat) in the end. We no longer have this issue. It is worth noting that this method is what we have used in the Amazon Linux instance for our final production server.

I believe SELinux may have been causing it but cannot confirm (or vote up at this time).


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.