1. 程式人生 > >mysql5.7導入數據提示--secure-file-priv選項報錯解決

mysql5.7導入數據提示--secure-file-priv選項報錯解決

not 數據 mysql 5.7 ria core can 解決辦法 ase 簡述

系統環境
  • CentOS Linux release 7.4.1708 (Core)
  • mysql 5.7.23

錯誤描述

  • 執行數據導入時,出現1290錯誤:
    mysql> load data infile ‘/mnt/test/20190220/test_eventHistory_2019022000_2019022023.txt‘ into table event_history_201902(json_str);
    ERROR 1290 (HY000): The MySQL server is running with the --secure-file-priv option so it cannot execute this statement

問題分析

  • 簡述下錯誤信息,mysql服務運行時啟用了--secure-file-priv option參數,因此這個語句無法執行。查閱官方文檔,secure_file_priv 這個參數用於限制數據的導入和導出,例如LOAD DATA
    或者 SELECT ... INTO OUTFILE 以及 LOAD_FILE()函數,要想執行以上操作用戶需要具有FILE權限。
  • secure_file_priv可以設置為如下:
    1. 如果為空,則此參數沒有作用,即不做限制
    2. 如果設置為目錄,則數據的導入導出就只會限制在此目錄中,並且這個目錄必須事先存在,服務器並不會創建它
    3. 如果設為NULL,服務器會禁止數據的導入導出操作
  • 查看一下當前系統secure_file_priv 的值:
    mysql> show global variables like ‘%secure%‘;
    +--------------------------+-------+
    | Variable_name            | Value |
    +--------------------------+-------+
    | require_secure_transport | OFF   |
    | secure_auth              | ON    |
    | secure_file_priv         | NULL  |
    +--------------------------+-------+
    3 rows in set (0.01 sec)
  • 值為NULL, 由此可知服務器會禁止數據的導入導出操作,嘗試修改此參數:
    mysql> set global secure_file_priv=‘‘;
    ERROR 1238 (HY000): Variable ‘secure_file_priv‘ is a read only variable
  • 這是一個只讀參數,不能使用set global來修改

解決辦法

  • 在mysql配置文件/etc/my.cnf中[mysqld]配置段添加如下配置
    [mysqld]
    ...
    secure_file_priv=‘‘
    ...
  • 重啟mysql並再次查看secure_file_priv的值
    # /etc/init.d/mysqld restart 
    #
    mysql> show global variables like ‘%secure%‘;
    +--------------------------+-------+
    | Variable_name            | Value |
    +--------------------------+-------+
    | require_secure_transport | OFF   |
    | secure_auth              | ON    |
    | secure_file_priv         |       |
    +--------------------------+-------+
    3 rows in set (0.00 sec)
  • 再次執行導入操作,成功
    mysql> load data infile ‘/mnt/test/20190220/test_eventHistory_2019022000_2019022023.txt‘ into table event_history_201902(json_str);
    Query OK, 234 rows affected (0.00 sec)

mysql5.7導入數據提示--secure-file-priv選項報錯解決