Home > Database > Mysql Tutorial > Why Does MySQL SELECT INTO OUTFILE Fail with Errcode 13 Despite Correct File Permissions?

Why Does MySQL SELECT INTO OUTFILE Fail with Errcode 13 Despite Correct File Permissions?

Barbara Streisand
Release: 2025-01-24 15:07:13
Original
621 people have browsed it

Why Does MySQL SELECT INTO OUTFILE Fail with Errcode 13 Despite Correct File Permissions?

Troubleshooting MySQL's SELECT INTO OUTFILE Errcode 13: Beyond Basic Permissions

Using SELECT INTO OUTFILE to export MySQL data to a CSV can be thwarted by Errcode 13, a permissions error. While insufficient file permissions are the usual culprit, the problem persists even with correct directory permissions, often due to AppArmor's security measures in modern Ubuntu Server versions.

AppArmor's Role in MySQL Permissions

AppArmor, a Linux security module, restricts application access to system resources. If MySQL runs under an AppArmor profile (check with sudo aa-status; look for "/usr/sbin/mysqld" under "profiles in enforce mode"), its write access might be limited.

Resolving the Issue: Granting AppArmor Access

To allow MySQL to write to specific locations:

  1. Edit the AppArmor profile: Open /etc/apparmor.d/usr.sbin.mysqld for editing.

  2. Add write permissions: Add lines granting read/write access to the target directory. For instance:

<code>/usr/sbin/mysqld {
    ...
    /data/ r,
    /data/* rw,
}</code>
Copy after login

This allows MySQL to read from and write to /data and its subdirectories.

  1. Reload AppArmor: Execute sudo /etc/init.d/apparmor reload to apply the changes.

  2. Restart MySQL: Restart the MySQL service. Retry your SELECT INTO OUTFILE command.

Important Security Note: Carefully consider the implications of granting write access to MySQL via AppArmor. Only grant access to absolutely necessary directories to minimize security risks.

The above is the detailed content of Why Does MySQL SELECT INTO OUTFILE Fail with Errcode 13 Despite Correct File Permissions?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template