How should I tackle --secure-file-priv in MySQL?

前端 未结 21 1087
攒了一身酷
攒了一身酷 2020-11-22 06:04

I am learning MySQL and tried using a LOAD DATA clause. When I used it as below:

LOAD DATA INFILE \"text.txt\" INTO table mytable;
相关标签:
21条回答
  • 2020-11-22 06:14

    I solved it using the LOCAL option in the command:

    LOAD DATA LOCAL INFILE "text.txt" INTO TABLE mytable;
    

    You can find more info here.

    If LOCAL is specified, the file is read by the client program on the client host and sent to the server. The file can be given as a full path name to specify its exact location. If given as a relative path name, the name is interpreted relative to the directory in which the client program was started.

    0 讨论(0)
  • 2020-11-22 06:14

    The thing that worked for me:

    1. Put your file inside of the folder specified in secure-file-priv.

      To find that type:

      mysql> show variables like "secure_file_priv";  
      
    2. Check if you have local_infile = 1.

      Do that typing:

      mysql> show variables like "local_infile";
      

      If you get:

      +---------------+-------+
      | Variable_name | Value |
      +---------------+-------+
      | local_infile  | OFF   |
      +---------------+-------+
      

      Then set it to one typing:

      mysql> set global local_infile = 1;
      
    3. Specify the full path for your file. In my case:

      mysql> load data infile "C:/ProgramData/MySQL/MySQL Server 8.0/Uploads/file.txt" into table test;
      
    0 讨论(0)
  • 2020-11-22 06:14

    Without changing any of the configuration files..

    1. look for the value of secure_file_priv using the command posted by @vhu: SHOW VARIABLES LIKE "secure_file_priv".
    2. define the full path for your query such as: select * from table into outfile 'secure_file_priv_PATH/OUTPUT-FILE' ... rest of your query

    this worked for my in mysql-shell on ubuntu 18.04 LTS mysql 5.7.29

    0 讨论(0)
  • 2020-11-22 06:16

    I'm working on MySQL5.7.11 on Debian, the command that worked for me to see the directory is:

    mysql> SELECT @@global.secure_file_priv;
    
    0 讨论(0)
  • 2020-11-22 06:16

    For MacOS Mojave running MySQL 5.6.23 I had this problem with writing files, but not loading them. (Not seen with previous versions of Mac OS). As most of the answers to this question have been for other systems, I thought I would post the my.cnf file that cured this (and a socket problems too) in case it is of help to other Mac users. This is /etc/my.cnf

    [client]
    default-character-set=utf8
    
    [mysqld]
    character-set-server=utf8
    secure-file-priv = ""
    skip-external-locking
    

    (The internationalization is irrelevant to the question.)

    Nothing else required. Just turn the MySQL server off and then on again in Preferences (we are talking Mac) for this to take.

    0 讨论(0)
  • 2020-11-22 06:17

    I had the same problem with 'secure-file-priv'. Commenting in the .ini file didn't work and neither did moving file in directory specified by 'secure-file-priv'.

    Finally, as dbc suggested, making 'secure-file-priv' equal to an empty string worked. So if anyone is stuck after trying answers above, hopefully doing this will help.

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