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:
Check AppArmor Status: Use this command to confirm AppArmor's mode for MySQL:
<code class="language-bash">sudo aa-status</code>
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>
Reload AppArmor Profiles: After editing the profile, reload AppArmor:
<code class="language-bash">sudo /etc/init.d/apparmor reload</code>
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!