Home >Database >Mysql Tutorial >Why Can\'t MySQL Access My File When Using LOAD DATA INFILE?
LOAD DATA INFILE Error Code : 13
When attempting to load data into a MySQL table using the LOAD DATA INFILE command on a remote server, you may encounter Error Code : 13: "Can't get stat of '/httpdocs/.../.../testFile.csv' (Errcode: 2)". This indicates that MySQL is unable to access the specified file.
The following steps can help resolve this issue:
1. Grant Sufficient Privileges
Ensure that the database user has sufficient privileges to access the file. Consider granting the user SELECT, FILE, and LOAD DATA permissions:
GRANT SELECT, FILE, LOAD DATA ON *.* TO 'userName'@'%'
2. Set File and Folder Permissions
Make sure that the file and folder permissions allow MySQL to read the file. Set the file permissions to 644 (rw-r--r--) and the folder permissions to 755 (rwxr-xr-x):
<code class="bash">chmod 644 /httpdocs/.../.../testFile.csv chmod 755 /httpdocs/.../.../</code>
3. Check Apparmor Settings
On Ubuntu systems, Apparmor can restrict MySQL's access to files. To allow MySQL to read files from the "tmp" directory, add the following line to /etc/apparmor.d/usr.sbin.mysqld:
/tmp/** rwk
Reload Apparmor using:
<code class="bash">sudo /etc/init.d/apparmor reload</code>
4. Disable SELinux
If using SELinux (Security-Enhanced Linux), it can also restrict file access. Try temporarily disabling it and re-running the LOAD DATA INFILE command. Consult your SELinux documentation for specific instructions.
Additional Notes:
The above is the detailed content of Why Can\'t MySQL Access My File When Using LOAD DATA INFILE?. For more information, please follow other related articles on the PHP Chinese website!