Home > Database > Mysql Tutorial > body text

How to Fix MySQL Error 1290: \'Can\'t create/write to file\' When Using INTO OUTFILE?

Susan Sarandon
Release: 2024-11-04 20:05:02
Original
485 people have browsed it

How to Fix MySQL Error 1290:

MySQL Secure File Privileges: Resolving Error 1290 When Writing to Files

MySQL's --secure-file-priv option restricts the execution of statements that write to files. This error occurs when attempting to write query results to a file using the INTO OUTFILE clause while this option is enabled.

Solution:

Find Allowed Write Paths

Check the value of the @@GLOBAL.secure_file_priv system variable to determine the directories where MySQL is allowed to write files:

<code class="sql">SELECT @@GLOBAL.secure_file_priv;</code>
Copy after login

Ubuntu 16.04: Write to the specified path, for example:

<code class="sql">SELECT * FROM train INTO OUTFILE '/var/lib/mysql-files/test.csv' FIELDS TERMINATED BY ',';</code>
Copy after login

Mac OSX (MAMP):

Create .my.cnf File:

  1. Open ~/.my.cnf.
  2. Add the line: secure_file_priv="/Users/[your username]/" within the [mysqld] section.

Disable Secure File Privileges (Not Recommended):

Set the @@GLOBAL.secure_file_priv system variable to NULL:

<code class="sql">SET GLOBAL secure_file_priv=NULL;</code>
Copy after login

Note: This method risks allowing untrusted code to write to arbitrary locations on the server. It should only be used as a temporary measure.

The above is the detailed content of How to Fix MySQL Error 1290: \'Can\'t create/write to file\' When Using INTO OUTFILE?. 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