Home >Database >Mysql Tutorial >Why Can\'t MySQL Access My File When Using LOAD DATA INFILE?

Why Can\'t MySQL Access My File When Using LOAD DATA INFILE?

Linda Hamilton
Linda HamiltonOriginal
2024-11-03 20:21:02630browse

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:

  • Ensure that the file path specified in the LOAD DATA INFILE statement is correct and accessible by MySQL.
  • Consider using a data import tool like mysqlimport or mysql.connector to import data instead.

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn