Suddenly encountered MySQL Error: Error (HY000): File '/var/www/xiaoyou/static/upload/import/20130427105733.csv.txt ' not Found (Errcode: 13)
Feel strange, because the program in the local very OK, angry statement as follows:
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,...);
I have been because of the permissions, problems, but when I put the directory and file permissions are chmod to 777 or error, after Google found:
Recent Ubuntu Server Editions (such as 10.04) ship with AppArmor and MySQL's profile might is in enforcing mode by default . You can check the this by executing
sudo aa-status
Like so:
# sudo aa-status 5 profiles is Loaded.5 profiles is in enforce MODE./USR/LIB/CONNMAN/SCRIPTS/DHCLIENT-SCRIPT/SBIN/DHCLI Ent3/usr/sbin/tcpdump/usr/lib/networkmanager/nm-dhcp-client.action/usr/sbin/mysqld 0 Profiles is in complain mode.1 Processes has profiles Defined.1 processes is in enforce mode:/usr/sbin/mysqld (1089) 0 processes is in complain mode.
If Mysqld is included in enforce mode, then it is the one probably denying the write. Entries would also is written in
/var/log/messages
When AppArmor blocks the writes/accesses. What are can do is edit
/etc/apparmor.d/usr.sbin.mysqld
and add
/data/
and
/data/*
Near the bottom:
...
/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
The general content is, mysqld forced encoding, the file does not have write permission, so I add the file directory to mysqld (/etc/apparmor.d/usr.sbin.mysqld the bottom of this file, such as the bold part):
/VAR/WWW/UPLOAD/IMPORT/R,
/var/www/upload/import/* RW,
MySQL import file data error: HY000: file ' xxx.txt ' not Found (errcode:13)