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

自古美人都是妖i 提交于 2020-01-06 03:13:18

问题


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)



来源:https://stackoverflow.com/questions/17520611/general-error-1-cant-create-write-to-file-errcode2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!