mysql錯誤:ERROR 29 (HY000): File 'xxx.txt' not found (Errcode: 13)

來源:互聯網
上載者:User

突然遇到mysql錯誤:ERROR 29 (HY000): File '/var/www/xiaoyou/static/upload/import/20130427105733.csv.txt' not found (Errcode: 13)

感覺特奇怪,因為程式在本地很ok,生氣了語句如下:

LOAD DATA INFILE '/var/www/upload/abc.csv.txt' INTO TABLE alumni_import FIELDS TERMINATED BY ',' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED by ' ' IGNORE 1 lines (field1,field2,...);

我一直因為是許可權,問題,但是當我把目錄和檔案許可權都chmod為777後還是出錯,google了後發現:


Recent Ubuntu Server Editions (such as 10.04) ship with AppArmor and MySQL's profile might be in enforcing mode by default. You can check this by executing
sudo aa-status
 like so:


# sudo aa-status 5 profiles are loaded.5 profiles are in enforce mode./usr/lib/connman/scripts/dhclient-script /sbin/dhclient3 /usr/sbin/tcpdump /usr/lib/NetworkManager/nm-dhcp-client.action /usr/sbin/mysqld 0 profiles are in complain mode.1 processes have profiles defined.1 processes are in enforce mode :/usr/sbin/mysqld (1089)0 processes are in complain mode.

If mysqld is included in enforce mode, then it is the one probably denying the write. Entries would also be written in
/var/log/messages
 when AppArmor blocks the writes/accesses. What you can do is edit
/etc/apparmor.d/usr.sbin.mysqld
 and add
/data/
 and
/data/*
 near the bottom like so:

...
/usr/sbin/mysqld {
    ...
    /var/log/mysql/ r,
    /var/log/mysql/* rw,
    /var/run/mysqld/mysqld.pid w,
    /var/run/mysqld/mysqld.sock w,
    /data/ r,
    /data/* rw,
}

And then make AppArmor reload the profiles.


# sudo /etc/init.d/apparmor reload


大體內容就是,mysqld強制編碼了,檔案沒有寫入許可權,於是我把該檔案目錄也加到mysqld(/etc/apparmor.d/usr.sbin.mysqld這個檔案的底部,如上粗體部分):


/var/www/upload/import/ r,


/var/www/upload/import/* rw,

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.