Home > Database > Mysql Tutorial > How to Resolve MySQL Error 1290 (HY000): --secure-file-priv Option?

How to Resolve MySQL Error 1290 (HY000): --secure-file-priv Option?

Mary-Kate Olsen
Release: 2024-10-31 06:44:30
Original
656 people have browsed it

How to Resolve MySQL Error 1290 (HY000): --secure-file-priv Option?

MySQL ERROR 1290 (HY000): --secure-file-priv Option

When attempting to export MySQL script results to a text file using the INTO OUTFILE statement, you may encounter an error 1290 (HY000) due to the --secure-file-priv option. This error signifies that the MySQL server has been configured to restrict file access based on specific paths.

Solution

To resolve this issue, you need to configure your MySQL server to allow file access to a specific path where you wish to write the results:

For Ubuntu 16.04:

  1. Use the following command to identify the allowed file writing directory:

    mysql> SELECT @@GLOBAL.secure_file_priv;
    Copy after login
    Copy after login
  2. Specify the allowed directory within your INTO OUTFILE statement:

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

For Mac OSX (MySQL installed via MAMP):

  1. Check if the secure_file_priv option is set to NULL:

    mysql> SELECT @@GLOBAL.secure_file_priv;
    Copy after login
    Copy after login
  2. If NULL, create a .my.cnf file in your home directory:

    $ vi ~/.my.cnf
    Copy after login
  3. Add the following lines to the file:

    [mysqld_safe]
    [mysqld]
    secure_file_priv="/path/to/allowed/directory"
    Copy after login
  4. Restart the MySQL service.
  5. Now, specify the allowed directory in your INTO OUTFILE statement:

    mysql> SELECT * FROM train INTO OUTFILE '/path/to/allowed/directory/test.csv' FIELDS TERMINATED BY ',';
    Copy after login

The above is the detailed content of How to Resolve MySQL Error 1290 (HY000): --secure-file-priv Option?. 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