General error: 1 Can't create/write to file er

2019-07-27 02:04发布

问题:

I am trying to write a CSV file to /var/www/VistaMind_CMStmp and I get the error Message: SQLSTATE[HY000]: General error: 1 Can't create/write to file '/VistaMind_CMS/tmp/app_users.csv' (Errcode: 2)

I tried doing chown mysql:mysql /var/www/VistaMind_CMS/tmp, but that does not work. I do not want to modify my TMPDIR var in my.cnf, which is currently set to /var/www, but instead, I want MySQL to dump a database table to /var/www/VistaMind_CMS/tmp.

Please help!

My code is :

    $file_path = $this->view->baseUrl()."/../tmp/app_users.csv";
    $sql = "SELECT * FROM users INTO OUTFILE '".$file_path."' ".
            "FIELDS TERMINATED BY ','
            ENCLOSED BY '\"'
            LINES TERMINATED BY '\n'";
    $db = Zend_Registry::get('db');
    $stmt = $db->query($sql, array());
    echo "Done!!";

回答1:

You need to do chown mysql:mysql /var/www/VistaMind_CMS/tmp.



回答2:

in my case the chown did not fix the problem. I followed the second step in the following post which finally solved my problem

http://www.mydailyhacks.org/2014/11/08/how-can-i-backup-a-mysql-database-or-export-it-to-a-file/

(I had to change the tmpdir used by mysql)