Home > Database > Mysql Tutorial > Why Does MySQL's SELECT INTO OUTFILE Return Errcode 13, and How Can I Fix It?

Why Does MySQL's SELECT INTO OUTFILE Return Errcode 13, and How Can I Fix It?

Barbara Streisand
Release: 2025-01-24 14:46:10
Original
829 people have browsed it

Why Does MySQL's SELECT INTO OUTFILE Return Errcode 13, and How Can I Fix It?

Troubleshooting MySQL's SELECT INTO OUTFILE Errcode 13

Exporting data to a CSV using MySQL's SELECT INTO OUTFILE can trigger an Errcode 13 permission error. This typically happens when the output file's location isn't MySQL's default storage directory (often /tmp). Users frequently encounter this problem when saving to alternative directories.

This error stems from operating system security. Distributions like Ubuntu Server often enable AppArmor by default, and the MySQL profile might be in "enforce" mode. This restricts MySQL's write access to certain directories.

To fix this, adjust the AppArmor profile for MySQL to allow writing to your chosen directory:

  1. Check AppArmor Status: Use this command to confirm AppArmor's mode for MySQL:

    <code class="language-bash">sudo aa-status</code>
    Copy after login
  2. Edit the AppArmor Profile (if in enforce mode): If AppArmor is enforcing, modify the /etc/apparmor.d/usr.sbin.mysqld file. Add or modify lines granting write access to your target directory. For example, to allow writing to /data/ and its subdirectories:

    <code>/usr/sbin/mysqld {
        ...
        **/data/ r,
        /data/* rw,
    }</code>
    Copy after login
  3. Reload AppArmor Profiles: After editing the profile, reload AppArmor:

    <code class="language-bash">sudo /etc/init.d/apparmor reload</code>
    Copy after login

Important Security Considerations: Granting write access to MySQL requires careful consideration of security implications. Implement robust permissions and security measures to prevent unauthorized data access.

The above is the detailed content of Why Does MySQL's SELECT INTO OUTFILE Return Errcode 13, and How Can I Fix It?. 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