MySQL ERROR 1290 (HY000) --secure-file-priv option

后端 未结 9 1361
醉话见心
醉话见心 2020-11-30 03:19

I am trying to write the results of MySQL script to a text file using the following code in my script.

SELECT p.title, p.content, c.name FROM post p
LEFT JOI         


        
相关标签:
9条回答
  • 2020-11-30 03:33
    1. Edit the (/etc/my.cnf file for CentOS) or (my.ini file for Windows)
    2. Add secure-file-priv = "" line at the end
    3. Stop mysql service using systemctl stop mysqld
    4. Restart it using systemctl start mysqld

    It will now allow you to import and export the data.

    0 讨论(0)
  • 2020-11-30 03:33

    You cannot export data as it is configured in mysql config files. Open my.cnf config file and check.

    Quote from MySQL doc

    This variable is used to limit the effect of data import and export operations, such as those performed by the LOAD DATA and SELECT ... INTO OUTFILE statements and the LOAD_FILE() function. These operations are permitted only to users who have the FILE privilege.

    secure_file_priv may be set as follows:

    • If empty, the variable has no effect.

    • If set to the name of a directory, the server limits import and export operations to work only with files in that directory. The directory must exist; the server will not create it.

    • If set to NULL, the server disables import and export operations. This value is permitted as of MySQL 5.7.6.

    (An empty value is the default, or it can be explicitly specified in my.cnf as secure_file_priv="". A NULL value can be set with secure_file_priv=NULL.)

    So, if you want to export data, then you need to comment this option and restart mysql server. Then you will be able to export.

    0 讨论(0)
  • 2020-11-30 03:35

    In my my.ini I only had

    # Secure File Priv.
    

    and I tried to put:

    # Secure File Priv.
    secure-file-priv = ""
    

    and

    # Secure File Priv.
    secure-file-priv = NULL
    

    without making it work.

    I finally deleted the line and left alone:

    secure-file-priv = ""
    

    Working correctly.

    0 讨论(0)
  • 2020-11-30 03:38

    FOR MAC OS, if installed via HOMEBREW:

    Edit my.cnf PATH: /usr/local/etc/my.cnf

    COPY this:

    # Default Homebrew MySQL server config
    [mysqld]
    # Only allow connections from localhost
    bind-address = 0.0.0.0
    secure-file-priv = ''
    

    SAVE

    Explanation: Secure_file_prive = NULL -- Limit mysqld not allowed to import and export Secure_file_priv = '/tmp/' -- Limit mysqld import and export can only occur in /tmp/ directory Secure_file_priv = '' -- does not restrict the import of mysqld

    0 讨论(0)
  • 2020-11-30 03:38

    That's because secure_file_priv is set to NULL

    mysql> show variables like secure_file_priv;

    | secure_file_priv | NULL  |
    

    You must stop mysql server

    shell>/usr/local/mysql/support-files/mysql.server stop
    

    Then restart mysql with the option defining where you want your files to be written to, for example to /tmp

    shell>/usr/local/mysql/support-files/mysql.server start --secure-file-priv=/tmp
    

    Then in mysql terminal you should see where your files can now be written to

    mysql> show variables like secure_file_priv;

    | secure_file_priv | /private/tmp/ |
    

    On Mac you can find this folder by using Go To Folder /private/tmp in Finder

    0 讨论(0)
  • 2020-11-30 03:41

    Just create a file /etc/my.cnf with the following content

    [mysqld]
    secure_file_priv            = ''
    

    You can use this oneliner:

    echo "[mysqld]\nsecure_file_priv\t\t= ''\n" | sudo tee /etc/my.cnf
    

    And then restart mysql. If brew was used to install the mysql run the following command:

    brew services restart mysql
    
    0 讨论(0)
提交回复
热议问题