Error Code: 1290. The MySQL server is running with the --secure-file-priv option so it cannot execute this statement

前端 未结 4 1198
你的背包
你的背包 2020-12-02 10:31

I encountered such a problem: Error Code: 1290. The MySQL server is running with the --secure-file-priv option so it cannot execute this statement when I tr

相关标签:
4条回答
  • 2020-12-02 11:02

    The code above exports data without the heading columns which is weird. Here's how to do it. You have to merge the two files later though using text a editor.

    SELECT column_name FROM information_schema.columns WHERE table_schema = 'my_app_db' AND table_name = 'customers' INTO OUTFILE 'C:/ProgramData/MySQL/MySQL Server 5.6/Uploads/customers_heading_cols.csv' FIELDS TERMINATED BY '' OPTIONALLY ENCLOSED BY '"' LINES TERMINATED BY ',';
    
    0 讨论(0)
  • 2020-12-02 11:10

    If you changed my.ini and restarted mysql and you still get this error please check your file path and replace "\" to "/". I solved my proplem after replacing.

    0 讨论(0)
  • 2020-12-02 11:12

    A quick answer, that doesn't require you to edit any configuration files (and works on other operating systems as well as Windows), is to just find the directory that you are allowed to save to using:

    mysql> SHOW VARIABLES LIKE "secure_file_priv";
    +------------------+-----------------------+
    | Variable_name    | Value                 |
    +------------------+-----------------------+
    | secure_file_priv | /var/lib/mysql-files/ |
    +------------------+-----------------------+
    1 row in set (0.06 sec)
    

    And then make sure you use that directory in your SELECT statement's INTO OUTFILE clause:

    SELECT *
    FROM xxxx
    WHERE XXX
    INTO OUTFILE '/var/lib/mysql-files/report.csv'
        FIELDS TERMINATED BY '#'
        ENCLOSED BY '"'
        LINES TERMINATED BY '\n'
    

    Original answer

    I've had the same problem since upgrading from MySQL 5.6.25 to 5.6.26.

    In my case (on Windows), looking at the MySQL56 Windows service shows me that the options/settings file that is being used when the service starts is C:\ProgramData\MySQL\MySQL Server 5.6\my.ini

    On linux the two most common locations are /etc/my.cnf or /etc/mysql/my.cnf.

    Opening this file I can see that the secure-file-priv option has been added under the [mysqld] group in this new version of MySQL Server with a default value:

    secure-file-priv="C:/ProgramData/MySQL/MySQL Server 5.6/Uploads"

    You could comment this (if you're in a non-production environment), or experiment with changing the setting (recently I had to set secure-file-priv = "" in order to disable the default). Don't forget to restart the service after making changes.

    Alternatively, you could try saving your output into the permitted folder (the location may vary depending on your installation):

    SELECT *
    FROM xxxx
    WHERE XXX
    INTO OUTFILE 'C:/ProgramData/MySQL/MySQL Server 5.6/Uploads/report.csv'
        FIELDS TERMINATED BY '#'
        ENCLOSED BY '"'
        LINES TERMINATED BY '\n'
    

    It's more common to have comma seperate values using FIELDS TERMINATED BY ','. See below for an example (also showing a Linux path):

    SELECT *
    FROM table
    INTO OUTFILE '/var/lib/mysql-files/report.csv'
        FIELDS TERMINATED BY ',' ENCLOSED BY '"'
        ESCAPED BY ''
        LINES TERMINATED BY '\n';
    
    0 讨论(0)
  • 2020-12-02 11:14

    I had to set

    C:\ProgramData\MySQL\MySQL Server 8.0/my.ini  secure-file-priv=""
    

    When I commented line with secure-file-priv, secure-file-priv was null and I couldn't download data.

    0 讨论(0)
提交回复
热议问题