Disable secure priv for data loading on MySQL

前端 未结 5 2046
刺人心
刺人心 2020-12-13 14:46

I\'m running MySQL 5.7 on a Windows 10 machine. I\'ve read through all the SO threads on this topic and still haven\'t figured out how to get my data to load and get past th

5条回答
  •  天命终不由人
    2020-12-13 15:35

    I can't reproduce the problem.

    mysql> SELECT VERSION();
    +-----------+
    | VERSION() |
    +-----------+
    | 5.7.13    |
    +-----------+
    1 row in set (0,00 sec)
    
    mysql> SELECT @@GLOBAL.secure_file_priv;
    +---------------------------+
    | @@GLOBAL.secure_file_priv |
    +---------------------------+
    | NULL                      |
    +---------------------------+
    1 row in set (0,00 sec)
    
    -- USE ...
    
    mysql> LOAD DATA INFILE '/var/lib/mysql-files/myfile.csv'
        -> INTO TABLE `test_files`
        -> COLUMNS TERMINATED BY ',' ENCLOSED BY '\"'
        -> LINES TERMINATED BY '\n';
    ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv
    option so it cannot execute this statement
    

    Change file: /etc/mysql/my.cnf

    [mysqld]
    .
    .
    .
    secure_file_priv=/var/lib/mysql-files/
    .
    .
    .
    

    Restart MySQL.

    mysql> SELECT @@GLOBAL.secure_file_priv;
    +---------------------------+
    | @@GLOBAL.secure_file_priv |
    +---------------------------+
    | /var/lib/mysql-files/     |
    +---------------------------+
    1 row in set (0,00 sec)
    
    mysql> LOAD DATA INFILE '/var/lib/mysql-files/myfile.csv'
        -> INTO TABLE `test_files`
        -> COLUMNS TERMINATED BY ',' ENCLOSED BY '\"'
        -> LINES TERMINATED BY '\n';
    Query OK, 3 rows affected (0,00 sec)
    Records: 3  Deleted: 0  Skipped: 0  Warnings: 0
    

    See 6.1.4 Server System Variables :: secure_file_priv

提交回复
热议问题